|
1
|
|
|
<?php |
|
2
|
|
|
namespace Shlinkio\Shlink\CLI\Command\Tag; |
|
3
|
|
|
|
|
4
|
|
|
use Acelaya\ZsmAnnotatedServices\Annotation as DI; |
|
5
|
|
|
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; |
|
6
|
|
|
use Shlinkio\Shlink\Core\Service\Tag\TagService; |
|
7
|
|
|
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Zend\I18n\Translator\Translator; |
|
13
|
|
|
use Zend\I18n\Translator\TranslatorInterface; |
|
14
|
|
|
|
|
15
|
|
|
class RenameTagCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var TagServiceInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
private $tagService; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var TranslatorInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $translator; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* RenameTagCommand constructor. |
|
28
|
|
|
* @param TagServiceInterface $tagService |
|
29
|
|
|
* @param TranslatorInterface $translator |
|
30
|
|
|
* |
|
31
|
|
|
* @DI\Inject({TagService::class, Translator::class}) |
|
32
|
|
|
*/ |
|
33
|
2 |
|
public function __construct(TagServiceInterface $tagService, TranslatorInterface $translator) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->tagService = $tagService; |
|
36
|
2 |
|
$this->translator = $translator; |
|
37
|
2 |
|
parent::__construct(); |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
protected function configure() |
|
41
|
|
|
{ |
|
42
|
|
|
$this |
|
43
|
2 |
|
->setName('tag:rename') |
|
44
|
2 |
|
->setDescription($this->translator->translate('Renames one existing tag.')) |
|
45
|
2 |
|
->addArgument('oldName', InputArgument::REQUIRED, $this->translator->translate('Current name of the tag.')) |
|
46
|
2 |
|
->addArgument('newName', InputArgument::REQUIRED, $this->translator->translate('New name of the tag.')); |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
50
|
|
|
{ |
|
51
|
2 |
|
$oldName = $input->getArgument('oldName'); |
|
52
|
2 |
|
$newName = $input->getArgument('newName'); |
|
53
|
|
|
|
|
54
|
|
|
try { |
|
55
|
2 |
|
$this->tagService->renameTag($oldName, $newName); |
|
56
|
1 |
|
$output->writeln(sprintf('<info>%s</info>', $this->translator->translate('Tag properly renamed.'))); |
|
57
|
1 |
|
} catch (EntityDoesNotExistException $e) { |
|
58
|
1 |
|
$output->writeln('<error>' . sprintf($this->translator->translate( |
|
59
|
1 |
|
'A tag with name "%s" was not found' |
|
60
|
1 |
|
), $oldName) . '</error>'); |
|
61
|
|
|
} |
|
62
|
2 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|