Created
June 25, 2015 08:56
-
-
Save sascha-egerer/ea67084e3082b37c552a to your computer and use it in GitHub Desktop.
Extension Command to install activated TYPO3 Extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Syzygy\SyzygyBase\Command; | |
/*************************************************************** | |
* Copyright notice | |
* | |
* (c) 2015 Sascha Egerer <[email protected]> | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* A copy is found in the text file GPL.txt and important notices to the license | |
* from the author is found in LICENSE.txt distributed with these scripts. | |
* | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
***************************************************************/ | |
use Helhum\Typo3Console\Mvc\Controller\CommandController; | |
use TYPO3\CMS\Core\Package\MetaData; | |
/** | |
* Extension related commands | |
*/ | |
class ExtensionCommandController extends CommandController { | |
/** | |
* @var \TYPO3\CMS\Core\Package\PackageManager | |
* @inject | |
*/ | |
protected $packageManager; | |
/** | |
* Install all extensions that are listed in "active-packages" by using the InstallUtility. | |
* This will not only install the extension but also do database updates and folder updates. | |
*/ | |
public function installActivatedPackagesCommand() { | |
$activePackages = $this->getPackagesFromRootComposerFile(); | |
$service = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class); | |
/** @var \TYPO3\CMS\Core\Package\PackageInterface $package */ | |
foreach ($this->packageManager->getAvailablePackages() as $package) { | |
if(in_array($package->getPackageKey(), $activePackages)) { | |
$this->outputLine('Installing Package: ' . $package->getPackageKey()); | |
$service->install($package->getPackageKey()); | |
} | |
} | |
} | |
/** | |
* @return string[] Array of packages keys in root composer.json | |
*/ | |
protected function getPackagesFromRootComposerFile() { | |
if (!file_exists(PATH_site . 'composer.json')) { | |
$this->outputLine('No composer.json found in project root'); | |
$this->sendAndExit(1); | |
} | |
$composerData = json_decode(file_get_contents(PATH_site . 'composer.json')); | |
if (!is_object($composerData)) { | |
$this->outputLine('composer.json seems to be invalid'); | |
$this->sendAndExit(1); | |
} | |
$activePackageKey = 'active-packages'; | |
if (!isset($composerData->extra->{$activePackageKey}) || !is_array($composerData->extra->{$activePackageKey})) { | |
$this->outputLine('No packages found to activate!'); | |
$this->sendAndExit(); | |
} | |
return $composerData->extra->{$activePackageKey}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment