Moved tag renaming to API
This commit is contained in:
parent
5c003588fa
commit
5d2c5a2053
5 changed files with 51 additions and 17 deletions
|
@ -127,11 +127,12 @@ $tagValidation =
|
|||
\Chibi\Router::register(['TagController', 'listView'], 'GET', '/tags/{filter}/{page}', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'autoCompleteView'], 'GET', '/tags-autocomplete', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'relatedView'], 'GET', '/tags-related', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'renameView'], 'GET', '/tags-rename', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'renameAction'], 'POST', '/tags-rename', $tagValidation);
|
||||
|
||||
foreach (['GET', 'POST'] as $method)
|
||||
{
|
||||
\Chibi\Router::register(['TagController', 'mergeAction'], $method, '/tags-merge', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'renameAction'], $method, '/tags-rename', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'massTagRedirectAction'], $method, '/mass-tag-redirect', $tagValidation);
|
||||
|
||||
$userValidations =
|
||||
|
|
35
src/Api/Jobs/RenameTagsJob.php
Normal file
35
src/Api/Jobs/RenameTagsJob.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
class RenameTagsJob extends AbstractJob
|
||||
{
|
||||
const SOURCE_TAG_NAME = 'source-tag-name';
|
||||
const TARGET_TAG_NAME = 'target-tag-name';
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$sourceTag = $this->getArgument(self::SOURCE_TAG_NAME);
|
||||
$targetTag = $this->getArgument(self::TARGET_TAG_NAME);
|
||||
|
||||
TagModel::removeUnused();
|
||||
TagModel::rename($sourceTag, $targetTag);
|
||||
|
||||
LogHelper::log('{user} renamed {source} to {target}', [
|
||||
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||
'source' => TextHelper::reprTag($sourceTag),
|
||||
'target' => TextHelper::reprTag($targetTag)]);
|
||||
}
|
||||
|
||||
public function requiresPrivilege()
|
||||
{
|
||||
return Privilege::RenameTags;
|
||||
}
|
||||
|
||||
public function requiresAuthentication()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function requiresConfirmedEmail()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -94,6 +94,12 @@ class TagController
|
|||
Messenger::message('Tags merged successfully.');
|
||||
}
|
||||
|
||||
public function renameView()
|
||||
{
|
||||
$context = getContext();
|
||||
$context->viewName = 'tag-list-wrapper';
|
||||
}
|
||||
|
||||
public function renameAction()
|
||||
{
|
||||
$context = getContext();
|
||||
|
@ -101,22 +107,13 @@ class TagController
|
|||
$context->handleExceptions = true;
|
||||
|
||||
Access::assert(Privilege::MergeTags);
|
||||
if (!InputHelper::get('submit'))
|
||||
return;
|
||||
|
||||
TagModel::removeUnused();
|
||||
|
||||
$suppliedSourceTag = InputHelper::get('source-tag');
|
||||
$suppliedSourceTag = TagModel::validateTag($suppliedSourceTag);
|
||||
|
||||
$suppliedTargetTag = InputHelper::get('target-tag');
|
||||
$suppliedTargetTag = TagModel::validateTag($suppliedTargetTag);
|
||||
|
||||
TagModel::rename($suppliedSourceTag, $suppliedTargetTag);
|
||||
|
||||
LogHelper::log('{user} renamed {source} to {target}', [
|
||||
'source' => TextHelper::reprTag($suppliedSourceTag),
|
||||
'target' => TextHelper::reprTag($suppliedTargetTag)]);
|
||||
Api::run(
|
||||
new RenameTagsJob(),
|
||||
[
|
||||
RenameTagsJob::SOURCE_TAG_NAME => InputHelper::get('source-tag'),
|
||||
RenameTagsJob::TARGET_TAG_NAME => InputHelper::get('target-tag'),
|
||||
]);
|
||||
|
||||
Messenger::message('Tag renamed successfully.');
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ class TagModel extends AbstractCrudModel
|
|||
throw new SimpleException('Target tag already exists');
|
||||
|
||||
$sourceTag->name = $targetName;
|
||||
TagModel::validateTag($sourceTag->name);
|
||||
self::save($sourceTag);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ Assets::addStylesheet('tag-list.css');
|
|||
|
||||
$tabs = [];
|
||||
if (Access::check(Privilege::ListTags)) $tabs['list'] = ['List', 'listView'];
|
||||
if (Access::check(Privilege::RenameTags)) $tabs['rename'] = ['Rename', 'renameAction'];
|
||||
if (Access::check(Privilege::MergeTags)) $tabs['merge'] = ['Merge', 'mergeAction'];
|
||||
if (Access::check(Privilege::RenameTags)) $tabs['rename'] = ['Rename', 'renameView'];
|
||||
if (Access::check(Privilege::MassTag)) $tabs['mass-tag-redirect'] = ['Mass tag', 'massTagRedirectAction'];
|
||||
$showTabs = count($tabs) > 1;
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue