A free, self-hostable news aggregator…
Fix label management (#3959)
maTh26afec23794c
diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.phpindex 4f3fe9bf9..0a57c0df2 100644--- a/app/Controllers/tagController.php+++ b/app/Controllers/tagController.php@@ -90,7 +90,7 @@ class FreshRSS_tag_Controller extends Minz_ActionController {$name = Minz_Request::param('name');$tagDAO = FreshRSS_Factory::createTagDao();- if (null === $tagDAO->searchByName($name)) {+ if (strlen($name) > 0 && null === $tagDAO->searchByName($name)) {$tagDAO->addTag(['name' => $name]);Minz_Request::good(_t('feedback.tag.created', $name), ['c' => 'tag', 'a' => 'index'], true);}@@ -106,13 +106,19 @@ class FreshRSS_tag_Controller extends Minz_ActionController {$targetName = Minz_Request::param('name');$sourceId = Minz_Request::param('id_tag');- $tagDAO = FreshRSS_Factory::createTagDao();+ if ($targetName == '' || $sourceId == '') {+ return Minz_Error::error(400);+ }- $sourceName = $tagDAO->searchById($sourceId)->name();+ $tagDAO = FreshRSS_Factory::createTagDao();+ $sourceTag = $tagDAO->searchById($sourceId);+ $sourceName = $sourceTag == null ? null : $sourceTag->name();$targetTag = $tagDAO->searchByName($targetName);- if (null === $targetTag) {+ if ($targetTag == null) {+ // There is no existing tag with the same target name$tagDAO->updateTag($sourceId, ['name' => $targetName]);} else {+ // There is an existing tag with the same target name$tagDAO->updateEntryTag($sourceId, $targetTag->id());$tagDAO->deleteTag($sourceId);}diff --git a/app/views/tag/index.phtml b/app/views/tag/index.phtmlindex 55db61b67..eb6eefdb1 100644--- a/app/views/tag/index.phtml+++ b/app/views/tag/index.phtml@@ -13,7 +13,7 @@<div class="form-group"><label class="group-name" for="new_label_name"><?= _t('sub.tag.name') ?></label><div class="group-controls">- <input id="new_label_name" name="name" type="text" autocomplete="off"/>+ <input id="new_label_name" name="name" type="text" autocomplete="off" required="required" /></div></div>@@ -25,12 +25,17 @@</form><h2><?= _t('sub.title.rename_label') ?></h2>+ <?php+ $disabled = '';+ if (count($this->tags) < 1) {+ $disabled = ' disabled="disabled"';+ } ?><form id="rename_tag" method="post" action="<?= _url('tag', 'rename') ?>" autocomplete="off"><input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" /><div class="form-group"><label class="group-name" for="id_tag"><?= _t('sub.tag.old_name') ?></label><div class="group-controls">- <select name="id_tag" id="id_tag">+ <select name="id_tag" id="id_tag"<?= $disabled?>><?php foreach ($this->tags as $tag): ?><option value="<?= $tag->id() ?>"><?= $tag->name() ?></option><?php endforeach; ?>@@ -40,13 +45,15 @@<div class="form-group"><label class="group-name" for="rename_new_name"><?= _t('sub.tag.new_name') ?></label><div class="group-controls">- <input id="rename_new_name" name="name" type="text" autocomplete="off"/>+ <input id="rename_new_name" name="name" type="text" autocomplete="off"<?= $disabled?>/></div></div><div class="form-group form-actions"><div class="group-controls">+ <?php if (!$disabled) { ?><button type="submit" class="btn btn-attention confirm"><?= _t('gen.action.rename') ?></button>+ <?php } ?></div></div></form>@@ -57,7 +64,7 @@<div class="form-group"><label class="group-name" for="id_tag_delete"><?= _t('sub.tag.name') ?></label><div class="group-controls">- <select name="id_tag" id="id_tag_delete">+ <select name="id_tag" id="id_tag_delete"<?= $disabled?>><?php foreach ($this->tags as $tag): ?><option value="<?= $tag->id() ?>"><?= $tag->name() ?></option><?php endforeach; ?>@@ -67,7 +74,9 @@<div class="form-group form-actions"><div class="group-controls">+ <?php if (!$disabled) { ?><button type="submit" class="btn btn-attention confirm"><?= _t('gen.action.remove') ?></button>+ <?php } ?></div></div></form>