diff --git a/setup/src/Magento/Setup/Model/Cron/JobSetCache.php b/setup/src/Magento/Setup/Model/Cron/JobSetCache.php index c1f65bc58ba1880ad7dbdfdf00fef1c962b70cec..7f58f34b7b1e065d77b5f939b5a5cfa9ad471bd7 100644 --- a/setup/src/Magento/Setup/Model/Cron/JobSetCache.php +++ b/setup/src/Magento/Setup/Model/Cron/JobSetCache.php @@ -7,6 +7,8 @@ namespace Magento\Setup\Model\Cron; use Magento\Backend\Console\Command\AbstractCacheManageCommand; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputDefinition; +use Symfony\Component\Console\Input\InputArgument; class JobSetCache extends AbstractJob { @@ -55,10 +57,21 @@ class JobSetCache extends AbstractJob public function execute() { try { - if (!empty($this->params)) { - $arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]); + $arguments = []; + if ($this->getName() === 'setup:cache:enable') { + if (!empty($this->params)) { + $arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]); + } + $arguments['command'] = 'cache:enable'; + $definition = new InputDefinition([ + new InputArgument(AbstractCacheManageCommand::INPUT_KEY_TYPES, InputArgument::REQUIRED), + new InputArgument('command', InputArgument::REQUIRED), + ]); + + $this->command->setDefinition($definition); + } else { + $arguments['command'] = 'cache:disable'; } - $arguments['command'] = $this->command->getName(); $this->command->run(new ArrayInput($arguments), $this->output); } catch (\Exception $e) { $this->status->toggleUpdateError(true); diff --git a/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php b/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php index 19f06687394211df07f54743b14c7b6f24f38613..ef2e12606bd041eead0147fc79b79874b39cf485 100644 --- a/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php +++ b/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php @@ -62,14 +62,14 @@ class JobUpgrade extends AbstractJob public function execute() { try { - $this->params['command'] = 'setup:upgrade'; - $this->command->run(new ArrayInput($this->params), $this->output); $this->queue->addJobs( [['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]] ); $this->queue->addJobs( [['name' => \Magento\Setup\Model\Updater::TASK_TYPE_MAINTENANCE_MODE, 'params' => ['enable' => false]]] ); + $this->params['command'] = 'setup:upgrade'; + $this->command->run(new ArrayInput($this->params), $this->output); } catch (\Exception $e) { $this->status->toggleUpdateError(true); throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage())); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php index ef098061d124f93b3690a8234b7ca7c124b11516..c4c5b296e7445f5654274cef7f786310d13e37d4 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php @@ -7,6 +7,8 @@ namespace Magento\Setup\Test\Unit\Model\Cron; use Magento\Setup\Model\Cron\JobSetCache; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputDefinition; +use Symfony\Component\Console\Input\InputArgument; class JobSetCacheTest extends \PHPUnit_Framework_TestCase { @@ -15,8 +17,9 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase * @param string $commandClass * @param string $commandName * @param string $jobName + * @param array $params */ - public function testSetCache($commandClass, $commandName, $jobName) + public function testSetCache($commandClass, $commandName, $jobName, $params) { $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false); @@ -32,12 +35,17 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase $output = $this->getMockForAbstractClass('Symfony\Component\Console\Output\OutputInterface', [], '', false); $status = $this->getMock('Magento\Setup\Model\Cron\Status', [], [], '', false); $command = $this->getMock($commandClass, [], [], '', false); - $command->expects($this->once())->method('getName')->willReturn($commandName); $command->expects($this->once()) ->method('run') - ->with(new ArrayInput(['command' => $commandName]), $output); + ->with(new ArrayInput(['command' => $commandName, 'types' => $params]), $output); - $model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, []); + $definition = new InputDefinition([ + new InputArgument('types', InputArgument::REQUIRED), + new InputArgument('command', InputArgument::REQUIRED), + ]); + $command->expects($this->any())->method('setDefinition')->with($definition); + + $model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, $params); $model->execute(); } @@ -47,8 +55,8 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase public function setCacheDataProvider() { return [ - ['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable'], - ['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable'], + ['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable', ['cache1']], + ['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable', []], ]; } }