Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Fix Symfony command registration for extensions #673

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/.Build/*
/composer.lock

/Configuration/Console/AllCommands.php
/Configuration/Console/ComposerPackagesCommands.php
/Libraries/*
/ext_emconf.php
/ext_icon.png
Expand Down
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ return PhpCsFixer\Config::create()
->exclude('Documentation')
->exclude('Libraries')
->notName('ext_emconf.php')
->notName('AllCommands.php')
->notName('ComposerPackagesCommands.php')
);
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ finder:
- "Libraries"
not-name:
- "ext_emconf.php"
- "AllCommands.php"
- "ComposerPackagesCommands.php"
27 changes: 6 additions & 21 deletions Classes/Composer/InstallerScript/PopulateCommandConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ public function run(ScriptEvent $event): bool
list($package, $installPath) = $item;
$installPath = ($installPath ?: $basePath);
$packageName = $package->getName();
if ($package->getType() === 'metapackage') {
// We have a meta package, which does not have any files
continue;
}
if ($packageName === 'typo3/cms') {
$commandConfiguration = array_merge($commandConfiguration, $this->getConfigFromTypo3Packages($installPath));
$packageType = $package->getType();
if (in_array($packageType, ['metapackage', 'typo3-cms-extension', 'typo3-cms-framework'], true)) {
// Commands in TYPO3 extensions are scanned for anyway at a later point.
// With that we ensure not showing commands for extensions that aren't active.
// Since meta packages have no code, thus cannot include any commands, we ignore them as well.
continue;
}
$commandConfiguration = array_merge($commandConfiguration, $this->getConfigFromPackage($installPath, $packageName));
}
$success = file_put_contents(
__DIR__ . '/../../../Configuration/Console/AllCommands.php',
__DIR__ . '/../../../Configuration/Console/ComposerPackagesCommands.php',
'<?php' . chr(10)
. 'return '
. var_export($commandConfiguration, true)
Expand Down Expand Up @@ -92,18 +91,4 @@ private function getConfigFromPackage(string $installPath, string $packageName)
}
return [$packageName => $commandConfiguration];
}

/**
* @param $typo3InstallPath
* @return array
*/
private function getConfigFromTypo3Packages(string $typo3InstallPath): array
{
$commandConfiguration = [];
foreach (glob($typo3InstallPath . '/typo3/sysext/*/') as $installPath) {
$packageName = basename($installPath);
$commandConfiguration = array_merge($commandConfiguration, $this->getConfigFromPackage($installPath, $packageName));
}
return $commandConfiguration;
}
}
27 changes: 13 additions & 14 deletions Classes/Mvc/Cli/CommandCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,28 @@ private function getCommandConfigurations(): array
if (!empty($this->commandConfigurations)) {
return $this->commandConfigurations;
}
if (file_exists($commandConfigurationFile = __DIR__ . '/../../../Configuration/Console/AllCommands.php')) {
return require $commandConfigurationFile;
}

// All code below is only for non composer mode
if (!$this->packageManager->isPackageAvailable('typo3_console')
|| !$this->packageManager->isPackageActive('typo3_console')
) {
// We are not installed, or not even existing as extension, but we still want to be able to run,
// thus we include our config directly in this case.
if (file_exists($commandConfigurationFile = __DIR__ . '/../../../Configuration/Console/ComposerPackagesCommands.php')) {
$this->commandConfigurations = require $commandConfigurationFile;
} else {
// We only reach this point in non composer mode
// We ensure that our commands are present, even if we are not an active extension or even not being an extension at all
$this->commandConfigurations['typo3_console'] = require __DIR__ . '/../../../Configuration/Console/Commands.php';
}
$this->populateCommandConfigurationFromExtensions();
return $this->commandConfigurations;
}

private function populateCommandConfigurationFromExtensions()
{
foreach ($this->packageManager->getActivePackages() as $package) {
$installPath = $package->getPackagePath();
$packageConfig = $this->getConfigFromPackage($installPath);
$packageConfig = $this->getConfigFromExtension($package->getPackagePath());
if (!empty($packageConfig)) {
$this->commandConfigurations[$package->getPackageKey()] = $packageConfig;
}
}
return $this->commandConfigurations;
}

