Skip to content

Commit

Permalink
[!!!] Make Surf work with latest TYPO3 Console versions
Browse files Browse the repository at this point in the history
TYPO3 Console was converted into a composer library, thus
we must not expect it to be located in typo3conf/ext

Additionally the typo3cms binary is now located in the vendor/bin
directory by default, thus we make this a default in Surf as well.

In case you use older TYPO3 Console Versions or not a composer installation,
you can configure a different path like that:
`$application->setOption('scriptFileName', './typo3cms');`

The path needs to be relative to the git checkout root.

Fixes #50
  • Loading branch information
helhum committed Dec 12, 2016
1 parent 51dd7eb commit 900ebed
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 42 deletions.
37 changes: 33 additions & 4 deletions Tests/Unit/Task/TYPO3/CMS/RunCommandTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public function exceptionThrownBecauseNoScriptFileNameOptionDefined()
public function executeWithCommandAndScriptFileName()
{
$options = array(
'scriptFileName' => './typo3cms',
'scriptFileName' => 'vendor/bin/typo3cms',
'command' => 'command:any',
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("php './typo3cms' 'command:any'");
$this->assertCommandExecuted("php 'vendor/bin/typo3cms' 'command:any'");
}

/**
Expand All @@ -73,12 +73,41 @@ public function executeWithCommandAndScriptFileName()
public function executeWithCommandAndScriptFileNameAndArgument()
{
$options = array(
'scriptFileName' => './typo3cms',
'scriptFileName' => 'vendor/bin/typo3cms',
'command' => 'command:any',
'arguments' => 'any',
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("php './typo3cms' 'command:any' 'any'");
$this->assertCommandExecuted("php 'vendor/bin/typo3cms' 'command:any' 'any'");
}


/**
* @test
*/
public function phpBinaryIsConfigurable()
{
$options = array(
'scriptFileName' => 'vendor/bin/typo3cms',
'command' => 'command:any',
'phpBinaryPathAndFilename' => 'php_cli',
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("php_cli 'vendor/bin/typo3cms' 'command:any'");
}

/**
* @test
*/
public function contextIsAddedIfConfigured()
{
$options = array(
'scriptFileName' => 'vendor/bin/typo3cms',
'command' => 'command:any',
'context' => 'Production',
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("TYPO3_CONTEXT='Production' php 'vendor/bin/typo3cms' 'command:any'");
}

/**
Expand Down
15 changes: 9 additions & 6 deletions Tests/Unit/Task/TYPO3/CMS/SetUpExtensionsTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function setUp()
*/
public function executeWithoutOptionExecutesSetUpActive()
{
$this->task->execute($this->node, $this->application, $this->deployment, array());
$this->assertCommandExecuted("php './typo3cms' 'extension:setupactive'");
$this->task->execute($this->node, $this->application, $this->deployment, array('scriptFileName' => 'vendor/bin/typo3cms'));
$this->assertCommandExecuted("php 'vendor/bin/typo3cms' 'extension:setupactive'");
}

/**
Expand All @@ -49,10 +49,11 @@ public function executeWithoutOptionExecutesSetUpActive()
public function executeWithOptionExecutesSetUpWithOption()
{
$options = array(
'scriptFileName' => 'vendor/bin/typo3cms',
'extensionKeys' => array('foo', 'bar')
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("php './typo3cms' 'extension:setup' 'foo,bar'");
$this->assertCommandExecuted("php 'vendor/bin/typo3cms' 'extension:setup' 'foo,bar'");
}

/**
Expand All @@ -61,11 +62,12 @@ public function executeWithOptionExecutesSetUpWithOption()
public function consoleIsFoundInCorrectPathWithoutAppDirectory()
{
$options = array(
'scriptFileName' => 'vendor/bin/typo3cms',
'extensionKeys' => array('foo', 'bar')
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("cd '{$this->deployment->getApplicationReleasePath($this->application)}'");
$this->assertCommandExecuted("php './typo3cms' 'extension:setup' 'foo,bar'");
$this->assertCommandExecuted("php 'vendor/bin/typo3cms' 'extension:setup' 'foo,bar'");
}

/**
Expand All @@ -75,11 +77,12 @@ public function consoleIsFoundInCorrectPathWithWebDirectoryAndSlashesAreTrimmed(
{
$options = array(
'extensionKeys' => array('foo', 'bar'),
'scriptFileName' => 'vendor/bin/typo3cms',
'webDirectory' => '/web/',
);
$this->task->execute($this->node, $this->application, $this->deployment, $options);
$this->assertCommandExecuted("cd '{$this->deployment->getApplicationReleasePath($this->application)}'");
$this->assertCommandExecuted("test -d '{$this->deployment->getApplicationReleasePath($this->application)}/web/typo3conf/ext/typo3_console'");
$this->assertCommandExecuted("php './typo3cms' 'extension:setup' 'foo,bar'");
$this->assertCommandExecuted("test -f '{$this->deployment->getApplicationReleasePath($this->application)}/vendor/bin/typo3cms'");
$this->assertCommandExecuted("php 'vendor/bin/typo3cms' 'extension:setup' 'foo,bar'");
}
}
2 changes: 1 addition & 1 deletion src/Application/TYPO3/CMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct($name = 'TYPO3 CMS')
parent::__construct($name);
$this->options = array_merge($this->options, array(
'context' => 'Production',
'scriptFileName' => './typo3cms',
'scriptFileName' => 'vendor/bin/typo3cms',
'webDirectory' => 'web'
));
}
Expand Down
27 changes: 22 additions & 5 deletions src/Task/TYPO3/CMS/AbstractCliTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,32 @@ protected function determineWorkingDirectoryAndTargetNode(Node $node, Applicatio
*/
protected function getAvailableCliPackage(Node $node, CMS $application, Deployment $deployment, array $options = array())
{
if ($this->packageExists('typo3_console', $node, $application, $deployment, $options)) {
try {
$this->getConsoleScriptFileName($node, $application, $deployment, $options);
return 'typo3_console';
} catch (InvalidConfigurationException $e) {
if ($this->packageExists('coreapi', $node, $application, $deployment, $options)) {
return 'coreapi';
}
}
return null;
}

if ($this->packageExists('coreapi', $node, $application, $deployment, $options)) {
return 'coreapi';
/**
* @param Node $node
* @param CMS $application
* @param Deployment $deployment
* @param array $options
* @return string
* @throws \TYPO3\Surf\Exception\InvalidConfigurationException
*/
protected function getConsoleScriptFileName(Node $node, CMS $application, Deployment $deployment, array $options = array())
{
if (isset($options['scriptFileName']) && strpos($options['scriptFileName'], 'typo3cms') !== false && $this->fileExists($options['scriptFileName'], $node, $application, $deployment, $options)) {
return $options['scriptFileName'];
} else {
throw new InvalidConfigurationException('TYPO3 Console script was not found. Make sure it is available in your project and you set the "scriptFileName" option correctly. Alternatively you can remove this task (' . get_class($this) . ') in your deployment configuration.', 1481489230);
}

return null;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Task/TYPO3/CMS/ActivatePackagesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use TYPO3\Surf\Domain\Model\Application;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Domain\Model\Node;
use TYPO3\Surf\Exception\InvalidConfigurationException;

/**
* This task activates a given set of packages
Expand All @@ -29,15 +30,17 @@ class ActivatePackagesTask extends AbstractCliTask
public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
{
$this->ensureApplicationIsTypo3Cms($application);
if (!$this->packageExists('typo3_console', $node, $application, $deployment, $options)) {
$deployment->getLogger()->warning('Extension "typo3_console" was not found! Make sure it is available in your project, or remove this task (' . __CLASS__ . ') in your deployment configuration!');
try {
$scriptFileName = $this->getConsoleScriptFileName($node, $application, $deployment, $options);
} catch (InvalidConfigurationException $e) {
$deployment->getLogger()->warning('TYPO3 Console script (' .$options['scriptFileName'] . ') was not found! Make sure it is available in your project, you set the "scriptFileName" option correctly or remove this task (' . __CLASS__ . ') in your deployment configuration!');
return;
}
$deployment->getLogger()->warning('This task has been deprecated and will be removed in Surf 2.1. Please use SetUpExtensionsTask instead.');
$activePackages = isset($options['activePackages']) ? $options['activePackages'] : array();
foreach ($activePackages as $packageKey) {
$this->executeCliCommand(
array('./typo3cms', 'extension:install', $packageKey),
array($scriptFileName, 'extension:activate', $packageKey),
$node,
$application,
$deployment,
Expand Down
2 changes: 1 addition & 1 deletion src/Task/TYPO3/CMS/CompareDatabaseTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getSuitableCliArguments(Node $node, CMS $application, Deploym
switch ($this->getAvailableCliPackage($node, $application, $deployment, $options)) {
case 'typo3_console':
$databaseCompareMode = isset($options['databaseCompareMode']) ? $options['databaseCompareMode'] : '*.add,*.change';
return array('./typo3cms', 'database:updateschema', $databaseCompareMode);
return array($this->getConsoleScriptFileName($node, $application, $deployment, $options), 'database:updateschema', $databaseCompareMode);
case 'coreapi':
$databaseCompareMode = isset($options['databaseCompareMode']) ? $options['databaseCompareMode'] : '2,4';
return array('typo3/cli_dispatch.phpsh', 'extbase', 'databaseapi:databasecompare', $databaseCompareMode);
Expand Down
17 changes: 9 additions & 8 deletions src/Task/TYPO3/CMS/CreatePackageStatesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ public function execute(Node $node, Application $application, Deployment $deploy
{
$this->ensureApplicationIsTypo3Cms($application);
if (!$this->packageStatesFileExists($node, $application, $deployment, $options)) {
if (!$this->packageExists('typo3_console', $node, $application, $deployment, $options)) {
throw new InvalidConfigurationException('No package states file found in the repository and no typo3_console package found to generate it. We cannot proceed!', 1420210956);
} else {
$commandArguments = array('./typo3cms', 'install:generatepackagestates');
if (!empty($options['removeInactivePackages'])) {
$commandArguments[] = '--remove-inactive-packages';
}
$this->executeCliCommand($commandArguments, $node, $application, $deployment, $options);
try {
$scriptFileName = $this->getConsoleScriptFileName($node, $application, $deployment, $options);
} catch (InvalidConfigurationException $e) {
throw new InvalidConfigurationException('No package states file found in the repository and no typo3_console package found to generate it. We cannot proceed.', 1420210956, $e);
}
$commandArguments = array($scriptFileName, 'install:generatepackagestates');
if (!empty($options['removeInactivePackages'])) {
$commandArguments[] = '--remove-inactive-packages';
}
$this->executeCliCommand($commandArguments, $node, $application, $deployment, $options);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/TYPO3/CMS/FlushCachesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function getSuitableCliArguments(Node $node, CMS $application, Deploym
{
switch ($this->getAvailableCliPackage($node, $application, $deployment, $options)) {
case 'typo3_console':
return array('./typo3cms', 'cache:flush', '--force');
return array($this->getConsoleScriptFileName($node, $application, $deployment, $options), 'cache:flush', '--force');
case 'coreapi':
return array('typo3/cli_dispatch.phpsh', 'extbase', 'cacheapi:clearallcaches');
default:
Expand Down
15 changes: 5 additions & 10 deletions src/Task/TYPO3/CMS/RunCommandTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* *
* */

use TYPO3\Surf\Application\TYPO3\CMS;
use TYPO3\Surf\Domain\Model\Application;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Domain\Model\Node;
Expand All @@ -30,18 +31,12 @@ class RunCommandTask extends AbstractCliTask
*/
public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
{
if (!$application instanceof \TYPO3\Surf\Application\TYPO3\CMS) {
// We could make this task generic by checking for $options['scriptFileName'] here only
throw new InvalidConfigurationException(sprintf('TYPO3 CMS application needed for RunCommandTask, got "%s"', get_class($application)), 1358863336);
}
$this->ensureApplicationIsTypo3Cms($application);
if (!isset($options['command'])) {
throw new InvalidConfigurationException('Missing option "command" for RunCommandTask', 1319201396);
}
if (!isset($options['scriptFileName'])) {
throw new InvalidConfigurationException('Missing option "scriptFileName" for RunCommandTask', 1481489230);
}
$this->executeCliCommand(
$this->getArguments($options),
$this->getArguments($node, $application, $deployment, $options),
$node,
$application,
$deployment,
Expand Down Expand Up @@ -81,9 +76,9 @@ public function rollback(Node $node, Application $application, Deployment $deplo
* @param array $options The command options
* @return array all arguments
*/
protected function getArguments(array $options)
protected function getArguments(Node $node, CMS $application, Deployment $deployment, array $options = array())
{
$arguments = array($options['scriptFileName'], $options['command']);
$arguments = array($this->getConsoleScriptFileName($node, $application, $deployment, $options), $options['command']);
if (isset($options['arguments'])) {
if (!is_array($options['arguments'])) {
$options['arguments'] = array($options['arguments']);
Expand Down
9 changes: 6 additions & 3 deletions src/Task/TYPO3/CMS/SetUpExtensionsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use TYPO3\Surf\Domain\Model\Application;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Domain\Model\Node;
use TYPO3\Surf\Exception\InvalidConfigurationException;

/**
* This task sets up extensions using typo3_console.
Expand All @@ -31,12 +32,14 @@ class SetUpExtensionsTask extends AbstractCliTask
public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
{
$this->ensureApplicationIsTypo3Cms($application);
if (!$this->packageExists('typo3_console', $node, $application, $deployment, $options)) {
$deployment->getLogger()->warning('Extension "typo3_console" was not found! Make sure it is available in your project, or remove this task (' . __CLASS__ . ') in your deployment configuration!');
try {
$scriptFileName = $this->getConsoleScriptFileName($node, $application, $deployment, $options);
} catch (InvalidConfigurationException $e) {
$deployment->getLogger()->warning('TYPO3 Console script (' .$options['scriptFileName'] . ') was not found! Make sure it is available in your project, you set the "scriptFileName" option correctly or remove this task (' . __CLASS__ . ') in your deployment configuration!');
return;
}
$extensionKeys = isset($options['extensionKeys']) ? $options['extensionKeys'] : array();
$commandArguments = array('./typo3cms');
$commandArguments = array($scriptFileName);
if (empty($extensionKeys)) {
$commandArguments[] = 'extension:setupactive';
} else {
Expand Down

0 comments on commit 900ebed

Please sign in to comment.