[TASK] Migrate extension commands to Symfony
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Command / ActivateExtensionCommand.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Extensionmanager\Command;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputArgument;
20 use Symfony\Component\Console\Input\InputInterface;
21 use Symfony\Component\Console\Output\OutputInterface;
22 use Symfony\Component\Console\Style\SymfonyStyle;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Extbase\Object\ObjectManager;
25 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
26 use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
27
28 /**
29 * Command for activating an existing extension via CLI.
30 */
31 class ActivateExtensionCommand extends Command
32 {
33 /**
34 * Defines the allowed options for this command
35 */
36 protected function configure()
37 {
38 $this
39 ->setDescription('Activates an extension by key')
40 ->setHelp('The extension files must be present in one of the recognized extension folder paths in TYPO3.')
41 ->setAliases(['extensionmanager:extension:install', 'extension:install'])
42 ->addArgument(
43 'extensionkey',
44 InputArgument::REQUIRED,
45 'The extension key of a currently deactivated extension, located in one of TYPO3\'s extension paths.'
46 );
47 }
48
49 /**
50 * Installs an extension
51 *
52 * @inheritdoc
53 */
54 protected function execute(InputInterface $input, OutputInterface $output)
55 {
56 $io = new SymfonyStyle($input, $output);
57 $extensionKey = $input->getArgument('extensionkey');
58
59 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
60 // Emits packages may have changed signal
61 $signalSlotDispatcher = $objectManager->get(Dispatcher::class);
62 $signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
63
64 // Do the installation process
65 $objectManager->get(InstallUtility::class)->install($extensionKey);
66
67 $io->success('Activated extension ' . $extensionKey . ' successfully.');
68 }
69 }