private function getConfigFromPackage(string $installPath): array
private function getConfigFromExtension(string $installPath): array
{
$commandConfiguration = [];
if (file_exists($commandConfigurationFile = $installPath . '/Configuration/Console/Commands.php')) {
Expand Down
18 changes: 6 additions & 12 deletions Configuration/Console/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,16 @@
'typo3_console:database:updateschema' => ['helhum.typo3console:database', 'helhum.typo3console:persistence'],
],
'replace' => [
'extbase',
'_extbase_help',
'_core_command',
'typo3/cms-backend:backend:lock',
'typo3/cms-backend:backend:unlock',
'backend:backend:lock',
'backend:backend:unlock',
'backend:referenceindex:update',
'extbase:_core_command',
'extbase:_extbase_help',
'extensionmanager:extension:dumpclassloadinginformation',
'extensionmanager:extension:install',
'extensionmanager:extension:uninstall',
'help:help',
'help:error',
'typo3/cms-extbase:help:error',
'extbase:help:error',
'extension:dumpclassloadinginformation',
'extension:install',
'extension:uninstall',
'referenceindex:update',
'typo3/cms-scheduler:scheduler:run',
'scheduler:scheduler:run',
],
];
14 changes: 7 additions & 7 deletions Resources/Private/ExtensionArtifacts/ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
'constraints' => [
'depends' => [
'php' => '7.0.0-7.2.99',
'typo3' => '8.7.0-9.0.99',
'extbase' => '8.7.0-9.0.99',
'extensionmanager' => '8.7.0-9.0.99',
'fluid' => '8.7.0-9.0.99',
'install' => '8.7.0-9.0.99',
'scheduler' => '8.7.0-9.0.99',
'saltedpasswords' => '8.7.0-9.0.99',
'typo3' => '8.7.10-9.0.99',
'extbase' => '8.7.10-9.0.99',
'extensionmanager' => '8.7.10-9.0.99',
'fluid' => '8.7.10-9.0.99',
'install' => '8.7.10-9.0.99',
'scheduler' => '8.7.10-9.0.99',
'saltedpasswords' => '8.7.10-9.0.99',
],
'conflicts' => [
'dbal' => '',
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Command/UpgradeCommandControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function setUpNewTypo3Instance($instancePath)
$consoleComposerJson = str_replace('"name": "helhum/typo3-console"', '"name": "helhum/typo3-console-test"', $consoleComposerJson);
file_put_contents($instancePath . '/typo3_console/composer.json', $consoleComposerJson);
$this->executeComposerCommand(['config', 'repositories.console', '{"type": "path", "url": "typo3_console", "options": {"symlink": false}}']);
$output = $this->executeComposerCommand(['require', 'typo3/cms-core=^8.7.9', 'helhum/typo3-composer-setup=^0.4', 'helhum/typo3-console-test=@dev']);
$output = $this->executeComposerCommand(['require', 'typo3/cms-core=^8.7.10', 'helhum/typo3-console-test=@dev']);
$this->assertContains('Mirroring from typo3_console', $output);

$this->executeMysqlQuery('DROP DATABASE IF EXISTS ' . getenv('TYPO3_INSTALL_DB_DBNAME'), false);
Expand Down
21 changes: 10 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@
"php": ">=7.0.0 <7.3",
"helhum/typo3-console-plugin": "^2.0.2",

"typo3/cms-backend": "^8.7.7 || ~9.0.0",
"typo3/cms-core": "^8.7.7 || ~9.0.0",
"typo3/cms-extbase": "^8.7.7 || ~9.0.0",
"typo3/cms-extensionmanager": "^8.7.7 || ~9.0.0",
"typo3/cms-fluid": "^8.7.7 || ~9.0.0",
"typo3/cms-install": "^8.7.7 || ~9.0.0",
"typo3/cms-scheduler": "^8.7.7 || ~9.0.0",
"typo3/cms-saltedpasswords": "^8.7.7 || ~9.0.0",
"typo3/cms-backend": "^8.7.10 || ~9.0.0",
"typo3/cms-core": "^8.7.10 || ~9.0.0",
"typo3/cms-extbase": "^8.7.10 || ~9.0.0",
"typo3/cms-extensionmanager": "^8.7.10 || ~9.0.0",
"typo3/cms-fluid": "^8.7.10 || ~9.0.0",
"typo3/cms-install": "^8.7.10 || ~9.0.0",
"typo3/cms-scheduler": "^8.7.10 || ~9.0.0",
"typo3/cms-saltedpasswords": "^8.7.10 || ~9.0.0",

"doctrine/annotations": "^1.4",
"symfony/console": "^3.3.6 || ^4.0",
"symfony/process": "^3.3.6 || ^4.0"
},
"require-dev": {
"typo3/cms-reports": "^8.7.7 || ~9.0.0 || 9.1.*@dev",
"typo3/cms-filemetadata": "^8.7.7 || ~9.0.0 || 9.1.*@dev",
"typo3/cms-reports": "^8.7.10 || ~9.0.0 || 9.1.*@dev",
"typo3/cms-filemetadata": "^8.7.10 || ~9.0.0 || 9.1.*@dev",

"helhum/typo3-composer-setup": "^0.4",
"typo3-console/php-server-command": "^0.1.1",
"typo3-console/create-reference-command": "^2.2",
"symfony/filesystem": "^3.2",
Expand Down