Skip to content

Commit 6957eec

Browse files
committed
MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron - unhelpful error message #3189
- fixes for QA issues.
1 parent 8270c85 commit 6957eec

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

setup/src/Magento/Setup/Model/Cron/JobSetCache.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Backend\Console\Command\AbstractCacheManageCommand;
99
use Symfony\Component\Console\Input\ArrayInput;
10+
use Symfony\Component\Console\Input\InputDefinition;
11+
use Symfony\Component\Console\Input\InputArgument;
1012

1113
class JobSetCache extends AbstractJob
1214
{
@@ -55,10 +57,21 @@ public function __construct(
5557
public function execute()
5658
{
5759
try {
58-
if (!empty($this->params)) {
59-
$arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]);
60+
$arguments = [];
61+
if ($this->getName() === 'setup:cache:enable') {
62+
if (!empty($this->params)) {
63+
$arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]);
64+
}
65+
$arguments['command'] = 'cache:enable';
66+
$definition = new InputDefinition([
67+
new InputArgument(AbstractCacheManageCommand::INPUT_KEY_TYPES, InputArgument::REQUIRED),
68+
new InputArgument('command', InputArgument::REQUIRED),
69+
]);
70+
71+
$this->command->setDefinition($definition);
72+
} else {
73+
$arguments['command'] = 'cache:disable';
6074
}
61-
$arguments['command'] = $this->command->getName();
6275
$this->command->run(new ArrayInput($arguments), $this->output);
6376
} catch (\Exception $e) {
6477
$this->status->toggleUpdateError(true);

setup/src/Magento/Setup/Model/Cron/JobUpgrade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public function __construct(
6262
public function execute()
6363
{
6464
try {
65-
$this->params['command'] = 'setup:upgrade';
66-
$this->command->run(new ArrayInput($this->params), $this->output);
6765
$this->queue->addJobs(
6866
[['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]]
6967
);
7068
$this->queue->addJobs(
7169
[['name' => \Magento\Setup\Model\Updater::TASK_TYPE_MAINTENANCE_MODE, 'params' => ['enable' => false]]]
7270
);
71+
$this->params['command'] = 'setup:upgrade';
72+
$this->command->run(new ArrayInput($this->params), $this->output);
7373
} catch (\Exception $e) {
7474
$this->status->toggleUpdateError(true);
7575
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));

setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Setup\Model\Cron\JobSetCache;
99
use Symfony\Component\Console\Input\ArrayInput;
10+
use Symfony\Component\Console\Input\InputDefinition;
11+
use Symfony\Component\Console\Input\InputArgument;
1012

1113
class JobSetCacheTest extends \PHPUnit_Framework_TestCase
1214
{
@@ -15,8 +17,9 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
1517
* @param string $commandClass
1618
* @param string $commandName
1719
* @param string $jobName
20+
* @param array $params
1821
*/
19-
public function testSetCache($commandClass, $commandName, $jobName)
22+
public function testSetCache($commandClass, $commandName, $jobName, $params)
2023
{
2124
$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
2225
$objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false);
@@ -32,12 +35,17 @@ public function testSetCache($commandClass, $commandName, $jobName)
3235
$output = $this->getMockForAbstractClass('Symfony\Component\Console\Output\OutputInterface', [], '', false);
3336
$status = $this->getMock('Magento\Setup\Model\Cron\Status', [], [], '', false);
3437
$command = $this->getMock($commandClass, [], [], '', false);
35-
$command->expects($this->once())->method('getName')->willReturn($commandName);
3638
$command->expects($this->once())
3739
->method('run')
38-
->with(new ArrayInput(['command' => $commandName]), $output);
40+
->with(new ArrayInput(['command' => $commandName, 'types' => $params]), $output);
3941

40-
$model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, []);
42+
$definition = new InputDefinition([
43+
new InputArgument('types', InputArgument::REQUIRED),
44+
new InputArgument('command', InputArgument::REQUIRED),
45+
]);
46+
$command->expects($this->any())->method('setDefinition')->with($definition);
47+
48+
$model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, $params);
4149
$model->execute();
4250
}
4351

@@ -47,8 +55,8 @@ public function testSetCache($commandClass, $commandName, $jobName)
4755
public function setCacheDataProvider()
4856
{
4957
return [
50-
['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable'],
51-
['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable'],
58+
['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable', ['cache1']],
59+
['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable', []],
5260
];
5361
}
5462
}

0 commit comments

Comments
 (0)