Skip to content

Commit 243d5a5

Browse files
committed
fix
1 parent 7265d59 commit 243d5a5

File tree

1 file changed

+46
-42
lines changed
  • app/code/core/Mage/Reports/Model/Resource/Report

1 file changed

+46
-42
lines changed

app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected function _getFlag()
4343
* @param string $code
4444
* @param mixed $value
4545
* @return Mage_Reports_Model_Resource_Report_Abstract
46+
* @throws Throwable
4647
*/
4748
protected function _setFlagData($code, $value = null)
4849
{
@@ -143,14 +144,15 @@ protected function _clearTableByDateRange(
143144
/**
144145
* Generate table date range select
145146
*
146-
* @param string $table
147-
* @param string $column
148-
* @param string $whereColumn
149-
* @param null|string $from
150-
* @param null|string $to
151-
* @param array $additionalWhere
152-
* @param string $alias
147+
* @param string $table
148+
* @param string $column
149+
* @param string $whereColumn
150+
* @param null|string $from
151+
* @param null|string $to
152+
* @param array $additionalWhere
153+
* @param string $alias
153154
* @return Varien_Db_Select
155+
* @throws Zend_Db_Exception
154156
*/
155157
protected function _getTableDateRangeSelect(
156158
$table,
@@ -180,7 +182,7 @@ protected function _getTableDateRangeSelect(
180182
$select->where($alias . '.' . $whereColumn . ' <= ?', $to);
181183
}
182184

183-
if (!empty($additionalWhere)) {
185+
if ($additionalWhere !== []) {
184186
foreach ($additionalWhere as $condition) {
185187
if (is_array($condition) && count($condition) == 2) {
186188
$condition = $adapter->quoteInto($condition[0], $condition[1]);
@@ -292,7 +294,7 @@ protected function _getTableDateRangeRelatedSelect(
292294
[],
293295
)
294296
// phpcs:ignore Ecg.Sql.SlowQuery.SlowSql
295-
->distinct(true);
297+
->distinct();
296298

297299
if ($from !== null) {
298300
$select->where($relatedAlias . '.' . $whereColumn . ' >= ?', $from);
@@ -302,7 +304,7 @@ protected function _getTableDateRangeRelatedSelect(
302304
$select->where($relatedAlias . '.' . $whereColumn . ' <= ?', $to);
303305
}
304306

305-
if (!empty($additionalWhere)) {
307+
if ($additionalWhere !== []) {
306308
foreach ($additionalWhere as $condition) {
307309
if (is_array($condition) && count($condition) == 2) {
308310
$condition = $adapter->quoteInto($condition[0], $condition[1]);
@@ -328,18 +330,18 @@ protected function _getTableDateRangeRelatedSelect(
328330
/**
329331
* Check range dates and transforms it to strings
330332
*
331-
* @param mixed $from
332-
* @param mixed $to
333+
* @param mixed $fromDate
334+
* @param mixed $toDate
333335
* @return Mage_Reports_Model_Resource_Report_Abstract
334336
*/
335-
protected function _checkDates(&$from, &$to)
337+
protected function _checkDates(&$fromDate, &$toDate)
336338
{
337-
if ($from !== null) {
338-
$from = $this->formatDate($from);
339+
if ($fromDate !== null) {
340+
$fromDate = $this->formatDate($fromDate);
339341
}
340342

341-
if ($to !== null) {
342-
$to = $this->formatDate($to);
343+
if ($toDate !== null) {
344+
$toDate = $this->formatDate($toDate);
343345
}
344346

345347
return $this;
@@ -354,6 +356,7 @@ protected function _checkDates(&$from, &$to)
354356
* @param mixed $to
355357
* @param null|int|Mage_Core_Model_Store|string $store
356358
* @return string
359+
* @throws Zend_Db_Exception
357360
*/
358361
public function getStoreTZOffsetQuery($table, $column, $from = null, $to = null, $store = null)
359362
{
@@ -373,24 +376,24 @@ public function getStoreTZOffsetQuery($table, $column, $from = null, $to = null,
373376
$from,
374377
$to,
375378
);
376-
if (empty($periods)) {
379+
if ($periods === []) {
377380
return $column;
378381
}
379382

380383
$query = '';
381384
$periodsCount = count($periods);
382385

383-
$i = 0;
386+
$index = 0;
384387
foreach ($periods as $offset => $timestamps) {
385388
$subParts = [];
386-
foreach ($timestamps as $ts) {
387-
$subParts[] = "($column between {$ts['from']} and {$ts['to']})";
389+
foreach ($timestamps as $timestamp) {
390+
$subParts[] = "($column between {$timestamp['from']} and {$timestamp['to']})";
388391
}
389392

390393
$then = $this->_getWriteAdapter()
391394
->getDateAddSql($column, $offset, Varien_Db_Adapter_Interface::INTERVAL_SECOND);
392395

393-
$query .= (++$i == $periodsCount) ? $then : 'CASE WHEN ' . implode(' OR ', $subParts) . " THEN $then ELSE ";
396+
$query .= (++$index == $periodsCount) ? $then : 'CASE WHEN ' . implode(' OR ', $subParts) . " THEN $then ELSE ";
394397
}
395398

396399
return $query . str_repeat('END ', count($periods) - 1);
@@ -400,42 +403,41 @@ public function getStoreTZOffsetQuery($table, $column, $from = null, $to = null,
400403
* Retrieve transitions for offsets of given timezone
401404
*
402405
* @param string $timezone
403-
* @param mixed $from
404-
* @param mixed $to
406+
* @param mixed $fromDate
407+
* @param mixed $toDate
405408
* @return array
406409
*/
407-
protected function _getTZOffsetTransitions($timezone, $from = null, $to = null)
410+
protected function _getTZOffsetTransitions($timezone, $fromDate = null, $toDate = null)
408411
{
409412
$tzTransitions = [];
410413
try {
411-
if (!empty($from)) {
412-
$from = new Zend_Date($from, Varien_Date::DATETIME_INTERNAL_FORMAT);
413-
$from = $from->getTimestamp();
414+
if (!empty($fromDate)) {
415+
$fromDate = new Zend_Date($fromDate, Varien_Date::DATETIME_INTERNAL_FORMAT);
416+
$fromDate = $fromDate->getTimestamp();
414417
}
415418

416-
$to = new Zend_Date($to, Varien_Date::DATETIME_INTERNAL_FORMAT);
417-
$nextPeriod = $this->_getWriteAdapter()->formatDate($to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
418-
$to = $to->getTimestamp();
419+
$toDate = new Zend_Date($toDate, Varien_Date::DATETIME_INTERNAL_FORMAT);
420+
$nextPeriod = $this->_getWriteAdapter()->formatDate($toDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
421+
$toDate = $toDate->getTimestamp();
419422

420423
$dtz = new DateTimeZone($timezone);
421-
$transitions = $dtz->getTransitions();
424+
$transitions = array_reverse($dtz->getTransitions());
422425
$dateTimeObject = new Zend_Date('c');
423-
for ($i = count($transitions) - 1; $i >= 0; $i--) {
424-
$tr = $transitions[$i];
425-
if (!$this->_isValidTransition($tr, $to)) {
426+
foreach ($transitions as $transition) {
427+
if (!$this->_isValidTransition($transition, $toDate)) {
426428
continue;
427429
}
428430

429-
$dateTimeObject->set($tr['time']);
430-
$tr['time'] = $this->_getWriteAdapter()
431+
$dateTimeObject->set($transition['time']);
432+
$transition['time'] = $this->_getWriteAdapter()
431433
->formatDate($dateTimeObject->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
432-
$tzTransitions[$tr['offset']][] = ['from' => $tr['time'], 'to' => $nextPeriod];
434+
$tzTransitions[$transition['offset']][] = ['from' => $transition['time'], 'to' => $nextPeriod];
433435

434-
if (!empty($from) && $tr['ts'] < $from) {
436+
if (!empty($fromDate) && $transition['ts'] < $fromDate) {
435437
break;
436438
}
437439

438-
$nextPeriod = $tr['time'];
440+
$nextPeriod = $transition['time'];
439441
}
440442
} catch (Exception $exception) {
441443
$this->_logException($exception);
@@ -465,7 +467,8 @@ protected function _isValidTransition($transition, $to)
465467
{
466468
$result = true;
467469
$timeStamp = $transition['ts'];
468-
$transitionYear = Carbon::createFromTimestamp($timeStamp)->format('Y');
470+
$time = $transition['time'];
471+
$transitionYear = Carbon::createFromTimeString($time)->format('Y');
469472

470473
if ($transitionYear > 10000 || $transitionYear < -10000) {
471474
$result = false;
@@ -490,8 +493,9 @@ protected function _getStoreTimezoneUtcOffset($store = null)
490493
/**
491494
* Retrieve date in UTC timezone
492495
*
493-
* @param null|string $date
496+
* @param null|string $date
494497
* @return null|Zend_Date
498+
* @throws Zend_Date_Exception
495499
*/
496500
protected function _dateToUtc($date)
497501
{

0 commit comments

Comments
 (0)