diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-08-05 09:59:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-05 09:59:03 +0200 |
commit | 1fdb40fc169b42af7622610c4f088688de231118 (patch) | |
tree | 4b5169150b1abcacf00f1ac2317aa633c37eaa26 /application | |
parent | f09e1e318e0b1c72aa659c20b715be508009175f (diff) | |
parent | 3b67b22225c54b28c5ea8b118710ef450016fb86 (diff) | |
download | Shaarli-1fdb40fc169b42af7622610c4f088688de231118.tar.gz Shaarli-1fdb40fc169b42af7622610c4f088688de231118.tar.zst Shaarli-1fdb40fc169b42af7622610c4f088688de231118.zip |
Merge pull request #887 from ArthurHoaro/hotfix/dash-tag-rename
Make sure that the tag exists before altering/removing it
Diffstat (limited to 'application')
-rw-r--r-- | application/LinkDB.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index 9e3efd6b..9308164a 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -465,6 +465,39 @@ You use the community supported version of the original Shaarli project, by Seba | |||
465 | } | 465 | } |
466 | 466 | ||
467 | /** | 467 | /** |
468 | * Rename or delete a tag across all links. | ||
469 | * | ||
470 | * @param string $from Tag to rename | ||
471 | * @param string $to New tag. If none is provided, the from tag will be deleted | ||
472 | * | ||
473 | * @return array|bool List of altered links or false on error | ||
474 | */ | ||
475 | public function renameTag($from, $to) | ||
476 | { | ||
477 | if (empty($from)) { | ||
478 | return false; | ||
479 | } | ||
480 | $delete = empty($to); | ||
481 | // True for case-sensitive tag search. | ||
482 | $linksToAlter = $this->filterSearch(['searchtags' => $from], true); | ||
483 | foreach($linksToAlter as $key => &$value) | ||
484 | { | ||
485 | $tags = preg_split('/\s+/', trim($value['tags'])); | ||
486 | if (($pos = array_search($from, $tags)) !== false) { | ||
487 | if ($delete) { | ||
488 | unset($tags[$pos]); // Remove tag. | ||
489 | } else { | ||
490 | $tags[$pos] = trim($to); | ||
491 | } | ||
492 | $value['tags'] = trim(implode(' ', array_unique($tags))); | ||
493 | $this[$value['id']] = $value; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | return $linksToAlter; | ||
498 | } | ||
499 | |||
500 | /** | ||
468 | * Returns the list of days containing articles (oldest first) | 501 | * Returns the list of days containing articles (oldest first) |
469 | * Output: An array containing days (in format YYYYMMDD). | 502 | * Output: An array containing days (in format YYYYMMDD). |
470 | */ | 503 | */ |