Skip to content

Commit 8fa3fab

Browse files
author
Kopylova,Olga(okopylova)
committed
Merge pull request #446 from magento-ogre/PR_Branch
[Ogres] Bug Fixes
2 parents e239e1d + 42c438b commit 8fa3fab

File tree

18 files changed

+441
-385
lines changed

18 files changed

+441
-385
lines changed

app/code/Magento/Cron/Console/Command/CronCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class CronCommand extends Command
2929
const INPUT_KEY_GROUP = 'group';
3030

3131
/**
32-
* Object Manager
32+
* Object manager factory
3333
*
34-
* @var ObjectManagerInterface
34+
* @var ObjectManagerFactory
3535
*/
36-
protected $objectManager;
36+
private $objectManagerFactory;
3737

3838
/**
3939
* Constructor
@@ -42,10 +42,7 @@ class CronCommand extends Command
4242
*/
4343
public function __construct(ObjectManagerFactory $objectManagerFactory)
4444
{
45-
$params = $_SERVER;
46-
$params[StoreManager::PARAM_RUN_CODE] = 'admin';
47-
$params[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
48-
$this->objectManager = $objectManagerFactory->create($params);
45+
$this->objectManagerFactory = $objectManagerFactory;
4946
parent::__construct();
5047
}
5148

@@ -80,6 +77,11 @@ protected function configure()
8077
*/
8178
protected function execute(InputInterface $input, OutputInterface $output)
8279
{
80+
$omParams = $_SERVER;
81+
$omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
82+
$omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
83+
$objectManager = $this->objectManagerFactory->create($omParams);
84+
8385
$params[self::INPUT_KEY_GROUP] = $input->getOption(self::INPUT_KEY_GROUP);
8486
$params[Observer::STANDALONE_PROCESS_STARTED] = '0';
8587
$bootstrap = $input->getOption(Cli::INPUT_KEY_BOOTSTRAP);
@@ -94,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9496
}
9597
}
9698
/** @var \Magento\Framework\App\Cron $cronObserver */
97-
$cronObserver = $this->objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]);
99+
$cronObserver = $objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]);
98100
$cronObserver->launch();
99101
$output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>');
100102
}

app/code/Magento/Cron/Model/Observer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,12 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
229229

230230
$schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->save();
231231

232-
call_user_func_array($callback, [$schedule]);
232+
try {
233+
call_user_func_array($callback, [$schedule]);
234+
} catch (\Exception $e) {
235+
$schedule->setStatus(Schedule::STATUS_ERROR);
236+
throw $e;
237+
}
233238

234239
$schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime(
235240
'%Y-%m-%d %H:%M:%S',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Class CronJobException used to check that cron handles execution exception
9+
* Please see \Magento\Cron\Test\Unit\Model\ObserverTest
10+
*/
11+
namespace Magento\Cron\Test\Unit\Model;
12+
13+
class CronJobException
14+
{
15+
public function execute()
16+
{
17+
throw new \Exception('Test exception');
18+
}
19+
}

app/code/Magento/Cron/Test/Unit/Model/ObserverTest.php

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -293,37 +293,36 @@ public function testDispatchExceptionNoCallback()
293293
}
294294

