Skip to content
Snippets Groups Projects
Commit 6957eecc authored by Maddy Chellathurai's avatar Maddy Chellathurai
Browse files

MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron -...

MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron - unhelpful error message #3189

- fixes for QA issues.
parent 8270c859
No related merge requests found
...@@ -7,6 +7,8 @@ namespace Magento\Setup\Model\Cron; ...@@ -7,6 +7,8 @@ namespace Magento\Setup\Model\Cron;
use Magento\Backend\Console\Command\AbstractCacheManageCommand; use Magento\Backend\Console\Command\AbstractCacheManageCommand;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputArgument;
class JobSetCache extends AbstractJob class JobSetCache extends AbstractJob
{ {
...@@ -55,10 +57,21 @@ class JobSetCache extends AbstractJob ...@@ -55,10 +57,21 @@ class JobSetCache extends AbstractJob
public function execute() public function execute()
{ {
try { try {
if (!empty($this->params)) { $arguments = [];
$arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]); 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); $this->command->run(new ArrayInput($arguments), $this->output);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->status->toggleUpdateError(true); $this->status->toggleUpdateError(true);
......
...@@ -62,14 +62,14 @@ class JobUpgrade extends AbstractJob ...@@ -62,14 +62,14 @@ class JobUpgrade extends AbstractJob
public function execute() public function execute()
{ {
try { try {
$this->params['command'] = 'setup:upgrade';
$this->command->run(new ArrayInput($this->params), $this->output);
$this->queue->addJobs( $this->queue->addJobs(
[['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]] [['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]]
); );
$this->queue->addJobs( $this->queue->addJobs(
[['name' => \Magento\Setup\Model\Updater::TASK_TYPE_MAINTENANCE_MODE, 'params' => ['enable' => false]]] [['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) { } catch (\Exception $e) {
$this->status->toggleUpdateError(true); $this->status->toggleUpdateError(true);
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage())); throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
......
...@@ -7,6 +7,8 @@ namespace Magento\Setup\Test\Unit\Model\Cron; ...@@ -7,6 +7,8 @@ namespace Magento\Setup\Test\Unit\Model\Cron;
use Magento\Setup\Model\Cron\JobSetCache; use Magento\Setup\Model\Cron\JobSetCache;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputArgument;
class JobSetCacheTest extends \PHPUnit_Framework_TestCase class JobSetCacheTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -15,8 +17,9 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase ...@@ -15,8 +17,9 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
* @param string $commandClass * @param string $commandClass
* @param string $commandName * @param string $commandName
* @param string $jobName * @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); $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
$objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false); $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false);
...@@ -32,12 +35,17 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase ...@@ -32,12 +35,17 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
$output = $this->getMockForAbstractClass('Symfony\Component\Console\Output\OutputInterface', [], '', false); $output = $this->getMockForAbstractClass('Symfony\Component\Console\Output\OutputInterface', [], '', false);
$status = $this->getMock('Magento\Setup\Model\Cron\Status', [], [], '', false); $status = $this->getMock('Magento\Setup\Model\Cron\Status', [], [], '', false);
$command = $this->getMock($commandClass, [], [], '', false); $command = $this->getMock($commandClass, [], [], '', false);
$command->expects($this->once())->method('getName')->willReturn($commandName);
$command->expects($this->once()) $command->expects($this->once())
->method('run') ->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(); $model->execute();
} }
...@@ -47,8 +55,8 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase ...@@ -47,8 +55,8 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
public function setCacheDataProvider() public function setCacheDataProvider()
{ {
return [ return [
['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable'], ['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable', ['cache1']],
['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable'], ['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable', []],
]; ];
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment