Skip to content

Commit bd22a2c

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1201 from magento-engcom/develop-prs
Public Pull Requests #9943 #9941
2 parents 397f87b + 015424a commit bd22a2c

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ class ProcessCronQueueObserver implements ObserverInterface
9797
protected $_shell;
9898

9999
/**
100-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
100+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
101101
*/
102-
protected $timezone;
102+
protected $dateTime;
103103

104104
/**
105105
* @var \Symfony\Component\Process\PhpExecutableFinder
@@ -124,7 +124,7 @@ class ProcessCronQueueObserver implements ObserverInterface
124124
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
125125
* @param \Magento\Framework\App\Console\Request $request
126126
* @param \Magento\Framework\ShellInterface $shell
127-
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
127+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
128128
* @param \Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory
129129
* @param \Psr\Log\LoggerInterface $logger
130130
* @param \Magento\Framework\App\State $state
@@ -138,7 +138,7 @@ public function __construct(
138138
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
139139
\Magento\Framework\App\Console\Request $request,
140140
\Magento\Framework\ShellInterface $shell,
141-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
141+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
142142
\Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory,
143143
\Psr\Log\LoggerInterface $logger,
144144
\Magento\Framework\App\State $state
@@ -150,7 +150,7 @@ public function __construct(
150150
$this->_scopeConfig = $scopeConfig;
151151
$this->_request = $request;
152152
$this->_shell = $shell;
153-
$this->timezone = $timezone;
153+
$this->dateTime = $dateTime;
154154
$this->phpExecutableFinder = $phpExecutableFinderFactory->create();
155155
$this->logger = $logger;
156156
$this->state = $state;
@@ -170,7 +170,7 @@ public function __construct(
170170
public function execute(\Magento\Framework\Event\Observer $observer)
171171
{
172172
$pendingJobs = $this->_getPendingSchedules();
173-
$currentTime = $this->timezone->scopeTimeStamp();
173+
$currentTime = $this->dateTime->gmtTimestamp();
174174
$jobGroupsRoot = $this->_config->getJobs();
175175

176176
$phpPath = $this->phpExecutableFinder->find() ?: 'php';
@@ -274,7 +274,7 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
274274
);
275275
}
276276

277-
$schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->save();
277+
$schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp()))->save();
278278

279279
try {
280280
call_user_func_array($callback, [$schedule]);
@@ -285,7 +285,7 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
285285

286286
$schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime(
287287
'%Y-%m-%d %H:%M:%S',
288-
$this->timezone->scopeTimeStamp()
288+
$this->dateTime->gmtTimestamp()
289289
));
290290
}
291291

@@ -322,7 +322,7 @@ protected function _generate($groupId)
322322
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
323323
);
324324
$schedulePeriod = $rawSchedulePeriod * self::SECONDS_IN_MINUTE;
325-
if ($lastRun > $this->timezone->scopeTimeStamp() - $schedulePeriod) {
325+
if ($lastRun > $this->dateTime->gmtTimestamp() - $schedulePeriod) {
326326
return $this;
327327
}
328328

@@ -343,7 +343,7 @@ protected function _generate($groupId)
343343
* save time schedules generation was ran with no expiration
344344
*/
345345
$this->_cache->save(
346-
$this->timezone->scopeTimeStamp(),
346+
$this->dateTime->gmtTimestamp(),
347347
self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . $groupId,
348348
['crontab'],
349349
null
@@ -398,7 +398,7 @@ protected function _cleanup($groupId)
398398
'system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY,
399399
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
400400
);
401-
if ($lastCleanup > $this->timezone->scopeTimeStamp() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
401+
if ($lastCleanup > $this->dateTime->gmtTimestamp() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
402402
return $this;
403403
}
404404

@@ -431,7 +431,7 @@ protected function _cleanup($groupId)
431431
Schedule::STATUS_ERROR => $historyFailure * self::SECONDS_IN_MINUTE,
432432
];
433433

434-
$now = $this->timezone->scopeTimeStamp();
434+
$now = $this->dateTime->gmtTimestamp();
435435
/** @var Schedule $record */
436436
foreach ($history as $record) {
437437
$checkTime = $record->getExecutedAt() ? strtotime($record->getExecutedAt()) :
@@ -443,7 +443,7 @@ protected function _cleanup($groupId)
443443

444444
// save time history cleanup was ran with no expiration
445445
$this->_cache->save(
446-
$this->timezone->scopeTimeStamp(),
446+
$this->dateTime->gmtTimestamp(),
447447
self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId,
448448
['crontab'],
449449
null
@@ -475,7 +475,7 @@ protected function getConfigSchedule($jobConfig)
475475
*/
476476
protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
477477
{
478-
$currentTime = $this->timezone->scopeTimeStamp();
478+
$currentTime = $this->dateTime->gmtTimestamp();
479479
$timeAhead = $currentTime + $timeInterval;
480480
for ($time = $currentTime; $time < $timeAhead; $time += self::SECONDS_IN_MINUTE) {
481481
$ts = strftime('%Y-%m-%d %H:%M:00', $time);
@@ -503,7 +503,7 @@ protected function generateSchedule($jobCode, $cronExpression, $time)
503503
->setCronExpr($cronExpression)
504504
->setJobCode($jobCode)
505505
->setStatus(Schedule::STATUS_PENDING)
506-
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))
506+
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp()))
507507
->setScheduledAt(strftime('%Y-%m-%d %H:%M', $time));
508508

509509
return $schedule;

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ class ProcessCronQueueObserverTest extends \PHPUnit_Framework_TestCase
6464
protected $_cronGroupConfig;
6565

6666
/**
67-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
67+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
6868
*/
69-
protected $timezone;
69+
protected $dateTimeMock;
7070

7171
/**
7272
* @var \Magento\Framework\Event\Observer
@@ -126,8 +126,10 @@ protected function setUp()
126126

127127
$this->observer = $this->getMock(\Magento\Framework\Event\Observer::class, [], [], '', false);
128128

129-
$this->timezone = $this->getMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
130-
$this->timezone->expects($this->any())->method('scopeTimeStamp')->will($this->returnValue(time()));
129+
$this->dateTimeMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\DateTime::class)
130+
->disableOriginalConstructor()
131+
->getMock();
132+
$this->dateTimeMock->expects($this->any())->method('gmtTimestamp')->will($this->returnValue(time()));
131133

132134
$phpExecutableFinder = $this->getMock(\Symfony\Component\Process\PhpExecutableFinder::class, [], [], '', false);
133135
$phpExecutableFinder->expects($this->any())->method('find')->willReturn('php');
@@ -148,7 +150,7 @@ protected function setUp()
148150
$this->_scopeConfig,
149151
$this->_request,
150152
$this->_shell,
151-
$this->timezone,
153+
$this->dateTimeMock,
152154
$phpExecutableFinderFactory,
153155
$this->loggerMock,
154156
$this->appStateMock

app/code/Magento/Ui/Component/Listing/Columns/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function prepareDataSource(array $dataSource)
5757
$date = $this->timezone->date(new \DateTime($item[$this->getData('name')]));
5858
$timezone = isset($this->getConfiguration()['timezone'])
5959
? $this->booleanUtils->convert($this->getConfiguration()['timezone'])
60-
: false;
60+
: true;
6161
if (!$timezone) {
6262
$date = new \DateTime($item[$this->getData('name')]);
6363
}

0 commit comments

Comments
 (0)