aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-08-04 19:10:00 +0200
committerArthurHoaro <arthur@hoa.ro>2017-08-05 09:55:20 +0200
commit3b67b22225c54b28c5ea8b118710ef450016fb86 (patch)
treedd58089728e46969c1eb5efb40d13b8580a4fe4e /application
parentd99aef535fa209c27c46a97dee4187ac21c84d4d (diff)
downloadShaarli-3b67b22225c54b28c5ea8b118710ef450016fb86.tar.gz
Shaarli-3b67b22225c54b28c5ea8b118710ef450016fb86.tar.zst
Shaarli-3b67b22225c54b28c5ea8b118710ef450016fb86.zip
Move tag renaming code to LinkDB and unit test it
Diffstat (limited to 'application')
-rw-r--r--application/LinkDB.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 8ca0fab3..5e38e848 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -464,6 +464,39 @@ You use the community supported version of the original Shaarli project, by Seba
464 } 464 }
465 465
466 /** 466 /**
467 * Rename or delete a tag across all links.
468 *
469 * @param string $from Tag to rename
470 * @param string $to New tag. If none is provided, the from tag will be deleted
471 *
472 * @return array|bool List of altered links or false on error
473 */
474 public function renameTag($from, $to)
475 {
476 if (empty($from)) {
477 return false;
478 }
479 $delete = empty($to);
480 // True for case-sensitive tag search.
481 $linksToAlter = $this->filterSearch(['searchtags' => $from], true);
482 foreach($linksToAlter as $key => &$value)
483 {
484 $tags = preg_split('/\s+/', trim($value['tags']));
485 if (($pos = array_search($from, $tags)) !== false) {
486 if ($delete) {
487 unset($tags[$pos]); // Remove tag.
488 } else {
489 $tags[$pos] = trim($to);
490 }
491 $value['tags'] = trim(implode(' ', array_unique($tags)));
492 $this[$value['id']] = $value;
493 }
494 }
495
496 return $linksToAlter;
497 }
498
499 /**
467 * Returns the list of days containing articles (oldest first) 500 * Returns the list of days containing articles (oldest first)
468 * Output: An array containing days (in format YYYYMMDD). 501 * Output: An array containing days (in format YYYYMMDD).
469 */ 502 */