[BUGFIX] Add user authentication to activate extension command
[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\Core\Bootstrap;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Extbase\Object\ObjectManager;
26 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
27 use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
28
29 /**
30 * Command for activating an existing extension via CLI.
31 */
32 class ActivateExtensionCommand extends Command
33 {
34 /**
35 * Defines the allowed options for this command
36 */
37 protected function configure()
38 {
39 $this
40 ->setDescription('Activates an extension by key')
41 ->setHelp('The extension files must be present in one of the recognized extension folder paths in TYPO3.')
42 ->setAliases(['extensionmanager:extension:install', 'extension:install'])
43 ->addArgument(
44 'extensionkey',
45 InputArgument::REQUIRED,
46 'The extension key of a currently deactivated extension, located in one of TYPO3\'s extension paths.'
47 );
48 }
49
50 /**
51 * Installs an extension
52 *
53 * @inheritdoc
54 */
55 protected function execute(InputInterface $input, OutputInterface $output)
56 {
57 $io = new SymfonyStyle($input, $output);
58 $extensionKey = $input->getArgument('extensionkey');
59
60 // Ensure the _cli_ user is authenticated because the extension might import data
61 Bootstrap::initializeBackendAuthentication();
62
63 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
64 // Emits packages may have changed signal
65 $signalSlotDispatcher = $objectManager->get(Dispatcher::class);
66 $signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
67
68 // Do the installation process
69 $objectManager->get(InstallUtility::class)->install($extensionKey);
70
71 $io->success('Activated extension ' . $extensionKey . ' successfully.');
72 }
73 }