295295
/**
296-
* Test case catch exception if callback exists but can't be executed
296+
* Test case catch exception if callback is not callable or throws exception
297+
*
298+
* @param string $cronJobType
299+
* @param mixed $cronJobObject
300+
* @param string $exceptionMessage
301+
* @param int $saveCalls
302+
*
303+
* @dataProvider dispatchExceptionInCallbackDataProvider
297304
*/
298-
public function testDispatchExceptionNotExecutable()
305+
public function testDispatchExceptionInCallback($cronJobType, $cronJobObject, $exceptionMessage, $saveCalls)
299306
{
300307
$jobConfig = [
301308
'test_group' => [
302-
'test_job1' => ['instance' => 'Not_Existed_Class', 'method' => 'notExistedMethod'],
309+
'test_job1' => ['instance' => $cronJobType, 'method' => 'execute'],
303310
],
304311
];
305312

306-
$exceptionMessage = 'Invalid callback: Not_Existed_Class::notExistedMethod can\'t be called';
307313
$this->_request->expects($this->any())->method('getParam')->will($this->returnValue('test_group'));
308-
$schedule = $this->getMockBuilder(
309-
'Magento\Cron\Model\Schedule'
310-
)->setMethods(
311-
['getJobCode', 'tryLockJob', 'getScheduledAt', 'save', 'setStatus', 'setMessages', '__wakeup']
312-
)->disableOriginalConstructor()->getMock();
314+
$schedule = $this->getMockBuilder('Magento\Cron\Model\Schedule')
315+
->setMethods(['getJobCode', 'tryLockJob', 'getScheduledAt', 'save', 'setStatus', 'setMessages', '__wakeup'])
316+
->disableOriginalConstructor()->getMock();
313317
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('test_job1'));
314318
$schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue('-1 day'));
315319
$schedule->expects($this->once())->method('tryLockJob')->will($this->returnValue(true));
316-
$schedule->expects(
317-
$this->once()
318-
)->method(
319-
'setStatus'
320-
)->with(
321-
$this->equalTo(\Magento\Cron\Model\Schedule::STATUS_ERROR)
322-
)->will(
323-
$this->returnSelf()
324-
);
320+
$schedule->expects($this->once())
321+
->method('setStatus')
322+
->with($this->equalTo(\Magento\Cron\Model\Schedule::STATUS_ERROR))
323+
->will($this->returnSelf());
325324
$schedule->expects($this->once())->method('setMessages')->with($this->equalTo($exceptionMessage));
326-
$schedule->expects($this->once())->method('save');
325+
$schedule->expects($this->exactly($saveCalls))->method('save');
327326

328327
$this->_collection->addItem($schedule);
329328

@@ -336,25 +335,41 @@ public function testDispatchExceptionNotExecutable()
336335
$scheduleMock = $this->getMockBuilder('Magento\Cron\Model\Schedule')->disableOriginalConstructor()->getMock();
337336
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
338337
$this->_scheduleFactory->expects($this->once())->method('create')->will($this->returnValue($scheduleMock));
339-
$this->_objectManager->expects(
340-
$this->once()
341-
)->method(
342-
'create'
343-
)->with(
344-
$this->equalTo('Not_Existed_Class')
345-
)->will(
346-
$this->returnValue('')
347-
);
338+
$this->_objectManager
339+
->expects($this->once())
340+
->method('create')
341+
->with($this->equalTo($cronJobType))
342+
->will($this->returnValue($cronJobObject));
348343

349344
$this->_observer->dispatch('');
350345
}
351346

347+
/**
348+
* @return array
349+
*/
350+
public function dispatchExceptionInCallbackDataProvider()
351+
{
352+
return [
353+
'non-callable callback' => [
354+
'Not_Existed_Class',
355+
'',
356+
'Invalid callback: Not_Existed_Class::execute can\'t be called',
357+
1
358+
],
359+
'exception in execution' => [
360+
'CronJobException',
361+
new \Magento\Cron\Test\Unit\Model\CronJobException(),
362+
'Test exception',
363+
2
364+
],
365+
];
366+
}
367+
352368
/**
353369
* Test case, successfully run job
354370
*/
355371
public function testDispatchRunJob()
356372
{
357-
require_once __DIR__ . '/CronJob.php';
358373
$testCronJob = new \Magento\Cron\Test\Unit\Model\CronJob();
359374

360375
$jobConfig = [

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,11 @@
185185
"components/jquery": [
186186
"lib/web/jquery.js",
187187
"lib/web/jquery/jquery.min.js",
188-
"lib/web/jquery/jquery-migrate.js",
189-
"lib/web/jquery/jquery-migrate.min.js"
188+
"lib/web/jquery/jquery-migrate.js"
190189
],
191190
"blueimp/jquery-file-upload": "lib/web/jquery/fileUploader",
192191
"components/jqueryui": [
193-
"lib/web/jquery/jquery-ui.js",
194-
"lib/web/jquery/jquery-ui.min.js"
192+
"lib/web/jquery/jquery-ui.js"
195193
],
196194
"twbs/bootstrap": [
197195
"lib/web/jquery/jquery.tabs.js"

0 commit comments

Comments
 (0)