diff --git a/.phpstan.dist.baseline.neon b/.phpstan.dist.baseline.neon index 4f9d022673f..86c89dd470b 100644 --- a/.phpstan.dist.baseline.neon +++ b/.phpstan.dist.baseline.neon @@ -618,18 +618,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/controllers/Customer/System/Config/ValidatevatController.php - - - message: '#^Parameter \#2 \$timestamp of function date expects int\|null, array\|bool given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Adminhtml/controllers/CustomerController.php - - - - message: '#^Parameter \#2 \$value of method Zend_Controller_Response_Abstract\:\:setHeader\(\) expects string, array\|bool given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Adminhtml/controllers/CustomerController.php - - message: '#^Variable \$id in isset\(\) always exists and is not nullable\.$#' identifier: isset.variable @@ -708,18 +696,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php - - - message: '#^Parameter \#1 \$order of method Mage_Sales_Model_Resource_Order_Collection_Abstract\:\:setOrderFilter\(\) expects int\|Mage_Sales_Model_Order, array\ given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php - - - - message: '#^Parameter \#1 \$prefix of function uniqid expects string, int\<0, max\> given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php - - message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(mixed\)\: bool\)\|null, ''\\\\intval'' given\.$#' identifier: argument.type @@ -2574,24 +2550,6 @@ parameters: count: 1 path: app/code/core/Mage/Core/Model/Config.php - - - message: '#^Binary operation "\+" between string and string results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: app/code/core/Mage/Core/Model/Date.php - - - - message: '#^Binary operation "\-" between string and string results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: app/code/core/Mage/Core/Model/Date.php - - - - message: '#^Property Mage_Core_Model_Date\:\:\$_systemOffset is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: app/code/core/Mage/Core/Model/Date.php - - message: '#^Call to an undefined method Mage_Core_Model_Resource_Design\:\:validate\(\)\.$#' identifier: method.notFound @@ -4296,12 +4254,6 @@ parameters: count: 1 path: app/code/core/Mage/Rss/Helper/Data.php - - - message: '#^Property Mage_Rule_Model_Abstract\:\:\$_conditions \(Mage_Rule_Model_Condition_Combine\) in empty\(\) is not falsy\.$#' - identifier: empty.property - count: 1 - path: app/code/core/Mage/Rule/Model/Abstract.php - - message: '#^Call to an undefined method Mage_Rule_Model_Action_Interface\:\:getId\(\)\.$#' identifier: method.notFound @@ -4380,12 +4332,6 @@ parameters: count: 1 path: app/code/core/Mage/Sales/Block/Recurring/Profiles.php - - - message: '#^Parameter \#1 \$order of method Mage_Sales_Model_Resource_Order_Collection_Abstract\:\:setOrderFilter\(\) expects int\|Mage_Sales_Model_Order, array given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Sales/Model/Api2/Order.php - - message: '#^Parameter \#2 \$code of method Mage_Api2_Model_Resource\:\:_critical\(\) expects int\|null, string given\.$#' identifier: argument.type diff --git a/.rector.php b/.rector.php index d22287c7c76..53800bea725 100644 --- a/.rector.php +++ b/.rector.php @@ -84,7 +84,7 @@ instanceOf: false, earlyReturn: false, strictBooleans: false, - carbon: false, + carbon: true, rectorPreset: false, phpunitCodeQuality: true, doctrineCodeQuality: false, diff --git a/app/Mage.php b/app/Mage.php index b70808e8ec0..ed4120b1bd6 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -7,6 +7,8 @@ * @package Mage */ +use Carbon\Carbon; + defined('DS') || define('DS', DIRECTORY_SEPARATOR); defined('PS') || define('PS', PATH_SEPARATOR); @@ -830,7 +832,7 @@ public static function isInstalled($options = []) if (is_readable($localConfigFile)) { $localConfig = simplexml_load_file($localConfigFile); date_default_timezone_set('UTC'); - if (($date = $localConfig->global->install->date) && strtotime((string) $date)) { + if (($date = $localConfig->global->install->date) && Carbon::parse((string) $date)->getTimestamp()) { self::$_isInstalled = true; } } diff --git a/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php b/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php index 4e37e73b319..27a9f587c6b 100644 --- a/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php +++ b/app/code/core/Mage/Admin/Model/Acl/Assert/Time.php @@ -7,6 +7,8 @@ * @package Mage_Admin */ +use Carbon\Carbon; + /** * Assert time for admin acl * @@ -26,7 +28,7 @@ public function assert( ?Mage_Admin_Model_Acl_Resource $resource = null, $privilege = null ) { - return $this->_isCleanTime(time()); + return $this->_isCleanTime(Carbon::now()->getTimestamp()); } /** diff --git a/app/code/core/Mage/Admin/Model/Resource/User.php b/app/code/core/Mage/Admin/Model/Resource/User.php index 68712653d3a..9f539e1a075 100644 --- a/app/code/core/Mage/Admin/Model/Resource/User.php +++ b/app/code/core/Mage/Admin/Model/Resource/User.php @@ -7,6 +7,8 @@ * @package Mage_Admin */ +use Carbon\Carbon; + /** * ACL user resource * @@ -47,7 +49,7 @@ public function recordLogin(Mage_Admin_Model_User $user) $adapter = $this->_getWriteAdapter(); $data = [ - 'logdate' => Varien_Date::now(), + 'logdate' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), 'lognum' => $user->getLognum() + 1, ]; diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index 001b6201269..7bf89fd96d1 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -7,6 +7,8 @@ * @package Mage_Admin */ +use Carbon\Carbon; + /** * Admin user model * @@ -670,7 +672,7 @@ public function changeResetPasswordLinkToken($newResetPasswordLinkToken) throw Mage::exception('Mage_Core', Mage::helper('adminhtml')->__('Invalid password reset token.')); } $this->setRpToken($newResetPasswordLinkToken); - $currentDate = Varien_Date::now(); + $currentDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $this->setRpTokenCreatedAt($currentDate); return $this; @@ -690,17 +692,14 @@ public function isResetPasswordLinkTokenExpired() return true; } - $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod(); - - $currentDate = Varien_Date::now(); - $currentTimestamp = Varien_Date::toTimestamp($currentDate); - $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt); + $currentTimestamp = Carbon::now(); + $tokenTimestamp = Carbon::now()->setTimeFromTimeString($resetPasswordLinkTokenCreatedAt); if ($tokenTimestamp > $currentTimestamp) { return true; } - $hoursDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60)); - if ($hoursDifference >= $tokenExpirationPeriod) { + $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod(); + if ($currentTimestamp->diffInDays($tokenTimestamp) >= $tokenExpirationPeriod) { return true; } @@ -729,7 +728,8 @@ public function cleanPasswordsValidationData() */ protected function _getDateNow($dayOnly = false) { - return Varien_Date::now($dayOnly); + $format = $dayOnly ? Mage_Core_Helper_Date::DATE_PHP_FORMAT : Mage_Core_Helper_Date::DATETIME_PHP_FORMAT; + return Carbon::now()->format($format); } /** diff --git a/app/code/core/Mage/AdminNotification/Model/Feed.php b/app/code/core/Mage/AdminNotification/Model/Feed.php index 8f399f323b2..9cc7a0b3d57 100644 --- a/app/code/core/Mage/AdminNotification/Model/Feed.php +++ b/app/code/core/Mage/AdminNotification/Model/Feed.php @@ -7,6 +7,8 @@ * @package Mage_AdminNotification */ +use Carbon\Carbon; + /** * AdminNotification Feed model * @@ -52,7 +54,7 @@ public function getFeedUrl() */ public function checkUpdate() { - if (($this->getFrequency() + $this->getLastUpdate()) > time()) { + if (($this->getFrequency() + $this->getLastUpdate()) > Carbon::now()->getTimestamp()) { return $this; } @@ -88,7 +90,7 @@ public function checkUpdate() */ public function getDate($rssDate) { - return gmdate(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($rssDate)); + return gmdate(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, Carbon::parse($rssDate)->getTimestamp()); } /** @@ -118,7 +120,7 @@ public function getLastUpdate() */ public function setLastUpdate() { - Mage::app()->saveCache(time(), 'admin_notifications_lastcheck'); + Mage::app()->saveCache(Carbon::now()->getTimestamp(), 'admin_notifications_lastcheck'); return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php index f9c096d21c9..3dd03d9c7ab 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Customer account form block * @@ -136,7 +138,7 @@ public function getCurrentStatus() $log = $this->getCustomerLog(); if ($log->getLogoutAt() || !$log->getLastVisitAt() - || strtotime(Varien_Date::now()) - strtotime($log->getLastVisitAt()) > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60 + || Carbon::parse(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT))->getTimestamp() - Carbon::parse($log->getLastVisitAt())->getTimestamp() > Mage_Log_Model_Visitor::getOnlineMinutesInterval() * 60 ) { return Mage::helper('customer')->__('Offline'); } diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php index 0e929a0f461..920ac80d7ec 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php @@ -8,6 +8,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Adminhtml dashboard google chart block * @@ -211,7 +213,7 @@ public function generateChart(): array $formats = Mage::app()->getLocale()->getTranslationList('datetime'); $format = $formats['yyMM'] ?? 'MM/yyyy'; $format = str_replace(['yyyy', 'yy', 'MM'], ['Y', 'y', 'm'], $format); - $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label)); + $this->_axisLabels[$idx][$_index] = Carbon::parse($_label)->format($format); break; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php index b7fc0a6e885..31bdb2606d1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php @@ -88,7 +88,7 @@ protected function _prepareForm() if ($queue->getQueueStartAt()) { $form->getElement('date')->setValue( - Mage::app()->getLocale()->date($queue->getQueueStartAt(), Varien_Date::DATETIME_INTERNAL_FORMAT), + Mage::app()->getLocale()->date($queue->getQueueStartAt(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), ); } diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php index 74d8d986637..b9f2e5bcc6b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php @@ -138,7 +138,7 @@ protected function _prepareForm() 'label' => Mage::helper('catalogrule')->__('From Date'), 'title' => Mage::helper('catalogrule')->__('From Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); $fieldset->addField('to_date', 'date', [ @@ -146,7 +146,7 @@ protected function _prepareForm() 'label' => Mage::helper('catalogrule')->__('To Date'), 'title' => Mage::helper('catalogrule')->__('To Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php index 1eac8e21291..95a9960db9a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php @@ -193,7 +193,7 @@ protected function _prepareForm() 'label' => Mage::helper('salesrule')->__('From Date'), 'title' => Mage::helper('salesrule')->__('From Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); $fieldset->addField('to_date', 'date', [ @@ -201,7 +201,7 @@ protected function _prepareForm() 'label' => Mage::helper('salesrule')->__('To Date'), 'title' => Mage::helper('salesrule')->__('To Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), - 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'input_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, ]); diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php index 24eace57b68..dfa0490cee2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php @@ -56,7 +56,7 @@ protected function _toHtml() ) { $id = "{$key}_{$idSuffix}"; $element = new Varien_Data_Form_Element_Date([ - 'format' => Varien_Date::DATE_INTERNAL_FORMAT, // hardcode because hardcoded values delimiter + 'format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, // hardcode because hardcoded values delimiter 'label' => $label, 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'onchange' => "dateTimeChoose_{$idSuffix}()", // won't work through Event.observe() diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php index 9fd9ebeb89c..fde616010b0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Dashboard Year-To-Date Month and Day starts Field Renderer * @@ -19,7 +21,7 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) $_months = []; for ($i = 1; $i <= 12; $i++) { $_months[$i] = Mage::app()->getLocale() - ->date(mktime(0, 0, 0, $i)) + ->date(Carbon::now()->setHour(0)->setMinute(0)->setSecond(0)->setMonth($i)) ->get(Zend_Date::MONTH_NAME); } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php index 52ba2298875..589af949275 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Adminhtml report grid block * @@ -104,10 +106,11 @@ protected function _prepareColumns() /** * @return $this + * @throws Zend_Date_Exception */ protected function _prepareCollection() { - $filter = $this->getParam($this->getVarNameFilter(), null); + $filter = $this->getParam($this->getVarNameFilter()); if (is_null($filter)) { $filter = $this->_defaultFilter; @@ -120,7 +123,13 @@ protected function _prepareCollection() if (!isset($data['report_from'])) { // getting all reports from 2001 year - $date = new Zend_Date(mktime(0, 0, 0, 1, 1, 2001)); + $date = new Zend_Date(Carbon::now() + ->setHour(0) + ->setMinute(0) + ->setSecond(0) + ->setMonth(1) + ->setYear(2001)); + $data['report_from'] = $date->toString($this->getLocale()->getDateFormat('short')); } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php index 971d6b1c7f1..4667c191a76 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php @@ -35,7 +35,7 @@ protected function _getUpdatedAt($reportCode) return ($flag->hasData()) ? Mage::app()->getLocale()->storeDate( 0, - new Zend_Date($flag->getLastUpdate(), Varien_Date::DATETIME_INTERNAL_FORMAT), + new Zend_Date($flag->getLastUpdate(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), true, ) : ''; diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php index 0cba9066e00..b9bc291b34d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php @@ -66,7 +66,7 @@ public function render(Varien_Object $row) $dateFormat = 'yyyy'; break; default: - $dateFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $dateFormat = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; break; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php index ead1475ede1..d6953c27a12 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php @@ -7,6 +7,7 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; /** * Adminhtml transaction detail @@ -97,7 +98,7 @@ protected function _toHtml() ($this->_txn->getIsClosed()) ? Mage::helper('sales')->__('Yes') : Mage::helper('sales')->__('No'), ); - $createdAt = (strtotime($this->_txn->getCreatedAt())) + $createdAt = (Carbon::parse($this->_txn->getCreatedAt())->getTimestamp()) ? $this->formatDate($this->_txn->getCreatedAt(), Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true) : $this->__('N/A'); $this->setCreatedAtHtml($this->escapeHtml($createdAt)); diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php index 0ebd7a1cc54..f535ae996a1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Sitemap grid link column renderer * @@ -21,9 +23,6 @@ class Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Time extends Mage_Adminhtml_Blo */ public function render(Varien_Object $row) { - return date( - Varien_Date::DATETIME_PHP_FORMAT, - strtotime($row->getSitemapTime()) + Mage::getSingleton('core/date')->getGmtOffset(), - ); + return Carbon::createFromTimestamp(Carbon::parse($row->getSitemapTime())->getTimestamp() + Mage::getSingleton('core/date')->getGmtOffset())->format(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); } } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php index f2099bed79c..27c825e46a5 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Custom import CSV file field for shipping table rates * @@ -30,7 +32,7 @@ public function getElementHtml() { $html = ''; - $html .= ''; + $html .= ''; $html .= << diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php index 99a44c3d681..c68ed79cfb2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php @@ -115,7 +115,7 @@ public function getValue($index = null) { if ($index) { if ($data = $this->getData('value', 'orig_' . $index)) { - return $data;//date('Y-m-d', strtotime($data)); + return $data; //date('Y-m-d', strtotime($data)); } return null; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php index 3eb9c9cbdff..4d21e6ae776 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php @@ -22,7 +22,7 @@ public function getValue($index = null) { if ($index) { if ($data = $this->getData('value', 'orig_' . $index)) { - return $data;//date('Y-m-d', strtotime($data)); + return $data; //date('Y-m-d', strtotime($data)); } return null; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php index 218f530d9e7..74b756fd5fb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php @@ -55,7 +55,7 @@ public function render(Varien_Object $row) try { if ($this->getColumn()->getGmtoffset()) { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format); + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)->toString($format); } else { $data = Mage::getSingleton('core/locale') ->date($data, Zend_Date::ISO_8601, null, false)->toString($format); @@ -63,7 +63,7 @@ public function render(Varien_Object $row) } catch (Exception $e) { if ($this->getColumn()->getTimezone()) { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format); + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)->toString($format); } else { $data = Mage::getSingleton('core/locale')->date($data, null, null, false)->toString($format); } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php index 71797a662bf..b02b1e29254 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php @@ -55,11 +55,11 @@ public function render(Varien_Object $row) $locale = $this->getColumn()->getLocale() ?? null; try { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT, $locale, $useTimezone) + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, $locale, $useTimezone) ->toString($format); } catch (Exception $e) { $data = Mage::app()->getLocale() - ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format); + ->date($data, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)->toString($format); } return $data; } diff --git a/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php b/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php index 7e241ae62eb..33d189e1d6b 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php @@ -92,7 +92,7 @@ protected function _showLastExecutionTime($flagCode, $refreshCode) $updatedAt = ($flag->hasData()) ? Mage::app()->getLocale()->storeDate( 0, - new Zend_Date($flag->getLastUpdate(), Varien_Date::DATETIME_INTERNAL_FORMAT), + new Zend_Date($flag->getLastUpdate(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), true, ) : 'undefined'; diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php index 2d5f239cf50..cadb630969e 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Order create model * @@ -1645,7 +1647,7 @@ protected function _getNewCustomerEmail($customer) $host = $this->getSession() ->getStore() ->getConfig(Mage_Customer_Model_Customer::XML_PATH_DEFAULT_EMAIL_DOMAIN); - $account = $customer->getIncrementId() ? $customer->getIncrementId() : time(); + $account = $customer->getIncrementId() ? $customer->getIncrementId() : Carbon::now()->getTimestamp(); $email = $account . '@' . $host; $account = $this->getData('account'); $account['email'] = $email; diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php index 7791a3a2cad..92f62a351cc 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Create random order * @@ -135,10 +137,19 @@ public function render() return $this; } + /** + * @throws Exception + */ protected function _getRandomDate() { - $timestamp = mktime(random_int(0, 23), random_int(0, 59), 0, random_int(1, 11), random_int(1, 28), random_int(2006, 2007)); - return date(Varien_Date::DATETIME_PHP_FORMAT, $timestamp); + return Carbon::now() + ->setHour(random_int(0, 23)) + ->setMinute(random_int(0, 59)) + ->setSecond(random_int(0, 0)) + ->setMonth(random_int(1, 11)) + ->setDay(random_int(1, 28)) + ->setYear(random_int(2006, 2007)) + ->format(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); } public function save() diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php index 0c0ad708b68..4b719aaca6f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * @package Mage_Adminhtml * @deprecated @@ -15,12 +17,14 @@ class Mage_Adminhtml_Model_System_Config_Source_Date_Short { public function toOptionArray() { + $format = 'm/d/y'; + $arr = []; $arr[] = ['label' => '', 'value' => '']; - $arr[] = ['label' => sprintf('MM/DD/YY (%s)', date('m/d/y')), 'value' => '%m/%d/%y']; - $arr[] = ['label' => sprintf('MM/DD/YYYY (%s)', date('m/d/Y')), 'value' => '%m/%d/%Y']; - $arr[] = ['label' => sprintf('DD/MM/YY (%s)', date('d/m/y')), 'value' => '%d/%m/%y']; - $arr[] = ['label' => sprintf('DD/MM/YYYY (%s)', date('d/m/Y')), 'value' => '%d/%m/%Y']; + $arr[] = ['label' => sprintf('MM/DD/YY (%s)', Carbon::now()->format($format)), 'value' => '%m/%d/%y']; + $arr[] = ['label' => sprintf('MM/DD/YYYY (%s)', Carbon::now()->format($format)), 'value' => '%m/%d/%Y']; + $arr[] = ['label' => sprintf('DD/MM/YY (%s)', Carbon::now()->format($format)), 'value' => '%d/%m/%y']; + $arr[] = ['label' => sprintf('DD/MM/YYYY (%s)', Carbon::now()->format($format)), 'value' => '%d/%m/%Y']; return $arr; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php index 4a188b92218..628637e879b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php @@ -81,7 +81,7 @@ public function saveAction() 'date_format' => $dateFormat, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, ]); $value = $filterInternal->filter($filterInput->filter($value)); } else { diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php index 634deced718..7e8b317c16d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Customer admin controller * @@ -322,7 +324,7 @@ public function saveAction() // Force new customer confirmation if ($isNewCustomer) { $customer->setPassword($data['account']['password']); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->setForceConfirmed(true); if ($customer->getPassword() === 'auto') { $sendPassToEmail = true; @@ -836,7 +838,7 @@ public function viewfileAction() ->setHeader('Pragma', 'public', true) ->setHeader('Content-type', $contentType, true) ->setHeader('Content-Length', $contentLength) - ->setHeader('Last-Modified', date('r', $contentModify)) + ->setHeader('Last-Modified', Carbon::createFromTimestamp($contentModify)->format('r')) ->clearBody(); $this->getResponse()->sendHeaders(); diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php index 5dbc3f7ab58..3e975f928c1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Adminhtml sales order shipment controller * @@ -556,6 +558,8 @@ public function createLabelAction() /** * Print label for one specific shipment + * + * @return Mage_Core_Controller_Varien_Action|void */ public function printLabelAction() { @@ -698,6 +702,7 @@ protected function _combineLabelsPdf(array $labelsContent) * * @param string $imageString * @return Zend_Pdf_Page|bool + * @throws Exception */ protected function _createPdfPageFromImageString($imageString) { @@ -712,7 +717,7 @@ protected function _createPdfPageFromImageString($imageString) imageinterlace($image, 0); $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_' - . uniqid(mt_rand()) . time() . '.png'; + . uniqid(random_int(0, mt_getrandmax()) . Carbon::now()->getTimestamp() . '.png'); imagepng($image, $tmpFileName); $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName); $page->drawImage($pdfImage, 0, 0, $xSize, $ySize); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php index ff15fa05281..754f5e26918 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Adminhtml account controller * @@ -44,6 +46,7 @@ protected function _getSyncFlag() * Synchronize action between storages * * @SuppressWarnings("PHPMD.Superglobals") + * @throws Throwable */ public function synchronizeAction() { @@ -56,7 +59,7 @@ public function synchronizeAction() $flag = $this->_getSyncFlag(); if ($flag && $flag->getState() == Mage_Core_Model_File_Storage_Flag::STATE_RUNNING && $flag->getLastUpdate() - && time() <= (strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL) + && Carbon::now()->lessThanOrEqualTo((string) (Carbon::parse($flag->getLastUpdate())->getTimestamp() + Mage_Core_Model_File_Storage_Flag::FLAG_TTL)) ) { return; } @@ -65,7 +68,7 @@ public function synchronizeAction() Mage::getSingleton('admin/session')->setSyncProcessStopWatch(false); $storage = ['type' => (int) $_REQUEST['storage']]; - if (isset($_REQUEST['connection']) && !empty($_REQUEST['connection'])) { + if (!empty($_REQUEST['connection'])) { $storage['connection'] = $_REQUEST['connection']; } @@ -93,23 +96,18 @@ public function statusAction() switch ($state) { case Mage_Core_Model_File_Storage_Flag::STATE_INACTIVE: $flagData = $flag->getFlagData(); - if (is_array($flagData)) { - if (isset($flagData['destination']) && !empty($flagData['destination'])) { - $result['destination'] = $flagData['destination']; - } + if (is_array($flagData) && !empty($flagData['destination'])) { + $result['destination'] = $flagData['destination']; } $state = Mage_Core_Model_File_Storage_Flag::STATE_INACTIVE; break; case Mage_Core_Model_File_Storage_Flag::STATE_RUNNING: if (!$flag->getLastUpdate() - || time() <= (strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL) + || Carbon::now()->lessThanOrEqualTo((string) (Carbon::parse($flag->getLastUpdate())->getTimestamp() + Mage_Core_Model_File_Storage_Flag::FLAG_TTL)) ) { $flagData = $flag->getFlagData(); - if (is_array($flagData) - && isset($flagData['source']) && !empty($flagData['source']) - && isset($flagData['destination']) && !empty($flagData['destination']) - ) { + if (is_array($flagData) && !empty($flagData['source']) && !empty($flagData['destination'])) { $result['message'] = Mage::helper('adminhtml')->__('Synchronizing %s to %s', $flagData['source'], $flagData['destination']); } else { $result['message'] = Mage::helper('adminhtml')->__('Synchronizing...'); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php index 14bbc5f2958..a652eca06b6 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php @@ -7,6 +7,8 @@ * @package Mage_Adminhtml */ +use Carbon\Carbon; + /** * Store controller * @@ -459,7 +461,7 @@ protected function _backupDatabase($failPath, $arguments = []) try { $backupDb = Mage::getModel('backup/db'); $backup = Mage::getModel('backup/backup') - ->setTime(time()) + ->setTime(Carbon::now()->getTimestamp()) ->setType('db') ->setPath(Mage::getBaseDir('var') . DS . 'backups'); diff --git a/app/code/core/Mage/Api/Model/Acl/Assert/Time.php b/app/code/core/Mage/Api/Model/Acl/Assert/Time.php index cccbff489d2..ea130587a79 100644 --- a/app/code/core/Mage/Api/Model/Acl/Assert/Time.php +++ b/app/code/core/Mage/Api/Model/Acl/Assert/Time.php @@ -7,6 +7,8 @@ * @package Mage_Api */ +use Carbon\Carbon; + /** * Assert time for admin acl * @@ -18,7 +20,6 @@ class Mage_Api_Model_Acl_Assert_Time implements Zend_Acl_Assert_Interface * Assert time * * @param string|null $privilege - * @return bool|null */ public function assert( Mage_Api_Model_Acl $acl, @@ -26,7 +27,7 @@ public function assert( ?Mage_Api_Model_Acl_Resource $resource = null, $privilege = null ) { - return $this->_isCleanTime(time()); + $this->_isCleanTime(Carbon::now()->getTimestamp()); } /** diff --git a/app/code/core/Mage/Api/Model/Resource/Role.php b/app/code/core/Mage/Api/Model/Resource/Role.php index ab761b13e0f..e7419528c5c 100644 --- a/app/code/core/Mage/Api/Model/Resource/Role.php +++ b/app/code/core/Mage/Api/Model/Resource/Role.php @@ -7,6 +7,8 @@ * @package Mage_Api */ +use Carbon\Carbon; + /** * ACL role resource * @@ -26,7 +28,7 @@ protected function _construct() */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if (!$object->getId()) { $object->setCreated($now); } diff --git a/app/code/core/Mage/Api/Model/Resource/User.php b/app/code/core/Mage/Api/Model/Resource/User.php index f0a08a2152d..8c8d0a3aebe 100644 --- a/app/code/core/Mage/Api/Model/Resource/User.php +++ b/app/code/core/Mage/Api/Model/Resource/User.php @@ -7,6 +7,8 @@ * @package Mage_Api */ +use Carbon\Carbon; + /** * ACL user resource * @@ -67,7 +69,7 @@ public function recordSession(Mage_Api_Model_User $user) ->from($this->getTable('api/session'), 'user_id') ->where('user_id = ?', $user->getId()) ->where('sessid = ?', $user->getSessid()); - $loginDate = Varien_Date::now(); + $loginDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if ($readAdapter->fetchRow($select)) { $writeAdapter->update( $this->getTable('api/session'), @@ -105,7 +107,7 @@ public function cleanOldSessions(?Mage_Api_Model_User $user) Varien_Db_Adapter_Interface::INTERVAL_SECOND, ); $where = [ - $readAdapter->quote(Varien_Date::now()) . ' > ' . $timeSubtract, + $readAdapter->quote(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)) . ' > ' . $timeSubtract, ]; if ($user) { $where['user_id = ?'] = $user->getId(); @@ -203,7 +205,7 @@ public function hasAssigned2Role($user) */ protected function _beforeSave(Mage_Core_Model_Abstract $user) { - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if (!$user->getId()) { $user->setCreated($now); } diff --git a/app/code/core/Mage/Api/Model/Session.php b/app/code/core/Mage/Api/Model/Session.php index c26074e9f02..4aa49f7ce95 100644 --- a/app/code/core/Mage/Api/Model/Session.php +++ b/app/code/core/Mage/Api/Model/Session.php @@ -7,6 +7,9 @@ * @package Mage_Api */ +use Carbon\Carbon; +use Carbon\CarbonInterface; + /** * Webservice api session * @@ -28,7 +31,7 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract */ public function start($sessionName = null) { - $this->_currentSessId = md5(time() . uniqid('', true) . $sessionName); + $this->_currentSessId = md5(Carbon::now()->getTimestamp() . uniqid('', true) . $sessionName); $this->sessionIds[] = $this->getSessionId(); return $this; } @@ -210,7 +213,7 @@ public function isSessionExpired($user) if (!$user->getId()) { return true; } - $timeout = strtotime(Varien_Date::now()) - strtotime($user->getLogdate()); + $timeout = Carbon::parse(Carbon::now()->format(CarbonInterface::DEFAULT_TO_STRING_FORMAT))->getTimestamp() - Carbon::parse($user->getLogdate())->getTimestamp(); return $timeout > Mage::getStoreConfig('api/config/session_timeout'); } diff --git a/app/code/core/Mage/Api2/Model/Acl/Global/Role.php b/app/code/core/Mage/Api2/Model/Acl/Global/Role.php index 6d6b73fdc6a..52db164e1a8 100644 --- a/app/code/core/Mage/Api2/Model/Acl/Global/Role.php +++ b/app/code/core/Mage/Api2/Model/Acl/Global/Role.php @@ -7,6 +7,8 @@ * @package Mage_Api2 */ +use Carbon\Carbon; + /** * API2 Global ACL Role model * @@ -58,9 +60,9 @@ protected function _construct() protected function _beforeSave() { if ($this->isObjectNew() && $this->getCreatedAt() === null) { - $this->setCreatedAt(Varien_Date::now()); + $this->setCreatedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } else { - $this->setUpdatedAt(Varien_Date::now()); + $this->setUpdatedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } //check and protect guest role diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php index bf04175e6d0..def0cf455aa 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php @@ -7,6 +7,8 @@ * @package Mage_Authorizenet */ +use Carbon\Carbon; + /** * Authorize.net request model for DirectPost model. * @@ -155,7 +157,7 @@ public function setDataFromOrder(Mage_Sales_Model_Order $order, Mage_Authorizene */ public function signRequestData() { - $fpTimestamp = (string) time(); + $fpTimestamp = (string) Carbon::now()->getTimestamp(); $signatureKey = $this->_getSignatureKey(); if (!empty($signatureKey)) { $hash = $this->_generateSha2RequestSign( diff --git a/app/code/core/Mage/Captcha/Model/Observer.php b/app/code/core/Mage/Captcha/Model/Observer.php index 345dd3bea76..13029e1b1be 100644 --- a/app/code/core/Mage/Captcha/Model/Observer.php +++ b/app/code/core/Mage/Captcha/Model/Observer.php @@ -7,6 +7,8 @@ * @package Mage_Captcha */ +use Carbon\Carbon; + /** * Captcha Observer * @@ -231,7 +233,8 @@ public function deleteOldAttempts() public function deleteExpiredImages() { foreach (Mage::app()->getWebsites(true) as $website) { - $expire = time() - Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore()) * 60; + $timeout = (int) Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore()); + $expire = Carbon::now()->subMinutes($timeout)->getTimestamp(); $imageDirectory = Mage::helper('captcha')->getImgDir($website); foreach (new DirectoryIterator($imageDirectory) as $file) { if ($file->isFile() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'png') { diff --git a/app/code/core/Mage/Captcha/Model/Resource/Log.php b/app/code/core/Mage/Captcha/Model/Resource/Log.php index 07644b84e56..19c1465a51c 100644 --- a/app/code/core/Mage/Captcha/Model/Resource/Log.php +++ b/app/code/core/Mage/Captcha/Model/Resource/Log.php @@ -7,6 +7,8 @@ * @package Mage_Captcha */ +use Carbon\Carbon; + /** * Log Attempts resource * @@ -127,7 +129,7 @@ public function deleteOldAttempts() { $this->_getWriteAdapter()->delete( $this->getMainTable(), - ['updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, time() - 60 * 30)], + ['updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, Carbon::now()->subSeconds(60 * 30)->getTimestamp())], ); } } diff --git a/app/code/core/Mage/Captcha/Model/Zend.php b/app/code/core/Mage/Captcha/Model/Zend.php index f7f666d4c3f..9c270976e56 100644 --- a/app/code/core/Mage/Captcha/Model/Zend.php +++ b/app/code/core/Mage/Captcha/Model/Zend.php @@ -7,6 +7,8 @@ * @package Mage_Captcha */ +use Carbon\Carbon; + /** * Implementation of Zend_Captcha * @@ -449,7 +451,7 @@ public function getWord() if (!is_array($sessionData)) { return null; } - return time() < $sessionData['expires'] ? $sessionData['data'] : null; + return Carbon::now()->lessThan($sessionData['expires']) ? $sessionData['data'] : null; } /** @@ -462,7 +464,7 @@ protected function _setWord($word) { $this->getSession()->setData( $this->_getFormIdKey(self::SESSION_WORD), - ['data' => $word, 'expires' => time() + $this->getTimeout()], + ['data' => $word, 'expires' => Carbon::now()->addSeconds($this->getTimeout())->getTimestamp()], ); $this->_word = $word; return $this; diff --git a/app/code/core/Mage/Catalog/Block/Product/New.php b/app/code/core/Mage/Catalog/Block/Product/New.php index b57ed274bfc..35c2f38aedb 100644 --- a/app/code/core/Mage/Catalog/Block/Product/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/New.php @@ -71,11 +71,11 @@ protected function _getProductCollection() { $todayStartOfDayDate = Mage::app()->getLocale()->date() ->setTime('00:00:00') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $todayEndOfDayDate = Mage::app()->getLocale()->date() ->setTime('23:59:59') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */ $collection = Mage::getResourceModel('catalog/product_collection'); diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php index 15339af8eb2..fa0463f6bbb 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php @@ -7,6 +7,8 @@ * @package Mage_Catalog */ +use Carbon\Carbon; + /** * Catalog product option date type * @@ -88,7 +90,6 @@ public function validateUserValue($values) public function prepareForCart() { if ($this->getIsValid() && $this->getUserValue() !== null) { - $option = $this->getOption(); $value = $this->getUserValue(); if (isset($value['date_internal']) && $value['date_internal'] != '') { @@ -103,10 +104,22 @@ public function prepareForCart() $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $timestamp += Mage::app()->getLocale()->date($value['date'], $format, null, false)->getTimestamp(); } else { - $timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']); + $timestamp += Carbon::now() + ->setHour(0) + ->setMinute(0) + ->setSecond(0) + ->setMonth($value['month']) + ->setDay($value['day']) + ->setYear($value['year']); } } else { - $timestamp += mktime(0, 0, 0, date('m'), date('d'), date('Y')); + $timestamp += Carbon::now() + ->setHour(0) + ->setMinute(0) + ->setSecond(0) + ->setMonth(Carbon::now()->format('m')) + ->setDay(Carbon::now()->format('d')) + ->setYear(Carbon::now()->format('Y')); } if ($this->_timeExists()) { @@ -120,11 +133,12 @@ public function prepareForCart() } } - $timestamp += 60 * 60 * $value['hour'] + 60 * $value['minute']; + $timestamp->addMinutes($value['minute']); + $timestamp->addHours($value['hour']); } $date = new Zend_Date($timestamp); - $result = $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + $result = $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); // Save date in internal format to avoid locale date bugs $this->_setInternalInRequest($result); @@ -144,7 +158,6 @@ public function prepareForCart() public function getFormattedOptionValue($optionValue) { if ($this->_formattedOptionValue === null) { - $option = $this->getOption(); if ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE) { $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM); $result = Mage::app()->getLocale()->date($optionValue, Zend_Date::ISO_8601, null, false) @@ -152,10 +165,10 @@ public function getFormattedOptionValue($optionValue) } elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME) { $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $result = Mage::app()->getLocale() - ->date($optionValue, Varien_Date::DATETIME_INTERNAL_FORMAT, null, false)->toString($format); + ->date($optionValue, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, null, false)->toString($format); } elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME) { $date = new Zend_Date($optionValue); - $result = date($this->is24hTimeFormat() ? 'H:i' : 'h:i a', $date->getTimestamp()); + $result = Carbon::createFromTimestamp($date->getTimestamp())->format($this->is24hTimeFormat() ? 'H:i' : 'h:i a'); } else { $result = $optionValue; } @@ -195,13 +208,13 @@ public function getEditableOptionValue($optionValue) */ public function parseOptionValue($optionValue, $productOptionValues) { - $timestamp = strtotime($optionValue); + $timestamp = Carbon::parse($optionValue)->getTimestamp(); if ($timestamp === false || $timestamp == -1) { return null; } $date = new Zend_Date($timestamp); - return $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + return $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } /** @@ -257,7 +270,7 @@ public function getYearStart() if (isset($_range[0]) && !empty($_range[0])) { return $_range[0]; } else { - return date('Y'); + return Carbon::now()->format('Y'); } } @@ -272,7 +285,7 @@ public function getYearEnd() if (isset($_range[1]) && !empty($_range[1])) { return $_range[1]; } else { - return date('Y'); + return Carbon::now()->format('Y'); } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php index 9c1510e6b96..0b929b1a820 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php @@ -7,6 +7,8 @@ * @package Mage_Catalog */ +use Carbon\Carbon; + /** * Catalog Product Mass processing resource model * @@ -84,7 +86,7 @@ public function updateAttributes($entityIds, $attrData, $storeId) */ protected function _updateUpdatedAt(array $entityIds): void { - $updatedAt = Varien_Date::now(); + $updatedAt = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $catalogProductTable = $this->getTable('catalog/product'); $adapter = $this->_getWriteAdapter(); diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Indexer.php index 3dbe6bb7ee6..f8d69f91eb7 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer.php @@ -7,6 +7,8 @@ * @package Mage_CatalogIndex */ +use Carbon\Carbon; + /** * CatalogIndex Index operation model * @@ -703,7 +705,7 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p if (isset($values[$code]['from']) && isset($values[$code]['to'])) { if ($values[$code]['from']) { if (!is_numeric($values[$code]['from'])) { - $_date = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['from'])); + $_date = Carbon::parse($values[$code]['from'])->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT); $values[$code]['from'] = $_date; } @@ -712,7 +714,7 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p if ($values[$code]['to']) { if (!is_numeric($values[$code]['to'])) { - $values[$code]['to'] = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['to'])); + $values[$code]['to'] = Carbon::parse($values[$code]['to'])->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT); } $filter[$code]->where('value <= ?', $values[$code]['to']); } diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php index a2746d2a53a..baa8e1464c9 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php @@ -7,6 +7,8 @@ * @package Mage_CatalogIndex */ +use Carbon\Carbon; + /** * Resource Model CatalogIndex Aggregation * @@ -91,7 +93,7 @@ public function saveCacheData($data, $key, $tags, $storeId) } else { $this->_getWriteAdapter()->insert($this->getMainTable(), array( 'store_id' => $storeId, - 'created_at'=> $this->formatDate(time()), + 'created_at'=> $this->formatDate(Carbon::now()->getTimestamp()), 'key' => $key, 'data' => $data )); @@ -100,10 +102,10 @@ public function saveCacheData($data, $key, $tags, $storeId) */ $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), [ - 'store_id' => $storeId, - 'created_at' => $this->formatDate(time()), - 'key' => $key, - 'data' => $data, + 'store_id' => $storeId, + 'created_at' => $this->formatDate(Carbon::now()->getTimestamp()), + 'key' => $key, + 'data' => $data, ], ['created_at', 'data']); $id = $this->_getWriteAdapter()->lastInsertId($this->getMainTable()); diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php index e83bacee688..a807216a879 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php @@ -756,7 +756,7 @@ protected function _beforeSave() $this->setLowStockDate(null); if ($this->verifyNotification()) { $this->setLowStockDate(Mage::app()->getLocale()->date(null, null, null, false) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } $this->setStockStatusChangedAutomatically(0); diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php index 899b50665d5..5f0a22c9e32 100644 --- a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php @@ -7,6 +7,8 @@ * @package Mage_CatalogRule */ +use Carbon\Carbon; + /** * Catalog rules resource model * @@ -177,22 +179,24 @@ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $website $customerGroupIds = $rule->getCustomerGroupIds(); - $fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getFromDate())); - $toTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getToDate())); - $toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0; + $fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(Carbon::parse((string) $rule->getFromDate())->getTimestamp()); + $toTime = (int) Mage::getModel('core/date')->gmtTimestamp(Carbon::parse((string) $rule->getToDate())->getTimestamp()); + $toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0; - $timestamp = time(); + $timestamp = Carbon::now()->getTimestamp(); if ($fromTime > $timestamp || ($toTime && $toTime < $timestamp) ) { return; } - $sortOrder = (int) $rule->getSortOrder(); - $actionOperator = $rule->getSimpleAction(); - $actionAmount = (float) $rule->getDiscountAmount(); - $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; - $subActionAmount = (float) $rule->getSubDiscountAmount(); - $actionStop = (int) $rule->getStopRulesProcessing(); + + $sortOrder = (string) $rule->getSortOrder(); + $actionOperator = $rule->getSimpleAction(); + $actionAmount = (string) $rule->getDiscountAmount(); + $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; + $subActionAmount = (string) $rule->getSubDiscountAmount(); + $actionStop = (string) $rule->getStopRulesProcessing(); + /** @var Mage_Catalog_Helper_Product_Flat $helper */ $helper = $this->_factory->getHelper('catalog/product_flat'); @@ -687,7 +691,7 @@ public function getRulesFromProduct($date, $websiteId, $customerGroupId, $produc { $adapter = $this->_getReadAdapter(); if (is_string($date)) { - $date = strtotime($date); + $date = Carbon::parse($date)->getTimestamp(); } $select = $adapter->select() ->from($this->getTable('catalogrule/rule_product')) diff --git a/app/code/core/Mage/CatalogRule/Model/Rule.php b/app/code/core/Mage/CatalogRule/Model/Rule.php index 1de3ff99a83..e205d446173 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule.php @@ -7,6 +7,8 @@ * @package Mage_CatalogRule */ +use Carbon\Carbon; + /** * Catalog Rule data model * @@ -180,7 +182,7 @@ public function getCustomerGroupIds() public function getNow() { if (!$this->_now) { - return Varien_Date::now(); + return Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); } return $this->_now; } @@ -354,7 +356,7 @@ public function calcProductPriceRule(Mage_Catalog_Model_Product $product, $price $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); } $dateTs = Mage::app()->getLocale()->date()->getTimestamp(); - $cacheKey = date('Y-m-d', $dateTs) . "|$websiteId|$customerGroupId|$productId|$price"; + $cacheKey = Carbon::createFromTimestamp($dateTs)->format('Y-m-d') . "|$websiteId|$customerGroupId|$productId|$price"; if (!array_key_exists($cacheKey, self::$_priceRulesData)) { $rulesData = $this->_getResource()->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId); diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php index aff1c0e6bee..cb43a69964c 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php @@ -7,6 +7,8 @@ * @package Mage_CatalogRule */ +use Carbon\Carbon; + /** * Catalog Rule Product Condition data model * @@ -98,7 +100,7 @@ protected function _prepareDatetimeValue($value, $object) if (!$value) { return null; } - $value = strtotime($value); + $value = Carbon::parse($value)->getTimestamp(); } return $value; } diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php index c691c843a6e..fe5464b3471 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php @@ -808,7 +808,7 @@ protected function _getStoreDate($storeId, $date = null) if (!is_empty_date($date)) { [$dateObj, $format] = $this->_dates[$storeId]; - $dateObj->setDate($date, Varien_Date::DATETIME_INTERNAL_FORMAT); + $dateObj->setDate($date, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); return $dateObj->toString($format); } diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php index 646087584d7..83d2bc1ac97 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php @@ -7,6 +7,8 @@ * @package Mage_Checkout */ +use Carbon\Carbon; + /** * Checkout api resource for Customer * @@ -128,7 +130,7 @@ protected function _prepareNewCustomerQuote(Mage_Sales_Model_Quote $quote) Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $quote->setCustomer($customer) ->setCustomerId(true); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 9d27ad7b6f5..46834258c19 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -7,6 +7,8 @@ * @package Mage_Checkout */ +use Carbon\Carbon; + /** * One page checkout processing model * @@ -708,7 +710,7 @@ protected function _prepareNewCustomerQuote() Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $quote->setCustomer($customer) ->setCustomerId(true); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php index f1812fd89e7..e08b9959f30 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php @@ -7,6 +7,8 @@ * @package Mage_Cms */ +use Carbon\Carbon; + /** * Wysiwyg Images model * @@ -336,7 +338,7 @@ public function getThumbnailUrl($filePath, $checkFile = false) if (str_starts_with($filePath, $mediaRootDir)) { $thumbSuffix = self::THUMBS_DIRECTORY_NAME . DS . substr($filePath, strlen($mediaRootDir)); if (!$checkFile || is_readable($this->getHelper()->getStorageRoot() . $thumbSuffix)) { - $randomIndex = '?rand=' . time(); + $randomIndex = '?rand=' . Carbon::now()->getTimestamp(); $thumbUrl = $this->getHelper()->getBaseUrl() . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY . DS . $thumbSuffix; return str_replace('\\', '/', $thumbUrl) . $randomIndex; diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php index 8000171305c..ec5bacec9c7 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -8,13 +8,16 @@ */ /** @var Mage_Core_Model_Resource_Setup $installer */ + +use Carbon\Carbon; + $installer = $this; $installer->startSetup(); /** @var Varien_Db_Adapter_Pdo_Mysql $connection */ $connection = $installer->getConnection(); -$now = Varien_Date::now(); +$now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $connection->insert($installer->getTable('cms/page'), [ 'title' => 'Enable Cookies', 'root_template' => 'one_column', diff --git a/app/code/core/Mage/Core/Block/Html/Date.php b/app/code/core/Mage/Core/Block/Html/Date.php index d9bc450f0bb..9ce80dae144 100644 --- a/app/code/core/Mage/Core/Block/Html/Date.php +++ b/app/code/core/Mage/Core/Block/Html/Date.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * HTML select element block * @@ -77,7 +79,7 @@ protected function _toHtml() public function getEscapedValue($index = null) { if ($this->getFormat() && $this->getValue()) { - return date($this->getFormat(), strtotime($this->getValue())); + return Carbon::parse($this->getValue())->format($this->getFormat()); } return htmlspecialchars($this->getValue()); diff --git a/app/code/core/Mage/Core/Controller/Front/Action.php b/app/code/core/Mage/Core/Controller/Front/Action.php index 4202b410055..c9648f84fce 100644 --- a/app/code/core/Mage/Core/Controller/Front/Action.php +++ b/app/code/core/Mage/Core/Controller/Front/Action.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Base front controller * @@ -123,7 +125,7 @@ protected function _prepareDownloadResponse( ->setHeader('Content-type', $contentType, true) ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength) ->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"') - ->setHeader('Last-Modified', date('r')); + ->setHeader('Last-Modified', Carbon::now()->format('r')); if (!is_null($content)) { if ($isFile) { diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 82d8803dbcd..24d5cbb5773 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Custom Zend_Controller_Action class (formally) * @@ -973,14 +975,19 @@ protected function _filterDates($array, $dateFields) if (empty($dateFields)) { return $array; } + $filterInput = new Zend_Filter_LocalizedToNormalized([ + 'date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), + ]); + $filterInternal = new Zend_Filter_NormalizedToLocalized([ + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, + ]); - $filter = new Varien_Data_Form_Filter_Date(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); foreach ($dateFields as $dateField) { - if (!empty($dateField) && isset($array[$dateField]) && $array[$dateField] !== '') { - $array[$dateField] = $filter->inputFilter($array[$dateField]); + if ($dateField && !empty($array[$dateField])) { + $array[$dateField] = $filterInput->filter($array[$dateField]); + $array[$dateField] = $filterInternal->filter($array[$dateField]); } } - return $array; } @@ -996,14 +1003,19 @@ protected function _filterDateTime($array, $dateFields) if (empty($dateFields)) { return $array; } + $filterInput = new Zend_Filter_LocalizedToNormalized([ + 'date_format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), + ]); + $filterInternal = new Zend_Filter_NormalizedToLocalized([ + 'date_format' => Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, + ]); - $filter = new Varien_Data_Form_Filter_Datetime(Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); foreach ($dateFields as $dateField) { - if (!empty($dateField) && isset($array[$dateField]) && $array[$dateField] !== '') { - $array[$dateField] = $filter->inputFilter($array[$dateField]); + if (array_key_exists($dateField, $array) && !empty($dateField)) { + $array[$dateField] = $filterInput->filter($array[$dateField]); + $array[$dateField] = $filterInternal->filter($array[$dateField]); } } - return $array; } @@ -1051,7 +1063,7 @@ protected function _prepareDownloadResponse( ->setHeader('Content-type', $contentType, true) ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true) ->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true) - ->setHeader('Last-Modified', date('r'), true); + ->setHeader('Last-Modified', Carbon::now()->format('r'), true); if (!is_null($content)) { if ($isFile) { diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index c6edf8db4ee..14de7b0ddd9 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -7,6 +7,9 @@ * @package Mage_Core */ +use Carbon\Carbon; +use Carbon\Exceptions\InvalidFormatException; + /** * Core data helper * @@ -173,9 +176,10 @@ public function formatTimezoneDate( } elseif (is_int($date)) { $date = $locale->date($date, null, null, $useTimezone); } elseif (!$date instanceof Zend_Date) { - if (($time = strtotime($date)) !== false) { - $date = $locale->date($time, null, null, $useTimezone); - } else { + try { + $date = $locale->date(Carbon::parse($date)->getTimestamp(), null, null, $useTimezone); + } catch (InvalidFormatException) { + // If date parsing fails, return empty string return ''; } } @@ -200,11 +204,11 @@ public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMA $locale = Mage::app()->getLocale(); if (is_null($time)) { - $date = $locale->date(time()); + $date = $locale->date(Carbon::now()->getTimestamp()); } elseif ($time instanceof Zend_Date) { $date = $time; } else { - $date = $locale->date(strtotime($time)); + $date = $locale->date(Carbon::parse($time)->getTimestamp()); } if ($showDate) { diff --git a/app/code/core/Mage/Core/Helper/Date.php b/app/code/core/Mage/Core/Helper/Date.php new file mode 100644 index 00000000000..50504b3bc69 --- /dev/null +++ b/app/code/core/Mage/Core/Helper/Date.php @@ -0,0 +1,32 @@ +addSeconds($period)->getTimestamp(); } if (is_null($path)) { $path = $this->getPath(); diff --git a/app/code/core/Mage/Core/Model/Date.php b/app/code/core/Mage/Core/Model/Date.php index 23546299ef7..25f44f93b1d 100644 --- a/app/code/core/Mage/Core/Model/Date.php +++ b/app/code/core/Mage/Core/Model/Date.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Date conversion model * @@ -21,13 +23,6 @@ class Mage_Core_Model_Date */ private $_offset = 0; - /** - * Current system offset in seconds - * - * @var int - */ - private $_systemOffset = 0; - /** * Init offset * @@ -35,7 +30,6 @@ class Mage_Core_Model_Date public function __construct() { $this->_offset = $this->calculateOffset($this->_getConfigTimezone()); - $this->_systemOffset = $this->calculateOffset(); } /** @@ -67,7 +61,7 @@ public function calculateOffset($timezone = null) } if ($result === true) { - $offset = (int) date('Z'); + $offset = (int) Carbon::now()->format('Z'); } if (!is_null($timezone)) { @@ -87,7 +81,7 @@ public function calculateOffset($timezone = null) public function gmtDate($format = null, $input = null) { if (is_null($format)) { - $format = Varien_Date::DATETIME_PHP_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_PHP_FORMAT; } $date = $this->gmtTimestamp($input); @@ -96,7 +90,7 @@ public function gmtDate($format = null, $input = null) return false; } - return date($format, (int) $date); + return Carbon::createFromTimestamp((int) $date)->format($format); } /** @@ -110,10 +104,10 @@ public function gmtDate($format = null, $input = null) public function date($format = null, $input = null) { if (is_null($format)) { - $format = Varien_Date::DATETIME_PHP_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_PHP_FORMAT; } - return date($format, $this->timestamp($input)); + return Carbon::createFromTimestamp($this->timestamp($input))->format($format); } /** @@ -129,7 +123,7 @@ public function gmtTimestamp($input = null) } elseif (is_numeric($input)) { $result = $input; } else { - $result = strtotime($input); + $result = Carbon::parse($input)->getTimestamp(); } if ($result === false) { @@ -138,7 +132,7 @@ public function gmtTimestamp($input = null) } $date = Mage::app()->getLocale()->date($result); - $timestamp = $date->get(Zend_Date::TIMESTAMP) - $date->get(Zend_Date::TIMEZONE_SECS); + $timestamp = (int) $date->get(Zend_Date::TIMESTAMP) - (int) $date->get(Zend_Date::TIMEZONE_SECS); unset($date); return $timestamp; @@ -158,11 +152,11 @@ public function timestamp($input = null) } elseif (is_numeric($input)) { $result = $input; } else { - $result = strtotime($input); + $result = Carbon::parse($input)->getTimestamp(); } $date = Mage::app()->getLocale()->date($result); - $timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS); + $timestamp = (int) $date->get(Zend_Date::TIMESTAMP) + (int) $date->get(Zend_Date::TIMEZONE_SECS); unset($date); return $timestamp; diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index e8a9bd9a761..4cfa4e7d362 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Locale model * @@ -581,9 +583,9 @@ public function storeTimeStamp($store = null) $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE); $currentTimezone = @date_default_timezone_get(); @date_default_timezone_set($timezone); - $date = date(Varien_Date::DATETIME_PHP_FORMAT); + $date = date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); @date_default_timezone_set($currentTimezone); - return strtotime($date); + return Carbon::parse($date)->getTimestamp(); } /** @@ -828,8 +830,8 @@ public function isStoreDateInInterval($store, $dateFrom = null, $dateTo = null) } $storeTimeStamp = $this->storeTimeStamp($store); - $fromTimeStamp = strtotime((string) $dateFrom); - $toTimeStamp = strtotime((string) $dateTo); + $fromTimeStamp = Carbon::parse((string) $dateFrom)->getTimestamp(); + $toTimeStamp = Carbon::parse((string) $dateTo)->getTimestamp(); if ($dateTo) { // fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59 $toTimeStamp += 86400; diff --git a/app/code/core/Mage/Core/Model/Resource/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Abstract.php index 29c1a11b32c..c9e2b6aacf3 100644 --- a/app/code/core/Mage/Core/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Abstract resource model * @@ -134,7 +136,7 @@ public function formatDate($date, $includeTime = true) */ public function mktime($str) { - return Varien_Date::toTimestamp($str); + return Carbon::now()->setTimeFromTimeString($str)->getTimestamp(); } /** diff --git a/app/code/core/Mage/Core/Model/Resource/Design.php b/app/code/core/Mage/Core/Model/Resource/Design.php index 9d37eef29b4..c3bfccfeb13 100644 --- a/app/code/core/Mage/Core/Model/Resource/Design.php +++ b/app/code/core/Mage/Core/Model/Resource/Design.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Core Design Resource Model * @@ -22,6 +24,7 @@ protected function _construct() /** * @param Mage_Core_Model_Design $object * @inheritDoc + * @throws Mage_Core_Exception */ public function _beforeSave(Mage_Core_Model_Abstract $object) { @@ -32,7 +35,7 @@ public function _beforeSave(Mage_Core_Model_Abstract $object) if (!$validator->isValid($dateFrom) || !$validator->isValid($dateTo)) { Mage::throwException(Mage::helper('core')->__('Invalid date')); } - if (Varien_Date::toTimestamp($dateFrom) > Varien_Date::toTimestamp($dateTo)) { + if (Carbon::now()->setTimeFromTimeString($dateFrom) > Carbon::now()->setTimeFromTimeString($dateTo)) { Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); } } @@ -134,7 +137,7 @@ protected function _checkIntersection($storeId, $dateFrom, $dateTo, $currentId) public function loadChange($storeId, $date = null) { if (is_null($date)) { - $date = Varien_Date::now(); + $date = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); } $select = $this->_getReadAdapter()->select() diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index ca86a9b5ecb..30634c03665 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Mysql4 session save handler * @@ -189,7 +191,7 @@ public function read($sessId) ->where('session_expires > :session_expires'); $bind = [ 'session_id' => $sessId, - 'session_expires' => Varien_Date::toTimestamp(true), + 'session_expires' => Carbon::now()->getTimestamp(), ]; $data = $this->_read->fetchOne($select, $bind); @@ -216,7 +218,7 @@ public function write($sessId, $sessData) $exists = $this->_read->fetchOne($select, $bindValues); $bind = [ - 'session_expires' => Varien_Date::toTimestamp(true) + $this->getLifeTime(), + 'session_expires' => Carbon::now()->addSeconds($this->getLifeTime())->getTimestamp(), 'session_data' => $sessData, ]; if ($exists) { @@ -260,7 +262,7 @@ public function gc($sessMaxLifeTime) if ($this->_automaticCleaningFactor == 1 || random_int(1, $this->_automaticCleaningFactor) == 1 ) { - $where = ['session_expires < ?' => Varien_Date::toTimestamp(true)]; + $where = ['session_expires < ?' => Carbon::now()->getTimestamp()]; $this->_write->delete($this->_sessionTable, $where); } } diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php index 12fe0a0ea7f..5467e9a4dee 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * @package Mage_Core * @@ -481,7 +483,7 @@ public function validate() // Refresh expire timestamp if ($this->useValidateSessionExpire() || $this->useValidateSessionPasswordTimestamp()) { - $this->setValidatorSessionRenewTimestamp(time()); + $this->setValidatorSessionRenewTimestamp(Carbon::now()->getTimestamp()); $_SESSION[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_LIFETIME] = $this->getCookie()->getLifetime(); } } @@ -545,16 +547,14 @@ protected function _validate() if ($this->useValidateSessionExpire() && isset($sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP]) && isset($sessionData[self::VALIDATOR_SESSION_LIFETIME]) - && ((int) $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + (int) $sessionData[self::VALIDATOR_SESSION_LIFETIME]) - < time() + && Carbon::now()->greaterThan((string) ((int) $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + (int) $sessionData[self::VALIDATOR_SESSION_LIFETIME])) ) { return false; } if ($this->useValidateSessionPasswordTimestamp() && isset($validatorData[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP]) && isset($sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP]) - && $validatorData[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP] - > $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + && $validatorData[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP] > $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] ) { return false; } diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php index cdc19b80d2b..3e3db9743da 100644 --- a/app/code/core/Mage/Core/functions.php +++ b/app/code/core/Mage/Core/functions.php @@ -7,6 +7,8 @@ * @package Mage_Core */ +use Carbon\Carbon; + /** * Object destructor * @@ -55,11 +57,12 @@ function uc_words($str, $destSep = '_', $srcSep = '_') * @param bool $dayOnly * @return string * @deprecated use equivalent Varien method directly - * @see Varien_Date::now() + * @see Carbon::now() */ function now($dayOnly = false) { - return Varien_Date::now($dayOnly); + $format = $dayOnly ? 'Y-m-d' : Carbon::DEFAULT_TO_STRING_FORMAT; + return Carbon::now()->format($format); } /** diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php index 2313924001c..93d7ef60ece 100644 --- a/app/code/core/Mage/Cron/Model/Observer.php +++ b/app/code/core/Mage/Cron/Model/Observer.php @@ -7,6 +7,8 @@ * @package Mage_Cron */ +use Carbon\Carbon; + /** * Crontab observer * @@ -104,7 +106,7 @@ public function generate() * check if schedule generation is needed */ $lastRun = Mage::app()->loadCache(self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT); - if ($lastRun > time() - Mage::getStoreConfig(self::XML_PATH_SCHEDULE_GENERATE_EVERY) * 60) { + if ($lastRun > Carbon::now()->subMinutes(Mage::getStoreConfig(self::XML_PATH_SCHEDULE_GENERATE_EVERY))->getTimestamp()) { return $this; } @@ -133,7 +135,7 @@ public function generate() /** * save time schedules generation was ran with no expiration */ - Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); + Mage::app()->saveCache(Carbon::now()->getTimestamp(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); return $this; } @@ -162,14 +164,14 @@ protected function _generateJobs($jobs, $exists) continue; } - $now = time(); + $now = Carbon::now()->getTimestamp(); $timeAhead = $now + $scheduleAheadFor; $schedule->setJobCode($jobCode) ->setCronExpr($cronExpr) ->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING); for ($time = $now; $time < $timeAhead; $time += 60) { - $ts = date('Y-m-d H:i:00', $time); + $ts = Carbon::createFromTimestamp($time)->format('Y-m-d H:i:00'); if (!empty($exists[$jobCode . '/' . $ts])) { // already scheduled continue; @@ -193,7 +195,7 @@ public function cleanup() { // check if history cleanup is needed $lastCleanup = Mage::app()->loadCache(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT); - if ($lastCleanup > time() - Mage::getStoreConfig(self::XML_PATH_HISTORY_CLEANUP_EVERY) * 60) { + if ($lastCleanup > Carbon::now()->subMinutes(Mage::getStoreConfig(self::XML_PATH_HISTORY_CLEANUP_EVERY))->getTimestamp()) { return $this; } @@ -211,17 +213,17 @@ public function cleanup() Mage_Cron_Model_Schedule::STATUS_ERROR => Mage::getStoreConfig(self::XML_PATH_HISTORY_FAILURE) * 60, ]; - $now = time(); + $now = Carbon::now()->getTimestamp(); foreach ($history->getIterator() as $record) { if (empty($record->getExecutedAt()) - || (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) + || (Carbon::parse($record->getExecutedAt())->getTimestamp() < $now - $historyLifetimes[$record->getStatus()]) ) { $record->delete(); } } // save time history cleanup was ran with no expiration - Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null); + Mage::app()->saveCache(Carbon::now()->getTimestamp(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null); return $this; } @@ -265,8 +267,8 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false) $runConfig = $jobConfig->run; if (!$isAlways) { $scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60; - $now = time(); - $time = strtotime($schedule->getScheduledAt()); + $now = Carbon::now()->getTimestamp(); + $time = Carbon::parse($schedule->getScheduledAt())->getTimestamp(); if ($time > $now) { return; } @@ -341,7 +343,7 @@ protected function _getAlwaysJobSchedule($jobCode) /** @var Mage_Cron_Model_Schedule $schedule */ $schedule = Mage::getModel('cron/schedule')->load($jobCode, 'job_code'); if ($schedule->getId() === null) { - $ts = date('Y-m-d H:i:00'); + $ts = Carbon::now()->format('Y-m-d H:i:00'); $schedule->setJobCode($jobCode) ->setCreatedAt($ts) ->setScheduledAt($ts); diff --git a/app/code/core/Mage/Cron/Model/Schedule.php b/app/code/core/Mage/Cron/Model/Schedule.php index 9e6296f3b4f..52b64adaad4 100644 --- a/app/code/core/Mage/Cron/Model/Schedule.php +++ b/app/code/core/Mage/Cron/Model/Schedule.php @@ -7,6 +7,8 @@ * @package Mage_Cron */ +use Carbon\Carbon; + /** * Crontab schedule model * @@ -83,7 +85,7 @@ public function trySchedule($time) return false; } if (!is_numeric($time)) { - $time = strtotime($time); + $time = Carbon::parse($time)->getTimestamp(); } if ($time === false) { @@ -100,7 +102,7 @@ public function trySchedule($time) if ($match) { $this->setCreatedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT)); - $this->setScheduledAt(date('Y-m-d H:i:00', (int) $time)); + $this->setScheduledAt(Carbon::createFromTimestamp((int) $time)->format('Y-m-d H:i:00')); } return $match; } diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index d7d0c02f351..80d021bc3c3 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -7,6 +7,8 @@ * @package Mage_Customer */ +use Carbon\Carbon; + /** * Customer model * @@ -1435,7 +1437,7 @@ public function getCreatedAtTimestamp() { $date = $this->getCreatedAt(); if ($date) { - return Varien_Date::toTimestamp($date); + return Carbon::now()->setTimeFromTimeString($date)->getTimestamp(); } return null; } @@ -1625,18 +1627,15 @@ public function isResetPasswordLinkTokenExpired() return true; } - $tokenExpirationPeriod = Mage::helper('customer')->getResetPasswordLinkExpirationPeriod(); + $currentTimestamp = Carbon::now(); + $tokenTimestamp = Carbon::now()->setTimeFromTimeString($resetPasswordLinkTokenCreatedAt); - $currentDate = Varien_Date::now(); - $currentTimestamp = Varien_Date::toTimestamp($currentDate); - $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt); - if ($tokenTimestamp > $currentTimestamp) { + if ($currentTimestamp->lessThan($tokenTimestamp)) { return true; } - $hoursDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60)); - - return $hoursDifference >= $tokenExpirationPeriod; + $tokenExpirationPeriod = Mage::helper('customer')->getResetPasswordLinkExpirationPeriod(); + return Carbon::now()->diffInDays($tokenTimestamp) >= $tokenExpirationPeriod; } /** diff --git a/app/code/core/Mage/Customer/Model/Resource/Customer.php b/app/code/core/Mage/Customer/Model/Resource/Customer.php index ce84309f4dd..40270065ab2 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Customer.php +++ b/app/code/core/Mage/Customer/Model/Resource/Customer.php @@ -7,6 +7,8 @@ * @package Mage_Customer */ +use Carbon\Carbon; + /** * Customer entity resource model * @@ -218,7 +220,7 @@ public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $tes */ public function changePassword(Mage_Customer_Model_Customer $customer, $newPassword) { - $customer->setPassword($newPassword)->setPasswordCreatedAt(time()); + $customer->setPassword($newPassword)->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $this->saveAttribute($customer, 'password_hash'); $this->saveAttribute($customer, 'password_created_at'); return $this; @@ -308,7 +310,7 @@ public function changeResetPasswordLinkToken(Mage_Customer_Model_Customer $custo { if (is_string($newResetPasswordLinkToken) && !empty($newResetPasswordLinkToken)) { $customer->setRpToken($newResetPasswordLinkToken); - $currentDate = Varien_Date::now(); + $currentDate = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $customer->setRpTokenCreatedAt($currentDate); $this->saveAttribute($customer, 'rp_token'); $this->saveAttribute($customer, 'rp_token_created_at'); @@ -363,7 +365,7 @@ public function getPasswordTimestamp($customerId) $value = $this->_getReadAdapter()->fetchOne($select); if ($value && !is_numeric($value)) { // Convert created_at string to unix timestamp - $value = Varien_Date::toTimestamp($value); + $value = Carbon::now()->setTimeFromTimeString($value)->getTimestamp(); } return $value; } diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index afdf9172bdb..c8656293f3c 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -7,6 +7,7 @@ * @package Mage_Customer */ +use Carbon\Carbon; use Mage_Customer_Helper_Data as Helper; /** @@ -287,7 +288,7 @@ public function createPostAction() if (empty($errors)) { $customer->cleanPasswordsValidationData(); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->save(); $this->_dispatchRegisterSuccess($customer); $this->_successProcessRegistration($customer); @@ -865,7 +866,7 @@ public function resetPasswordPostAction() $customer->setRpToken(null); $customer->setRpTokenCreatedAt(null); $customer->cleanPasswordsValidationData(); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->setRpCustomerId(null); $customer->setConfirmation(null); // Set email is confirmed. $customer->save(); @@ -1033,7 +1034,7 @@ public function editPostAction() try { $customer->cleanPasswordsValidationData(); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); // Reset all password reset tokens if all data was sufficient and correct on email change if ($customer->getIsChangeEmail()) { diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php index bf0b558ef0f..3d806f5ef24 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php @@ -64,7 +64,7 @@ public function loadFile() $uploader->save($path); if ($uploadFile = $uploader->getUploadedFileName()) { $session = Mage::getModel('dataflow/session'); - $session->setCreatedDate(date(Varien_Date::DATETIME_PHP_FORMAT)); + $session->setCreatedDate(date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT)); $session->setDirection('import'); $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); $session->save(); diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php b/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php index 1c26fa338fd..854ca71eb4e 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php @@ -7,6 +7,8 @@ * @package Mage_Dataflow */ +use Carbon\Carbon; + /** * @package Mage_Dataflow */ @@ -54,7 +56,7 @@ protected function _getProgressBarHtml($sessionId, $totalRows) '; + . $args['row']['session_id'] . '", "' . $args['idx'] . '", "' . Carbon::now()->getTimestamp() . '", "' . $memory . '");'; echo '
  • ' . $memory . '
  • '; return []; diff --git a/app/code/core/Mage/Dataflow/Model/Profile.php b/app/code/core/Mage/Dataflow/Model/Profile.php index 1ce96d44391..538952f99f1 100644 --- a/app/code/core/Mage/Dataflow/Model/Profile.php +++ b/app/code/core/Mage/Dataflow/Model/Profile.php @@ -7,6 +7,8 @@ * @package Mage_Dataflow */ +use Carbon\Carbon; + /** * Convert profile * @@ -226,7 +228,7 @@ protected function _afterSave() ); } if ($uploadFile) { - $newFilename = 'import-' . date('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile; + $newFilename = 'import-' . Carbon::now()->format('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile; rename($path . $uploadFile, $path . $newFilename); $newUploadedFilenames[] = $newFilename; } diff --git a/app/code/core/Mage/Dataflow/Model/Resource/Profile.php b/app/code/core/Mage/Dataflow/Model/Resource/Profile.php index 5673f8fcae8..b938e04357a 100644 --- a/app/code/core/Mage/Dataflow/Model/Resource/Profile.php +++ b/app/code/core/Mage/Dataflow/Model/Resource/Profile.php @@ -7,6 +7,8 @@ * @package Mage_Dataflow */ +use Carbon\Carbon; + /** * Convert profile resource model * @@ -27,9 +29,9 @@ protected function _construct() protected function _beforeSave(Mage_Core_Model_Abstract $object) { if (!$object->getCreatedAt()) { - $object->setCreatedAt($this->formatDate(time())); + $object->setCreatedAt($this->formatDate(Carbon::now()->getTimestamp())); } - $object->setUpdatedAt($this->formatDate(time())); + $object->setUpdatedAt($this->formatDate(Carbon::now()->getTimestamp())); return parent::_beforeSave($object); } diff --git a/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php b/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php index 18d7f2b2a9b..2cf4f4f8722 100644 --- a/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php +++ b/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php @@ -7,6 +7,8 @@ * @package Mage_Dataflow */ +use Carbon\Carbon; + /** * Convert history resource model * @@ -27,7 +29,7 @@ protected function _construct() protected function _beforeSave(Mage_Core_Model_Abstract $object) { if (!$object->getPerformedAt()) { - $object->setPerformedAt($this->formatDate(time())); + $object->setPerformedAt($this->formatDate(Carbon::now()->getTimestamp())); } parent::_beforeSave($object); return $this; diff --git a/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php b/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php index 765d8f3e060..620ed92bedc 100644 --- a/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php +++ b/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php @@ -34,7 +34,7 @@ public function load() $uploader->save($path); if ($uploadFile = $uploader->getUploadedFileName()) { $session = Mage::getModel('dataflow/session'); - $session->setCreatedDate(date(Varien_Date::DATETIME_PHP_FORMAT)); + $session->setCreatedDate(date(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT)); $session->setDirection('import'); $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); $session->save(); diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php index f923eb03f17..1e3f3a001c7 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php @@ -413,7 +413,7 @@ protected function _validateInputRule($value) } break; case 'date': - $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT); + $validator = new Zend_Validate_Date(Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); $validator->setMessage( Mage::helper('eav')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID, diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php index 591d0671917..fd5c4da758e 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php @@ -7,6 +7,8 @@ * @package Mage_Eav */ +use Carbon\Carbon; + /** * EAV Entity Attribute Date Data Model * @@ -56,17 +58,19 @@ public function validateValue($value) $errors = array_merge($errors, $result); } - //range validation + // Default date format + $format = 'd/m/Y'; + // Range validation $validateRules = $attribute->getValidateRules(); - if ((!empty($validateRules['date_range_min']) && (strtotime($value) < $validateRules['date_range_min'])) - || (!empty($validateRules['date_range_max']) && (strtotime($value) > $validateRules['date_range_max'])) + if ((!empty($validateRules['date_range_min']) && (Carbon::parse($value)->getTimestamp() < $validateRules['date_range_min'])) + || (!empty($validateRules['date_range_max']) && (Carbon::parse($value)->getTimestamp() > $validateRules['date_range_max'])) ) { if (!empty($validateRules['date_range_min']) && !empty($validateRules['date_range_max'])) { - $errors[] = Mage::helper('customer')->__('Please enter a valid date between %s and %s at %s.', date('d/m/Y', $validateRules['date_range_min']), date('d/m/Y', $validateRules['date_range_max']), $label); + $errors[] = Mage::helper('customer')->__('Please enter a valid date between %s and %s at %s.', Carbon::createFromTimestamp($validateRules['date_range_min'])->format($format), Carbon::createFromTimestamp($validateRules['date_range_max'])->format($format), $label); } elseif (!empty($validateRules['date_range_min'])) { - $errors[] = Mage::helper('customer')->__('Please enter a valid date equal to or greater than %s at %s.', date('d/m/Y', $validateRules['date_range_min']), $label); + $errors[] = Mage::helper('customer')->__('Please enter a valid date equal to or greater than %s at %s.', Carbon::createFromTimestamp($validateRules['date_range_min'])->format($format), $label); } elseif (!empty($validateRules['date_range_max'])) { - $errors[] = Mage::helper('customer')->__('Please enter a valid date less than or equal to %s at %s.', date('d/m/Y', $validateRules['date_range_max']), $label); + $errors[] = Mage::helper('customer')->__('Please enter a valid date less than or equal to %s at %s.', Carbon::createFromTimestamp($validateRules['date_range_max'])->format($format), $label); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Abstract.php index e4fd2f459fd..2a0e8f119be 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Abstract.php @@ -856,8 +856,8 @@ public function checkAttributeUniqueValue(Mage_Eav_Model_Entity_Attribute_Abstra } else { $value = $object->getData($attribute->getAttributeCode()); if ($attribute->getBackend()->getType() === 'datetime') { - $date = new Zend_Date($value, Varien_Date::DATE_INTERNAL_FORMAT); - $value = $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + $date = new Zend_Date($value, Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); + $value = $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } $bind = [ 'entity_type_id' => $this->getTypeId(), diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php index d3128a0de52..ea18677ec75 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -74,6 +74,6 @@ public function formatDate($date) false, ); } - return $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + return $date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php index 151a99308a8..481ae473b9e 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php @@ -7,6 +7,8 @@ * @package Mage_Eav */ +use Carbon\Carbon; + /** * Entity/Attribute/Model - attribute backend default * @@ -41,7 +43,7 @@ public function beforeSave($object) $date = $object->getData($attributeCode); if (is_null($date)) { if ($object->isObjectNew()) { - $object->setData($attributeCode, Varien_Date::now()); + $object->setData($attributeCode, Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } } else { // convert to UTC diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php index 4e2b87c6934..2642c8454a6 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php @@ -7,6 +7,8 @@ * @package Mage_Eav */ +use Carbon\Carbon; + /** * Entity/Attribute/Model - attribute backend default * @@ -22,7 +24,7 @@ class Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated extends Mage_Eav_Mode */ public function beforeSave($object) { - $object->setData($this->getAttribute()->getAttributeCode(), Varien_Date::now()); + $object->setData($this->getAttribute()->getAttributeCode(), Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); return $this; } } diff --git a/app/code/core/Mage/ImportExport/Model/Export.php b/app/code/core/Mage/ImportExport/Model/Export.php index 9a2f5f83743..34c8243427e 100644 --- a/app/code/core/Mage/ImportExport/Model/Export.php +++ b/app/code/core/Mage/ImportExport/Model/Export.php @@ -7,6 +7,8 @@ * @package Mage_ImportExport */ +use Carbon\Carbon; + /** * Export model * @@ -290,6 +292,6 @@ public function getFileFormat() */ public function getFileName() { - return $this->getEntity() . '_' . date('Ymd_His') . '.' . $this->_getWriter()->getFileExtension(); + return $this->getEntity() . '_' . Carbon::now()->format('Ymd_His') . '.' . $this->_getWriter()->getFileExtension(); } } diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php index fb2a8f38028..550efa530cf 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_ImportExport */ +use Carbon\Carbon; + /** * Import entity abstract model * @@ -546,7 +548,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData, $ break; case 'datetime': $val = trim($rowData[$attrCode]); - $valid = strtotime($val) !== false + $valid = Carbon::parse($val)->getTimestamp() !== false || preg_match('/^\d{2}.\d{2}.\d{2,4}(?:\s+\d{1,2}.\d{1,2}(?:.\d{1,2})?)?$/', $val); break; case 'text': diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php index 94737902889..915b60fd304 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php @@ -7,6 +7,8 @@ * @package Mage_ImportExport */ +use Carbon\Carbon; + /** * Import entity customer model * @@ -372,13 +374,13 @@ protected function _saveCustomers() } if (self::SCOPE_DEFAULT == $this->getRowScope($rowData)) { // entity table data - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $entityRow = [ 'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'], 'store_id' => empty($rowData[self::COL_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]], 'created_at' => empty($rowData['created_at']) - ? $now : gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($rowData['created_at'])), + ? $now : gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, Carbon::parse($rowData['created_at'])->getTimestamp()), 'updated_at' => $now, ]; @@ -410,7 +412,7 @@ protected function _saveCustomers() if ($attrParams['type'] === 'select') { $value = $attrParams['options'][strtolower($value)]; } elseif ($attrParams['type'] === 'datetime') { - $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($value)); + $value = gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, Carbon::parse($value)->getTimestamp()); } elseif ($attrParams['type'] === 'multiselect') { $value = (array) $attrParams['options'][strtolower($value)]; $attribute->getBackend()->beforeSave($resource->setData($attrCode, $value)); diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php index 36337f94330..43e24ea973c 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php @@ -7,6 +7,8 @@ * @package Mage_ImportExport */ +use Carbon\Carbon; + /** * Import entity customer address * @@ -183,7 +185,7 @@ protected function _importData() if ($attrParams['type'] === 'select') { $value = $attrParams['options'][strtolower($rowData[$attrAlias])]; } elseif ($attrParams['type'] === 'datetime') { - $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($rowData[$attrAlias])); + $value = gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, Carbon::parse($rowData[$attrAlias])->getTimestamp()); } elseif ($attrParams['type'] === 'multiselect') { $value = $attrParams['options'][strtolower($rowData[$attrAlias])]; $multiSelect[$attrParams['id']][] = $value; @@ -206,7 +208,7 @@ protected function _importData() || $rowScope == Mage_ImportExport_Model_Import_Entity_Customer::SCOPE_ADDRESS ) { // entity table data - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $entityRows[] = [ 'entity_id' => $entityId, 'entity_type_id' => $this->_entityTypeId, diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php index 5014ffd9c36..1a68034267d 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php @@ -7,6 +7,8 @@ * @package Mage_ImportExport */ +use Carbon\Carbon; + /** * Import entity product model * @@ -896,7 +898,7 @@ protected function _saveCustomOptions() 'entity_id' => $productId, 'has_options' => 0, 'required_options' => 0, - 'updated_at' => Varien_Date::now(), + 'updated_at' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), ]; } @@ -1374,7 +1376,7 @@ protected function _saveProducts() if (self::SCOPE_DEFAULT == $rowScope) { $rowSku = $rowData[self::COL_SKU]; - $now = Varien_Date::now(); + $now = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); // 1. Entity phase if (isset($this->_oldSku[$rowSku])) { // existing row @@ -1510,7 +1512,7 @@ protected function _saveProducts() */ protected function _getStrftimeFormat() { - return Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); + return Varien_Date::convertZendToStrftime(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, true, true); } /** @@ -1558,8 +1560,8 @@ protected function _prepareAttributes($rowData, $rowScope, $attributes, $rowSku, $attrTable = $attribute->getBackend()->getTable(); $storeIds = [0]; - if ($attribute->getBackendType() === 'datetime' && strtotime($attrValue)) { - $attrValue = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($attrValue)); + if ($attribute->getBackendType() === 'datetime' && Carbon::parse($attrValue)->getTimestamp()) { + $attrValue = gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, Carbon::parse($attrValue)->getTimestamp()); } elseif ($attribute->getAttributeCode() === 'url_key') { if (empty($attrValue)) { $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $product->getStoreId()); @@ -1946,7 +1948,7 @@ protected function _saveStockItem() if ($stockItem->verifyNotification()) { $stockItem->setLowStockDate(Mage::app()->getLocale() ->date(null, null, null, false) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } $stockItem->setStockStatusChangedAutomatically((int) !$stockItem->verifyStock()); } else { diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php index d4ae9c78269..cc2ae83d393 100644 --- a/app/code/core/Mage/Index/Model/Event.php +++ b/app/code/core/Mage/Index/Model/Event.php @@ -7,6 +7,8 @@ * @package Mage_Index */ +use Carbon\Carbon; + /** * @package Mage_Index * @@ -319,7 +321,7 @@ protected function _beforeSave() $newData = $this->getNewData(false); $this->setNewData(serialize($newData)); if (!$this->hasCreatedAt()) { - $this->setCreatedAt($this->_getResource()->formatDate(time(), true)); + $this->setCreatedAt($this->_getResource()->formatDate(Carbon::now()->getTimestamp())); } return parent::_beforeSave(); } diff --git a/app/code/core/Mage/Index/Model/Lock.php b/app/code/core/Mage/Index/Model/Lock.php index ee23d55338e..2481796a22e 100644 --- a/app/code/core/Mage/Index/Model/Lock.php +++ b/app/code/core/Mage/Index/Model/Lock.php @@ -7,6 +7,8 @@ * @package Mage_Index */ +use Carbon\Carbon; + /** * Lock model * @@ -287,7 +289,7 @@ protected function _getLockFile($lockName) self::$_lockFileResource[$lockName] = null; throw new Exception(sprintf('Unable to open lock file \'%s\': %s', $file, error_get_last())); } - fwrite(self::$_lockFileResource[$lockName], date('r')); + fwrite(self::$_lockFileResource[$lockName], Carbon::now()->format('r')); } return self::$_lockFileResource[$lockName]; } diff --git a/app/code/core/Mage/Index/Model/Observer.php b/app/code/core/Mage/Index/Model/Observer.php index 910101e244a..dbdb260590a 100644 --- a/app/code/core/Mage/Index/Model/Observer.php +++ b/app/code/core/Mage/Index/Model/Observer.php @@ -7,6 +7,8 @@ * @package Mage_Index */ +use Carbon\Carbon; + /** * @package Mage_Index */ @@ -144,7 +146,7 @@ public function cleanOutdatedEvents() ->getProcessesCollection() ->addFieldToFilter('mode', Mage_Index_Model_Process::MODE_MANUAL); - $now = new DateTime(); + $now = Carbon::now(); /** @noinspection PhpUnhandledExceptionInspection */ $dateInterval = new DateInterval('PT' . self::OLD_INDEX_EVENT_THRESHOLD_SECONDS . 'S'); $oldEventsThreshold = $now diff --git a/app/code/core/Mage/Index/Model/Resource/Process.php b/app/code/core/Mage/Index/Model/Resource/Process.php index 12523bd068c..281d6e9e7c1 100644 --- a/app/code/core/Mage/Index/Model/Resource/Process.php +++ b/app/code/core/Mage/Index/Model/Resource/Process.php @@ -7,6 +7,8 @@ * @package Mage_Index */ +use Carbon\Carbon; + /** * Index Process Resource Model * @@ -47,7 +49,7 @@ public function endProcess(Mage_Index_Model_Process $process) { $data = [ 'status' => Mage_Index_Model_Process::STATUS_PENDING, - 'ended_at' => $this->formatDate(time()), + 'ended_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; $this->_updateProcessData($process->getId(), $data); return $this; @@ -62,7 +64,7 @@ public function startProcess(Mage_Index_Model_Process $process) { $data = [ 'status' => Mage_Index_Model_Process::STATUS_RUNNING, - 'started_at' => $this->formatDate(time()), + 'started_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; $this->_updateProcessData($process->getId(), $data); return $this; @@ -77,7 +79,7 @@ public function failProcess(Mage_Index_Model_Process $process) { $data = [ 'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX, - 'ended_at' => $this->formatDate(time()), + 'ended_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; $this->_updateProcessData($process->getId(), $data); return $this; @@ -119,7 +121,7 @@ protected function _updateProcessData($processId, $data) */ public function updateProcessStartDate(Mage_Index_Model_Process $process) { - $this->_updateProcessData($process->getId(), ['started_at' => $this->formatDate(time())]); + $this->_updateProcessData($process->getId(), ['started_at' => $this->formatDate(Carbon::now()->getTimestamp())]); return $this; } @@ -130,7 +132,7 @@ public function updateProcessStartDate(Mage_Index_Model_Process $process) */ public function updateProcessEndDate(Mage_Index_Model_Process $process) { - $this->_updateProcessData($process->getId(), ['ended_at' => $this->formatDate(time())]); + $this->_updateProcessData($process->getId(), ['ended_at' => $this->formatDate(Carbon::now()->getTimestamp())]); return $this; } diff --git a/app/code/core/Mage/Install/Model/Installer/Config.php b/app/code/core/Mage/Install/Model/Installer/Config.php index 6169cd665a5..1417c29e66a 100644 --- a/app/code/core/Mage/Install/Model/Installer/Config.php +++ b/app/code/core/Mage/Install/Model/Installer/Config.php @@ -7,6 +7,8 @@ * @package Mage_Install */ +use Carbon\Carbon; + /** * Config installer * @@ -161,9 +163,9 @@ protected function _checkUrl($url, $secure = false) public function replaceTmpInstallDate($date = null) { - $stamp = strtotime((string) $date); + $stamp = Carbon::parse((string) $date)->getTimestamp(); $localXml = file_get_contents($this->_localConfigFile); - $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, date('r', $stamp ? $stamp : time()), $localXml); + $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, Carbon::createFromTimestamp($stamp ? $stamp : Carbon::now()->getTimestamp())->format('r'), $localXml); file_put_contents($this->_localConfigFile, $localXml); return $this; diff --git a/app/code/core/Mage/Log/Model/Aggregation.php b/app/code/core/Mage/Log/Model/Aggregation.php index 765ccdf44a0..b2eb765512e 100644 --- a/app/code/core/Mage/Log/Model/Aggregation.php +++ b/app/code/core/Mage/Log/Model/Aggregation.php @@ -7,6 +7,8 @@ * @package Mage_Log */ +use Carbon\Carbon; + /** * Log Aggregation Model * @@ -53,7 +55,7 @@ private function _process($store) { $lastDateRecord = null; $start = $this->_lastRecord; - $end = time(); + $end = Carbon::now()->getTimestamp(); $date = $start; while ($date < $end) { @@ -127,7 +129,7 @@ public function getLastRecordDate() { $result = $this->_getResource()->getLastRecordDate(); if (!$result) { - $result = $this->_date(strtotime('now - 2 months')); + $result = $this->_date(Carbon::parse('now - 2 months')->getTimestamp()); } return $result; @@ -142,7 +144,7 @@ private function _date($in, $offset = null) { $out = $in; if (is_numeric($in)) { - $out = date(Varien_Date::DATETIME_PHP_FORMAT, $in); + $out = Carbon::createFromTimestamp($in)->format(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); } return $out; } @@ -150,13 +152,14 @@ private function _date($in, $offset = null) /** * @param string|int $in * @param null $offset deprecated - * @return false|int + * @return int + * @SuppressWarnings("PHPMD.UnusedFormalParameter") */ private function _timestamp($in, $offset = null) { $out = $in; if (!is_numeric($in)) { - $out = strtotime($in); + $out = Carbon::parse($in)->getTimestamp(); } return $out; } @@ -167,6 +170,6 @@ private function _timestamp($in, $offset = null) */ private function _round($in) { - return date('Y-m-d H:00:00', $this->_timestamp($in)); + return Carbon::createFromTimestamp($this->_timestamp($in))->format('Y-m-d H:00:00'); } } diff --git a/app/code/core/Mage/Log/Model/Customer.php b/app/code/core/Mage/Log/Model/Customer.php index 328e03473f0..ccd84b0d59e 100644 --- a/app/code/core/Mage/Log/Model/Customer.php +++ b/app/code/core/Mage/Log/Model/Customer.php @@ -7,6 +7,8 @@ * @package Mage_Log */ +use Carbon\Carbon; + /** * Customer log model * @@ -61,7 +63,7 @@ public function getLoginAtTimestamp() { $loginAt = $this->getLoginAt(); if ($loginAt) { - return Varien_Date::toTimestamp($loginAt); + return Carbon::now()->setTimeFromTimeString($loginAt)->getTimestamp(); } return null; diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php index 226421cabb2..d453dadf997 100644 --- a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php +++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php @@ -7,6 +7,8 @@ * @package Mage_Log */ +use Carbon\Carbon; + /** * Log Prepare Online visitors resource * @@ -26,7 +28,7 @@ protected function _construct() */ public function prepare(Mage_Log_Model_Visitor_Online $object) { - if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) { + if (($object->getUpdateFrequency() + $object->getPrepareAt()) > Carbon::now()->getTimestamp()) { return $this; } diff --git a/app/code/core/Mage/Log/Model/Visitor.php b/app/code/core/Mage/Log/Model/Visitor.php index 4b9e448af81..21696dd5c5a 100644 --- a/app/code/core/Mage/Log/Model/Visitor.php +++ b/app/code/core/Mage/Log/Model/Visitor.php @@ -7,6 +7,8 @@ * @package Mage_Log */ +use Carbon\Carbon; + /** * @package Mage_Log * @@ -174,7 +176,7 @@ public function getUrl() public function getFirstVisitAt() { if (!$this->hasData('first_visit_at')) { - $this->setData('first_visit_at', Varien_Date::now()); + $this->setData('first_visit_at', Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } return $this->getData('first_visit_at'); } @@ -185,7 +187,7 @@ public function getFirstVisitAt() public function getLastVisitAt() { if (!$this->hasData('last_visit_at')) { - $this->setData('last_visit_at', Varien_Date::now()); + $this->setData('last_visit_at', Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } return $this->getData('last_visit_at'); } @@ -209,7 +211,7 @@ public function initByRequest($observer) $visitorId = $this->getId(); if (!$visitorId) { $this->initServerData(); - $this->setFirstVisitAt(Varien_Date::now()); + $this->setFirstVisitAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); $this->setIsNewVisitor(true); $this->save(); } @@ -250,7 +252,7 @@ public function saveByRequest($observer) try { $this->initServerData(); - $this->setLastVisitAt(Varien_Date::now()); + $this->setLastVisitAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); $this->save(); $this->_session->setVisitorData($this->getData()); } catch (Exception $e) { diff --git a/app/code/core/Mage/Log/Model/Visitor/Online.php b/app/code/core/Mage/Log/Model/Visitor/Online.php index 63456817f76..a1ac8d08f49 100644 --- a/app/code/core/Mage/Log/Model/Visitor/Online.php +++ b/app/code/core/Mage/Log/Model/Visitor/Online.php @@ -7,6 +7,8 @@ * @package Mage_Log */ +use Carbon\Carbon; + /** * Prepare Log Online Visitors Model * @@ -68,7 +70,7 @@ public function getPrepareAt() public function setPrepareAt($time = null) { if (is_null($time)) { - $time = time(); + $time = Carbon::now()->getTimestamp(); } Mage::app()->saveCache($time, 'log_visitor_online_prepare_at'); return $this; diff --git a/app/code/core/Mage/Oauth/Model/Consumer.php b/app/code/core/Mage/Oauth/Model/Consumer.php index 70505695d94..26846d3a540 100644 --- a/app/code/core/Mage/Oauth/Model/Consumer.php +++ b/app/code/core/Mage/Oauth/Model/Consumer.php @@ -7,6 +7,8 @@ * @package Mage_Oauth */ +use Carbon\Carbon; + /** * Application model * @@ -56,7 +58,7 @@ protected function _construct() protected function _beforeSave() { if (!$this->getId()) { - $this->setUpdatedAt(time()); + $this->setUpdatedAt(Carbon::now()->getTimestamp()); } $this->setCallbackUrl(trim($this->getCallbackUrl())); $this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl())); diff --git a/app/code/core/Mage/Oauth/Model/Resource/Nonce.php b/app/code/core/Mage/Oauth/Model/Resource/Nonce.php index 751261847d7..392f3107c06 100644 --- a/app/code/core/Mage/Oauth/Model/Resource/Nonce.php +++ b/app/code/core/Mage/Oauth/Model/Resource/Nonce.php @@ -7,6 +7,8 @@ * @package Mage_Oauth */ +use Carbon\Carbon; + /** * oAuth nonce resource model * @@ -32,7 +34,7 @@ public function deleteOldEntries($minutes) return $adapter->delete( $this->getMainTable(), - $adapter->quoteInto('timestamp <= ?', time() - $minutes * 60, Zend_Db::INT_TYPE), + $adapter->quoteInto('timestamp <= ?', Carbon::now()->subMinutes($minutes)->getTimestamp(), Zend_Db::INT_TYPE), ); } else { return 0; diff --git a/app/code/core/Mage/Oauth/Model/Resource/Token.php b/app/code/core/Mage/Oauth/Model/Resource/Token.php index 887d23ef5d1..70d9f86c8e3 100644 --- a/app/code/core/Mage/Oauth/Model/Resource/Token.php +++ b/app/code/core/Mage/Oauth/Model/Resource/Token.php @@ -7,6 +7,8 @@ * @package Mage_Oauth */ +use Carbon\Carbon; + /** * OAuth token resource model * @@ -66,7 +68,7 @@ public function deleteOldEntries($minutes) $this->getMainTable(), $adapter->quoteInto( 'type = "' . Mage_Oauth_Model_Token::TYPE_REQUEST . '" AND created_at <= ?', - Varien_Date::formatDate(time() - $minutes * 60), + Varien_Date::formatDate(Carbon::now()->subMinutes($minutes)->getTimestamp()), ), ); } else { diff --git a/app/code/core/Mage/Oauth/Model/Server.php b/app/code/core/Mage/Oauth/Model/Server.php index f098f67c0af..cd11a6dbe2f 100644 --- a/app/code/core/Mage/Oauth/Model/Server.php +++ b/app/code/core/Mage/Oauth/Model/Server.php @@ -7,6 +7,8 @@ * @package Mage_Oauth */ +use Carbon\Carbon; + /** * oAuth Server * @@ -442,12 +444,14 @@ protected function _validateCallbackUrlParam() * * @param string $nonce Nonce string * @param string|int $timestamp UNIX Timestamp + * @throws Mage_Core_Exception + * @throws Throwable */ protected function _validateNonce($nonce, $timestamp) { $timestamp = (int) $timestamp; - if ($timestamp <= 0 || $timestamp > (time() + self::TIME_DEVIATION)) { + if ($timestamp <= 0 || $timestamp > Carbon::now()->addSeconds(self::TIME_DEVIATION)->getTimestamp()) { $this->_throwException('', self::ERR_TIMESTAMP_REFUSED); } /** @var Mage_Oauth_Model_Nonce $nonceObj */ diff --git a/app/code/core/Mage/Oauth/Model/Token.php b/app/code/core/Mage/Oauth/Model/Token.php index 090130322d0..caeab25f912 100644 --- a/app/code/core/Mage/Oauth/Model/Token.php +++ b/app/code/core/Mage/Oauth/Model/Token.php @@ -7,6 +7,8 @@ * @package Mage_Oauth */ +use Carbon\Carbon; + /** * oAuth token model * @@ -204,7 +206,7 @@ protected function _beforeSave() $this->validate(); if ($this->isObjectNew() && $this->getCreatedAt() === null) { - $this->setCreatedAt(Varien_Date::now()); + $this->setCreatedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } parent::_beforeSave(); return $this; diff --git a/app/code/core/Mage/Payment/Block/Form/Cc.php b/app/code/core/Mage/Payment/Block/Form/Cc.php index 06e170238ac..686f53a08bd 100644 --- a/app/code/core/Mage/Payment/Block/Form/Cc.php +++ b/app/code/core/Mage/Payment/Block/Form/Cc.php @@ -7,6 +7,8 @@ * @package Mage_Payment */ +use Carbon\Carbon; + /** * @package Mage_Payment */ @@ -125,7 +127,7 @@ public function hasSsCardType() public function getSsStartYears() { $years = []; - $first = date('Y'); + $first = Carbon::now()->format('Y'); for ($index = 5; $index >= 0; $index--) { $year = $first - $index; diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 1f9bfebf7e7..b920a8296ff 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -7,6 +7,8 @@ * @package Mage_Payment */ +use Carbon\Carbon; + /** * Payment configuration model * @@ -127,7 +129,7 @@ public function getMonths() public function getYears() { $years = []; - $first = date('Y'); + $first = (int) Carbon::now()->format('Y'); for ($index = 0; $index <= 10; $index++) { $year = $first + $index; diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile.php b/app/code/core/Mage/Payment/Model/Recurring/Profile.php index 32f764c88a3..a42cf4c82f1 100644 --- a/app/code/core/Mage/Payment/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Payment/Model/Recurring/Profile.php @@ -7,6 +7,8 @@ * @package Mage_Payment */ +use Carbon\Carbon; + /** * Recurring payment profile * Extends from Mage_Core_Abstract for a reason: to make descendants have its own resource @@ -102,7 +104,7 @@ public function isValid() // start date, order ref ID, schedule description if (!$this->getStartDatetime()) { $this->_errors['start_datetime'][] = Mage::helper('payment')->__('Start date is undefined.'); - } elseif (!Zend_Date::isDate($this->getStartDatetime(), Varien_Date::DATETIME_INTERNAL_FORMAT)) { + } elseif (!Zend_Date::isDate($this->getStartDatetime(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)) { $this->_errors['start_datetime'][] = Mage::helper('payment')->__('Start date has invalid format.'); } if (!$this->getScheduleDescription()) { @@ -222,7 +224,7 @@ public function importBuyRequest(Varien_Object $buyRequest) Mage::throwException(Mage::helper('payment')->__('Recurring profile start date has invalid format.')); } $utcTime = $this->_locale->utcDate($this->_store, $startDate, true, $dateFormat) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $this->setStartDatetime($utcTime)->setImportedStartDatetime($startDate); } return $this->_filterValues(); @@ -251,7 +253,7 @@ public function importProduct(Mage_Catalog_Model_Product $product) $options = unserialize($options->getValue(), ['allowed_classes' => false]); if (is_array($options)) { if (isset($options['start_datetime'])) { - $startDatetime = new Zend_Date($options['start_datetime'], Varien_Date::DATETIME_INTERNAL_FORMAT); + $startDatetime = new Zend_Date($options['start_datetime'], Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $this->setNearestStartDatetime($startDatetime); } } @@ -295,10 +297,10 @@ public function setNearestStartDatetime(?Zend_Date $minAllowed = null) { // TODO: implement proper logic with invoking payment method instance $date = $minAllowed; - if (!$date || $date->getTimestamp() < time()) { - $date = new Zend_Date(time()); + if (!$date || $date->getTimestamp() < Carbon::now()->getTimestamp()) { + $date = new Zend_Date(Carbon::now()->getTimestamp()); } - $this->setStartDatetime($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $this->setStartDatetime($date->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); return $this; } @@ -314,7 +316,7 @@ public function exportStartDatetime($asString = true) if (!$datetime || !$this->_locale || !$this->_store) { return; } - $date = $this->_locale->storeDate($this->_store, strtotime($datetime), true); + $date = $this->_locale->storeDate($this->_store, Carbon::parse($datetime)->getTimestamp(), true); if ($asString) { return $date->toString($this->_locale->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); } @@ -545,7 +547,7 @@ protected function _filterValues() // automatically determine start date, if not set if ($this->getStartDatetime()) { - $date = new Zend_Date($this->getStartDatetime(), Varien_Date::DATETIME_INTERNAL_FORMAT); + $date = new Zend_Date($this->getStartDatetime(), Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $this->setNearestStartDatetime($date); } else { $this->setNearestStartDatetime(); diff --git a/app/code/core/Mage/Paypal/Model/Cert.php b/app/code/core/Mage/Paypal/Model/Cert.php index 15225ae87c6..2000bfed16c 100644 --- a/app/code/core/Mage/Paypal/Model/Cert.php +++ b/app/code/core/Mage/Paypal/Model/Cert.php @@ -7,6 +7,8 @@ * @package Mage_Paypal */ +use Carbon\Carbon; + /** * PayPal specific model for certificate based authentication * @@ -49,7 +51,7 @@ public function getCertPath() Mage::throwException(Mage::helper('paypal')->__('PayPal certificate does not exist.')); } - $certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), strtotime($this->getUpdatedAt())); + $certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), Carbon::parse($this->getUpdatedAt())->getTimestamp()); $certFile = $this->_getBaseDir() . DS . $certFileName; if (!file_exists($certFile)) { diff --git a/app/code/core/Mage/Paypal/Model/Express.php b/app/code/core/Mage/Paypal/Model/Express.php index ea3a27ec7a1..b4d4f332b23 100644 --- a/app/code/core/Mage/Paypal/Model/Express.php +++ b/app/code/core/Mage/Paypal/Model/Express.php @@ -7,6 +7,8 @@ * @package Mage_Paypal */ +use Carbon\Carbon; + /** * @package Mage_Paypal */ @@ -635,7 +637,7 @@ public function canCapture() $dateCompass = new DateTime($orderTransaction->getCreatedAt()); $dateCompass->modify('+' . $orderValidPeriod . ' days'); - $currentDate = new DateTime(); + $currentDate = Carbon::now(); if ($currentDate > $dateCompass || $orderValidPeriod == 0) { return false; diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php index b70d94eb6b1..9b131ced83c 100644 --- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php +++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php @@ -7,6 +7,8 @@ * @package Mage_Paypal */ +use Carbon\Carbon; + /** * Wrapper that performs Paypal Express and Checkout communication * Use current Paypal Express method instance @@ -971,7 +973,7 @@ protected function _prepareNewCustomerQuote() $customer->setSuffix($quote->getCustomerSuffix()); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); $customer->setPasswordHash($customer->hashPassword($customer->getPassword())); - $customer->setPasswordCreatedAt(time()); + $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp()); $customer->save(); $quote->setCustomer($customer); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Paypal/Model/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Report/Settlement.php index 241e6563299..0fb2cf09c23 100644 --- a/app/code/core/Mage/Paypal/Model/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Report/Settlement.php @@ -208,7 +208,7 @@ public function fetchAndSave($config) // Set last modified date, this value will be overwritten during parsing if (isset($attributes['mtime'])) { $lastModified = new Zend_Date($attributes['mtime']); - $this->setReportLastModified($lastModified->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $this->setReportLastModified($lastModified->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } $this->setReportDate($this->_fileNameToDate($filename)) @@ -254,7 +254,7 @@ public function parseCsv($localCsv, $format = 'new') switch ($lineType) { case 'RH': // Report header. $lastModified = new Zend_Date($line[1]); - $this->setReportLastModified($lastModified->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $this->setReportLastModified($lastModified->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); //$this->setAccountId($columns[2]); -- probably we'll just take that from the section header... break; case 'FH': // File header. diff --git a/app/code/core/Mage/Persistent/Model/Session.php b/app/code/core/Mage/Persistent/Model/Session.php index 7e8338cefa3..786695482a0 100644 --- a/app/code/core/Mage/Persistent/Model/Session.php +++ b/app/code/core/Mage/Persistent/Model/Session.php @@ -7,6 +7,8 @@ * @package Mage_Persistent */ +use Carbon\Carbon; + /** * Persistent Session Model * @@ -80,7 +82,7 @@ public function getExpiredBefore($store = null) { return gmdate( Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, - time() - Mage::helper('persistent')->getLifeTime($store), + Carbon::now()->subSeconds(Mage::helper('persistent')->getLifeTime($store))->getTimestamp(), ); } @@ -208,7 +210,7 @@ public function deleteExpired($websiteId = null) if ($lifetime) { $this->getResource()->deleteExpired( $websiteId, - gmdate(Varien_Date::DATETIME_PHP_FORMAT, time() - $lifetime), + gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT, Carbon::now()->subSeconds((int) $lifetime->__toString())->getTimestamp()), ); } @@ -233,7 +235,7 @@ protected function _afterDeleteCommit() */ public function save() { - $this->setUpdatedAt(gmdate(Varien_Date::DATETIME_PHP_FORMAT)); + $this->setUpdatedAt(gmdate(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT)); return parent::save(); } } diff --git a/app/code/core/Mage/Reports/Helper/Data.php b/app/code/core/Mage/Reports/Helper/Data.php index 0663af19ce4..1520ed9bbaf 100644 --- a/app/code/core/Mage/Reports/Helper/Data.php +++ b/app/code/core/Mage/Reports/Helper/Data.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * @package Mage_Reports */ @@ -43,71 +45,53 @@ public function isReportsEnabled() /** * Retrieve array of intervals * - * @param string $from - * @param string $to + * @param string $dateFrom + * @param string $dateTo * @param self::REPORT_PERIOD_TYPE_* $period * @return array - * @throws Zend_Date_Exception */ - public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY) + public function getIntervals($dateFrom, $dateTo, $period = self::REPORT_PERIOD_TYPE_DAY) { $intervals = []; - $dateStart = null; - - if (!$from && !$to) { + if (!$dateFrom && !$dateTo) { return $intervals; } - $start = new Zend_Date($from, Varien_Date::DATE_INTERNAL_FORMAT); - - if ($period == self::REPORT_PERIOD_TYPE_DAY) { - $dateStart = $start; - } - - if ($period == self::REPORT_PERIOD_TYPE_MONTH) { - $dateStart = new Zend_Date(date('Y-m', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT); + $dateStart = Carbon::now()->setTimeFromTimeString($dateFrom . ' 00:00:00'); + $endDate = Carbon::now()->setTimeFromTimeString($dateTo . ' 00:00:00'); + + switch ($period) { + case self::REPORT_PERIOD_TYPE_DAY: + $format = 'YYYY-MM-DD'; + $modifier = 'addDay'; + break; + case self::REPORT_PERIOD_TYPE_MONTH: + $format = 'YYYY-MM'; + $modifier = 'addMonth'; + break; + case self::REPORT_PERIOD_TYPE_YEAR: + default: + $format = 'YYYY'; + $modifier = 'addYear'; + break; } - if ($period == self::REPORT_PERIOD_TYPE_YEAR) { - $dateStart = new Zend_Date(date('Y', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT); + for ($date = $dateStart->copy(); $date->lte($endDate); $date->$modifier()) { + $intervals[] = $date->isoFormat($format); } - if (!$period || !$dateStart) { - return $intervals; - } - - $dateEnd = new Zend_Date($to, Varien_Date::DATE_INTERNAL_FORMAT); - - while ($dateStart->compare($dateEnd) <= 0) { - $time = ''; - switch ($period) { - case self::REPORT_PERIOD_TYPE_DAY: - $time = $dateStart->toString('yyyy-MM-dd'); - $dateStart->addDay(1); - break; - case self::REPORT_PERIOD_TYPE_MONTH: - $time = $dateStart->toString('yyyy-MM'); - $dateStart->addMonth(1); - break; - case self::REPORT_PERIOD_TYPE_YEAR: - $time = $dateStart->toString('yyyy'); - $dateStart->addYear(1); - break; - } - $intervals[] = $time; - } return $intervals; } /** * @param Varien_Data_Collection $collection - * @param string $from - * @param string $to - * @param string $periodType + * @param string $dateFrom + * @param string $dateTo + * @param self::REPORT_PERIOD_TYPE_* $periodType */ - public function prepareIntervalsCollection($collection, $from, $to, $periodType = self::REPORT_PERIOD_TYPE_DAY) + public function prepareIntervalsCollection($collection, $dateFrom, $dateTo, $periodType = self::REPORT_PERIOD_TYPE_DAY) { - $intervals = $this->getIntervals($from, $to, $periodType); + $intervals = $this->getIntervals($dateFrom, $dateTo, $periodType); foreach ($intervals as $interval) { $item = Mage::getModel('adminhtml/report_item'); diff --git a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php index 9b8e4be3c0e..0415d7c4cf1 100644 --- a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * Reports Product Index Abstract Model * @@ -50,7 +52,7 @@ public function save() $this->setStoreId($this->getStoreId()); } if (!$this->hasAddedAt()) { - $this->setAddedAt(Varien_Date::now()); + $this->setAddedAt(Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT)); } // Thanks to new performance tweaks it is possible to switch off visitor logging diff --git a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php index 61024cbe7a6..66b201664d4 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * Reports summary collection * @@ -33,31 +35,31 @@ public function setSelectPeriod($periodType, $customStart = null, $customEnd = n { switch ($periodType) { case '24h': - $customStart = Varien_Date::toTimestamp(true) - 86400; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subDay()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; case '7d': - $customStart = Varien_Date::toTimestamp(true) - 604800; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subWeek()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; case '30d': - $customStart = Varien_Date::toTimestamp(true) - 2592000; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subMonth()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; case '1y': - $customStart = Varien_Date::toTimestamp(true) - 31536000; - $customEnd = Varien_Date::toTimestamp(true); + $customStart = Carbon::now()->subYear()->getTimestamp(); + $customEnd = Carbon::now()->getTimestamp(); break; default: if (is_string($customStart)) { - $customStart = strtotime($customStart); + $customStart = Carbon::parse($customStart)->getTimestamp(); } if (is_string($customEnd)) { - $customEnd = strtotime($customEnd); + $customEnd = Carbon::parse($customEnd)->getTimestamp(); } break; } diff --git a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php index 918d31672f0..293836a72d9 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php @@ -809,8 +809,8 @@ public function addCreateAtPeriodFilter($period) } $this->addFieldToFilter($fieldToFilter, [ - 'from' => $from->toString(Varien_Date::DATETIME_INTERNAL_FORMAT), - 'to' => $to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT), + 'from' => $from->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), + 'to' => $to->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT), ]); return $this; diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php index 684765324a8..9c98fbe6bcc 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * Reports Product Index Abstract Resource Model * @@ -61,14 +63,14 @@ public function updateCustomerFromVisitor(Mage_Reports_Model_Product_Index_Abstr $data = [ 'visitor_id' => $object->getVisitorId(), 'store_id' => $object->getStoreId(), - 'added_at' => Varien_Date::now(), + 'added_at' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), ]; } else { $where = ['index_id = ?' => $row['index_id']]; $data = [ 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), - 'added_at' => Varien_Date::now(), + 'added_at' => Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT), ]; } @@ -179,7 +181,7 @@ public function registerIds(Varien_Object $object, $productIds) 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), ]; - $addedAt = Varien_Date::toTimestamp(true); + $addedAt = Carbon::now()->getTimestamp(); $data = []; foreach ($productIds as $productId) { $productId = (int) $productId; diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php index 71f81f21b24..22d60890932 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * Abstract report aggregate resource model * @@ -52,7 +54,7 @@ protected function _setFlagData($code, $value = null) $this->_getFlag()->setFlagData($value); } - $time = Varien_Date::toTimestamp(true); + $time = Carbon::now()->getTimestamp(); // touch last_update $this->_getFlag()->setLastUpdate($this->formatDate($time)); @@ -399,12 +401,12 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null) $tzTransitions = []; try { if (!empty($from)) { - $from = new Zend_Date($from, Varien_Date::DATETIME_INTERNAL_FORMAT); + $from = new Zend_Date($from, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $from = $from->getTimestamp(); } - $to = new Zend_Date($to, Varien_Date::DATETIME_INTERNAL_FORMAT); - $nextPeriod = $this->_getWriteAdapter()->formatDate($to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $to = new Zend_Date($to, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); + $nextPeriod = $this->_getWriteAdapter()->formatDate($to->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); $to = $to->getTimestamp(); $dtz = new DateTimeZone($timezone); @@ -418,7 +420,7 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null) $dateTimeObject->set($tr['time']); $tr['time'] = $this->_getWriteAdapter() - ->formatDate($dateTimeObject->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + ->formatDate($dateTimeObject->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); $tzTransitions[$tr['offset']][] = ['from' => $tr['time'], 'to' => $nextPeriod]; if (!empty($from) && $tr['ts'] < $from) { @@ -454,7 +456,7 @@ protected function _isValidTransition($transition, $to) { $result = true; $timeStamp = $transition['ts']; - $transitionYear = date('Y', $timeStamp); + $transitionYear = Carbon::createFromTimestamp($timeStamp)->format('Y'); if ($transitionYear > 10000 || $transitionYear < -10000) { $result = false; diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php index ac1272e19cc..55c1741ccc9 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * Report Reviews collection * @@ -59,7 +61,7 @@ class Mage_Reports_Model_Resource_Report_Collection /** * Array of store ids * - * @var array + * @var array|null */ protected $_storeIds; @@ -127,7 +129,7 @@ public function getIntervals() $time['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay()) ->toString('yyyy-MM-dd 23:59:59') - : $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59'); + : $dateStart->toString('yyyy-MM-' . Carbon::createFromTimestamp($dateStart->getTimestamp())->format('t') . ' 23:59:59'); $dateStart->addMonth(1); @@ -170,9 +172,9 @@ public function getIntervals() public function getPeriods() { return [ - 'day' => Mage::helper('reports')->__('Day'), - 'month' => Mage::helper('reports')->__('Month'), - 'year' => Mage::helper('reports')->__('Year'), + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY => Mage::helper('reports')->__('Day'), + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH => Mage::helper('reports')->__('Month'), + Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR => Mage::helper('reports')->__('Year'), ]; } @@ -191,7 +193,7 @@ public function setStoreIds($storeIds) /** * Get store ids * - * @return array + * @return array|null */ public function getStoreIds() { @@ -223,7 +225,7 @@ public function setPageSize($size) /** * Get page size * - * @return int + * @return int|null */ public function getPageSize() { @@ -279,7 +281,7 @@ public function getReport($from, $to) public function timeShift($datetime) { return Mage::app()->getLocale() - ->utcDate(null, $datetime, true, Varien_Date::DATETIME_INTERNAL_FORMAT) - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->utcDate(null, $datetime, true, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT) + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } } diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php index 1fc582dac26..6d9718ef722 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php @@ -165,7 +165,7 @@ protected function _beforeLoad() $selectUnions = []; // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $dtFormat = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); if ($this->_period == 'year') { diff --git a/app/code/core/Mage/Reports/Model/Test.php b/app/code/core/Mage/Reports/Model/Test.php index a61df6ef2a1..f755b8380d0 100644 --- a/app/code/core/Mage/Reports/Model/Test.php +++ b/app/code/core/Mage/Reports/Model/Test.php @@ -7,6 +7,8 @@ * @package Mage_Reports */ +use Carbon\Carbon; + /** * Model for flex reports * @@ -14,6 +16,8 @@ */ class Mage_Reports_Model_Test extends Varien_Object { + public const DATETIME_INTERNAL_FORMAT = 'Y-m-d H:i'; + /** * @return false|string */ @@ -71,16 +75,16 @@ public function getAllLinearExample() { $session = Mage::getModel('review/session'); - $startPoint = time() - 24 * 60 * 60; + $startPoint = Carbon::now()->subDay()->getTimestamp(); $allData = []; $countOfStartData = 12; for ($i = 1; $i <= $countOfStartData; $i++) { - $allData[] = ['time' => date('Y-m-d H:i', $startPoint), 'value' => random_int(1, 100)]; + $allData[] = ['time' => Carbon::createFromTimestamp($startPoint)->format(self::DATETIME_INTERNAL_FORMAT), 'value' => random_int(1, 100)]; $startPoint += 30 * 60; } - $allData[] = ['time' => date('Y-m-d H:i', $startPoint + (90 * 60))]; + $allData[] = ['time' => Carbon::createFromTimestamp($startPoint + (90 * 60))->format(self::DATETIME_INTERNAL_FORMAT)]; $session -> setData('startPoint', $startPoint); @@ -99,11 +103,11 @@ public function getNewLinearData() $reset = 12; $newData = [ - ['time' => date('Y-m-d H:i', $startPoint), 'value' => random_int(1, 100)], + ['time' => Carbon::createFromTimestamp($startPoint)->format(self::DATETIME_INTERNAL_FORMAT), 'value' => random_int(1, 100)], ]; $startPoint += 30 * 60; - $newData[] = ['time' => date('Y-m-d H:i', $startPoint + (90 * 60))]; + $newData[] = ['time' => Carbon::createFromTimestamp($startPoint + (90 * 60))->format(self::DATETIME_INTERNAL_FORMAT)]; $session->setData('startPoint', $startPoint); diff --git a/app/code/core/Mage/Rss/Block/Catalog/New.php b/app/code/core/Mage/Rss/Block/Catalog/New.php index a107e5e803e..bf766d6a936 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/New.php +++ b/app/code/core/Mage/Rss/Block/Catalog/New.php @@ -44,11 +44,11 @@ protected function _toHtml() $todayStartOfDayDate = Mage::app()->getLocale()->date() ->setTime('00:00:00') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $todayEndOfDayDate = Mage::app()->getLocale()->date() ->setTime('23:59:59') - ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + ->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $products = $product->getCollection() ->setStoreId($storeId) diff --git a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php index 317edf91ef4..7c6200921b0 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php @@ -7,6 +7,8 @@ * @package Mage_Rss */ +use Carbon\Carbon; + /** * Review form block * @@ -33,7 +35,7 @@ protected function _toHtml() $storeId = $this->_getStoreId(); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); $customerGroup = $this->_getCustomerGroupId(); - $now = date('Y-m-d'); + $now = Carbon::now()->format('Y-m-d'); $url = Mage::getUrl(''); $newUrl = Mage::getUrl('rss/catalog/salesrule'); $lang = Mage::getStoreConfig('general/locale/code'); diff --git a/app/code/core/Mage/Rss/Block/Catalog/Special.php b/app/code/core/Mage/Rss/Block/Catalog/Special.php index 7a129214f4c..e927cf266ee 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Special.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Special.php @@ -174,7 +174,7 @@ public function addSpecialXmlCallback($args) if (isset($row['special_to_date']) && $row['final_price'] <= $row['special_price'] && $row['allowed_price_in_rss'] ) { - $compareDate = self::$_currentDate->compareDate($row['special_to_date'], Varien_Date::DATE_INTERNAL_FORMAT); + $compareDate = self::$_currentDate->compareDate($row['special_to_date'], Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); if ($compareDate === -1 || $compareDate === 0) { $row['use_special'] = true; } diff --git a/app/code/core/Mage/Rss/Block/Order/New.php b/app/code/core/Mage/Rss/Block/Order/New.php index 5399753c173..8119e299b2c 100644 --- a/app/code/core/Mage/Rss/Block/Order/New.php +++ b/app/code/core/Mage/Rss/Block/Order/New.php @@ -7,6 +7,8 @@ * @package Mage_Rss */ +use Carbon\Carbon; + /** * Review form block * @@ -41,7 +43,7 @@ protected function _toHtml() $order = Mage::getModel('sales/order'); $period = Mage::helper('rss')->getRssAdminOrderNewPeriod($storeId); $passDate = $order->getResource()->formatDate( - mktime(0, 0, 0, (int) date('m'), (int) date('d') - $period), + Carbon::now()->setHour(0)->setMinute(0)->setSecond(0)->subDays($period)->getTimestamp(), ); $newurl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order', ['_secure' => true, '_nosecret' => true]); diff --git a/app/code/core/Mage/Rule/Model/Abstract.php b/app/code/core/Mage/Rule/Model/Abstract.php index f2f5fb27b9d..206f8353bd3 100644 --- a/app/code/core/Mage/Rule/Model/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Abstract.php @@ -35,7 +35,7 @@ abstract class Mage_Rule_Model_Abstract extends Mage_Core_Model_Abstract /** * Store rule combine conditions model * - * @var Mage_Rule_Model_Condition_Combine + * @var Mage_Rule_Model_Condition_Combine|null */ protected $_conditions; @@ -86,6 +86,7 @@ abstract public function getActionsInstance(); * * @param int $storeId * @return Varien_Db_Select + * @throws Mage_Core_Exception */ public function getProductFlatSelect($storeId) { @@ -310,7 +311,9 @@ protected function _convertFlatToRecursive(array $data) $path = explode('--', $id); $node = & $arr; for ($i = 0, $l = count($path); $i < $l; $i++) { - $node = & $node[$key][$path[$i]] ?? []; + // @phpstan-ignore-next-line + $var = $node[$key][$path[$i]] ?? []; + $node = &$var; } foreach ($data as $k => $v) { $node[$k] = $v; @@ -323,7 +326,7 @@ protected function _convertFlatToRecursive(array $data) if (in_array($key, ['from_date', 'to_date']) && $value) { $value = Mage::app()->getLocale()->date( $value, - Varien_Date::DATE_INTERNAL_FORMAT, + Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, null, false, ); @@ -363,8 +366,8 @@ public function validateData(Varien_Object $object) } if ($fromDate && $toDate) { - $fromDate = new Zend_Date($fromDate, Varien_Date::DATE_INTERNAL_FORMAT); - $toDate = new Zend_Date($toDate, Varien_Date::DATE_INTERNAL_FORMAT); + $fromDate = new Zend_Date($fromDate, Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); + $toDate = new Zend_Date($toDate, Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT); if ($fromDate->compare($toDate) === 1) { $result[] = Mage::helper('rule')->__('End Date must be greater than Start Date.'); @@ -437,6 +440,7 @@ public function setIsReadonly($value) * Get rule associated website Ids * * @return array + * @throws Mage_Core_Exception */ public function getWebsiteIds() { diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index 0e76f0c980d..854c995a524 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -366,11 +366,11 @@ public function getValue() $format = null; switch ($this->getInputType()) { case 'date': - $format = Varien_Date::DATE_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; break; case 'datetime': - $format = Varien_Date::DATETIME_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; break; } @@ -603,13 +603,13 @@ public function getValueElement() switch ($this->getInputType()) { case 'date': - $elementParams['input_format'] = Varien_Date::DATE_INTERNAL_FORMAT; - $elementParams['format'] = Varien_Date::DATE_INTERNAL_FORMAT; + $elementParams['input_format'] = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; + $elementParams['format'] = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; break; case 'datetime': - $elementParams['input_format'] = Varien_Date::DATETIME_INTERNAL_FORMAT; - $elementParams['format'] = Varien_Date::DATETIME_INTERNAL_FORMAT; + $elementParams['input_format'] = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; + $elementParams['format'] = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; $elementParams['time'] = true; break; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php index 642e2ed5e85..abd55512797 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Rule */ +use Carbon\Carbon; + /** * Abstract Rule product condition data model * @@ -507,8 +509,8 @@ public function validate(Varien_Object $object) $attr = $object->getResource()->getAttribute($attrCode); if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) { - $this->setValue(strtotime($this->getValue())); - $value = strtotime($object->getData($attrCode)); + $this->setValue(Carbon::parse($this->getValue())->getTimestamp()); + $value = Carbon::parse($object->getData($attrCode))->getTimestamp(); return $this->validateAttribute($value); } @@ -527,7 +529,7 @@ public function validate(Varien_Object $object) foreach ($this->_entityAttributeValues[$object->getId()] as $storeId => $value) { $attr = $object->getResource()->getAttribute($attrCode); if ($attr && $attr->getBackendType() == 'datetime') { - $value = strtotime($value); + $value = Carbon::parse($value)->getTimestamp(); } elseif ($attr && $attr->getFrontendInput() == 'multiselect') { $value = strlen($value) ? explode(',', $value) : []; } diff --git a/app/code/core/Mage/Rule/Model/Environment.php b/app/code/core/Mage/Rule/Model/Environment.php index 0b511a6a09c..a07a7d7ad4f 100644 --- a/app/code/core/Mage/Rule/Model/Environment.php +++ b/app/code/core/Mage/Rule/Model/Environment.php @@ -7,6 +7,8 @@ * @package Mage_Rule */ +use Carbon\Carbon; + /** * Class Mage_Rule_Model_Environment * @@ -24,7 +26,7 @@ class Mage_Rule_Model_Environment extends Varien_Object */ public function collect() { - $this->setNow(time()); + $this->setNow(Carbon::now()->getTimestamp()); Mage::dispatchEvent('rule_environment_collect', ['env' => $this]); diff --git a/app/code/core/Mage/Rule/Model/Resource/Abstract.php b/app/code/core/Mage/Rule/Model/Resource/Abstract.php index 834b18f9928..8725d21ae35 100644 --- a/app/code/core/Mage/Rule/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Resource/Abstract.php @@ -46,14 +46,14 @@ public function _beforeSave(Mage_Core_Model_Abstract $object) { $fromDate = $object->getFromDate(); if ($fromDate instanceof Zend_Date) { - $object->setFromDate($fromDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $object->setFromDate($fromDate->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } elseif (!is_string($fromDate) || empty($fromDate)) { $object->setFromDate(null); } $toDate = $object->getToDate(); if ($toDate instanceof Zend_Date) { - $object->setToDate($toDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $object->setToDate($toDate->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } elseif (!is_string($toDate) || empty($toDate)) { $object->setToDate(null); } diff --git a/app/code/core/Mage/Sales/Model/Abstract.php b/app/code/core/Mage/Sales/Model/Abstract.php index 79709d1154d..e196d66cbaf 100644 --- a/app/code/core/Mage/Sales/Model/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Sales */ +use Carbon\Carbon; + /** * Sales abstract model * Provide date processing functionality @@ -47,10 +49,7 @@ public function afterCommitCallback() public function getCreatedAtDate() { return Mage::app()->getLocale()->date( - Varien_Date::toTimestamp($this->getCreatedAt()), - null, - null, - true, + Carbon::now()->setTimeFromTimeString(($this->getCreatedAt()))->getTimestamp(), ); } @@ -63,7 +62,7 @@ public function getCreatedAtStoreDate() { return Mage::app()->getLocale()->storeDate( $this->getStore(), - Varien_Date::toTimestamp($this->getCreatedAt()), + Carbon::now()->setTimeFromTimeString($this->getCreatedAt())->getTimestamp(), true, ); } diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php index 1d15733117d..1338477780a 100644 --- a/app/code/core/Mage/Sales/Model/Observer.php +++ b/app/code/core/Mage/Sales/Model/Observer.php @@ -7,6 +7,8 @@ * @package Mage_Sales */ +use Carbon\Carbon; + /** * Sales observer * @@ -25,7 +27,6 @@ class Mage_Sales_Model_Observer * Clean expired quotes (cron process) * * @return $this - * @throws Mage_Core_Exception */ public function cleanExpiredQuotes() { @@ -34,12 +35,12 @@ public function cleanExpiredQuotes() foreach ($lifetimes as $storeId => $day) { $day = (int) $day; - $lifetime = 86400 * $day; /** @var Mage_Sales_Model_Resource_Quote_Collection $quotes */ $quotes = Mage::getResourceModel('sales/quote_collection'); $quotes->addFieldToFilter('store_id', $storeId); - $quotes->addFieldToFilter('updated_at', ['to' => date('Y-m-d', time() - $lifetime)]); + $quotes->addFieldToFilter('updated_at', ['to' => Carbon::now()->subDays($day)->format('Y-m-d')]); + if ($day == 0) { $quotes->addFieldToFilter('is_active', 0); } diff --git a/app/code/core/Mage/Sales/Model/Resource/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Abstract.php index d5f9902c1e5..7809b026b18 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Resource/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Sales */ +use Carbon\Carbon; + /** * Sales abstract resource model * @@ -21,7 +23,7 @@ abstract class Mage_Sales_Model_Resource_Abstract extends Mage_Core_Model_Resour */ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) { - $currentTime = Varien_Date::now(); + $currentTime = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) { $object->setCreatedAt($currentTime); } diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php index ec8bda1c7e9..342a8e903d5 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php @@ -61,7 +61,7 @@ public function getSalesOrder() /** * Add order filter * - * @param int|Mage_Sales_Model_Order $order + * @param array|int|Mage_Sales_Model_Order $order * @return $this */ public function setOrderFilter($order) diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php index 9cafe7e315e..8b1034626ce 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php @@ -166,7 +166,7 @@ protected function _beforeLoad() $selectUnions = []; // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $dtFormat = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); if ($this->_period == 'year') { diff --git a/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php b/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php index a1bc9a4b799..0c9729c3978 100644 --- a/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php +++ b/app/code/core/Mage/SalesRule/Model/Coupon/Massgenerator.php @@ -141,7 +141,7 @@ public function generatePool() $expirationDate = $this->getToDate(); if ($expirationDate instanceof Zend_Date) { - $expirationDate = $expirationDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + $expirationDate = $expirationDate->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); } $coupon->setId(null) diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php b/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php index 88f2bc93406..1fce868a598 100644 --- a/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php +++ b/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php @@ -33,7 +33,7 @@ public function _beforeSave(Mage_Core_Model_Abstract $object) if (!$object->getExpirationDate()) { $object->setExpirationDate(null); } elseif ($object->getExpirationDate() instanceof Zend_Date) { - $object->setExpirationDate($object->getExpirationDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + $object->setExpirationDate($object->getExpirationDate()->toString(Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT)); } // maintain single primary coupon per rule diff --git a/app/code/core/Mage/SalesRule/Model/Rule.php b/app/code/core/Mage/SalesRule/Model/Rule.php index 955e02fadef..0929878b27e 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule.php +++ b/app/code/core/Mage/SalesRule/Model/Rule.php @@ -165,7 +165,7 @@ protected function _construct() /** * Returns code mass generator instance for auto generated specific coupons * - * @return Mage_Core_Model_Abstract|Mage_SalesRule_Model_Coupon_Massgenerator + * @return Mage_SalesRule_Model_Coupon_Massgenerator */ public static function getCouponMassGenerator() { @@ -440,7 +440,7 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10) public function hasIsValidForAddress($address) { $addressId = $this->_getAddressId($address); - return isset($this->_validatedAddresses[$addressId]) ? true : false; + return isset($this->_validatedAddresses[$addressId]); } /** diff --git a/app/code/core/Mage/Shipping/Block/Tracking/Popup.php b/app/code/core/Mage/Shipping/Block/Tracking/Popup.php index 048931ae471..c05b8604c5e 100644 --- a/app/code/core/Mage/Shipping/Block/Tracking/Popup.php +++ b/app/code/core/Mage/Shipping/Block/Tracking/Popup.php @@ -7,6 +7,8 @@ * @package Mage_Shipping */ +use Carbon\Carbon; + /** * Class Mage_Shipping_Block_Tracking_Popup * @@ -217,7 +219,7 @@ public function formatDeliveryDate($date) { $locale = Mage::app()->getLocale(); $format = $locale->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM); - return $locale->date(strtotime($date), Zend_Date::TIMESTAMP, null, false) + return $locale->date(Carbon::parse($date)->getTimestamp(), Zend_Date::TIMESTAMP, null, false) ->toString($format); } @@ -237,7 +239,7 @@ public function formatDeliveryTime($time, $date = null) $locale = Mage::app()->getLocale(); $format = $locale->getTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); - return $locale->date(strtotime($time), Zend_Date::TIMESTAMP, null, false) + return $locale->date(Carbon::parse($time)->getTimestamp(), Zend_Date::TIMESTAMP, null, false) ->toString($format); } diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php index 77240cbf6ad..6cfa4c6aa25 100644 --- a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php +++ b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php @@ -7,6 +7,8 @@ * @package Mage_Tag */ +use Carbon\Carbon; + /** * Tag Relation resource model * @@ -168,7 +170,7 @@ public function addRelations($model) 'store_id' => $model->getStoreId(), 'product_id' => $value, 'customer_id' => $model->getCustomerId(), - 'created_at' => $this->formatDate(time()), + 'created_at' => $this->formatDate(Carbon::now()->getTimestamp()), ]; } $write->insertMultiple($this->getMainTable(), $insertData); diff --git a/app/code/core/Mage/Tag/Model/Tag.php b/app/code/core/Mage/Tag/Model/Tag.php index d5834ca8e6f..7b44bc9f3ac 100644 --- a/app/code/core/Mage/Tag/Model/Tag.php +++ b/app/code/core/Mage/Tag/Model/Tag.php @@ -7,6 +7,8 @@ * @package Mage_Tag */ +use Carbon\Carbon; + /** * Tag model * @@ -356,7 +358,7 @@ public function saveRelation($productId, $customerId, $storeId) ->setProductId($productId) ->setCustomerId($customerId) ->setActive(Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE) - ->setCreatedAt($relationModel->getResource()->formatDate(time())); + ->setCreatedAt($relationModel->getResource()->formatDate(Carbon::now()->getTimestamp())); $result = ''; $relationModelSaveNeed = false; diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php index 59b352df9f3..e089f0b03c7 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php @@ -7,6 +7,8 @@ * @package Mage_Usa */ +use Carbon\Carbon; + /** * DHL Abstract class * @@ -59,12 +61,12 @@ protected function _determineShippingDay($shippingDays, $date) $shippingDays = explode(',', $shippingDays); $i = 0; - $weekday = date('D', strtotime($date)); + $weekday = Carbon::parse($date)->format('D'); while (!in_array($weekday, $shippingDays) && $i < 10) { $i++; - $weekday = date('D', strtotime("$date +$i day")); + $weekday = Carbon::parse("$date +$i day")->format('D'); } - return date(self::REQUEST_DATE_FORMAT, strtotime("$date +$i day")); + return Carbon::parse("$date +$i day")->format(self::REQUEST_DATE_FORMAT); } } diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php index 1b8b7714381..cc8e9e2b5d0 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php @@ -7,6 +7,8 @@ * @package Mage_Usa */ +use Carbon\Carbon; + /** * DHL International (API v1.4) * @@ -771,7 +773,7 @@ protected function _getQuotes() $debugPoint = &$debugData['try-' . $offset]; $requestXml = $this->_buildQuotesRequestXml(); - $date = date(self::REQUEST_DATE_FORMAT, strtotime($this->_getShipDate() . " +$offset days")); + $date = Carbon::parse($this->_getShipDate() . " +$offset days")->format(self::REQUEST_DATE_FORMAT); $this->_setQuotesRequestXmlDate($requestXml, $date); $request = $requestXml->asXML(); diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php index 12401b020db..8415431374e 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php @@ -7,6 +7,8 @@ * @package Mage_Usa */ +use Carbon\Carbon; + /** * Fedex shipping implementation * @@ -304,7 +306,7 @@ protected function _formRateRequest($purpose) 'Version' => $this->getVersionInfo(), 'RequestedShipment' => [ 'DropoffType' => $r->getDropoffType(), - 'ShipTimestamp' => date('c'), + 'ShipTimestamp' => Carbon::now()->format('c'), 'PackagingType' => $r->getPackaging(), 'TotalInsuredValue' => [ 'Amount' => $r->getValue(), @@ -594,7 +596,7 @@ protected function _getXmlQuotes() $requestHeader->addChild('AccountNumber', $r->getAccount()); $requestHeader->addChild('MeterNumber', '0'); - $xml->addChild('ShipDate', date('Y-m-d')); + $xml->addChild('ShipDate', Carbon::now()->format('Y-m-d')); $xml->addChild('DropoffType', $r->getDropoffType()); if ($r->hasService()) { $xml->addChild('Service', $r->getService()); @@ -1042,10 +1044,10 @@ protected function _parseTrackingResponse($trackingValue, $response) $resultArray['status'] = (string) $trackInfo->StatusDescription; $resultArray['service'] = (string) $trackInfo->ServiceInfo; $timestamp = $trackInfo->EstimatedDeliveryTimestamp ?? $trackInfo->ActualDeliveryTimestamp; - $timestamp = strtotime((string) $timestamp); + $timestamp = Carbon::parse((string) $timestamp)->getTimestamp(); if ($timestamp) { - $resultArray['deliverydate'] = date('Y-m-d', $timestamp); - $resultArray['deliverytime'] = date('H:i:s', $timestamp); + $resultArray['deliverydate'] = Carbon::createFromTimestamp($timestamp)->format('Y-m-d'); + $resultArray['deliverytime'] = Carbon::createFromTimestamp($timestamp)->format('H:i:s'); } $deliveryLocation = $trackInfo->EstimatedDeliveryAddress ?? $trackInfo->ActualDeliveryAddress; @@ -1064,7 +1066,7 @@ protected function _parseTrackingResponse($trackingValue, $response) } $resultArray['signedby'] = (string) $trackInfo->DeliverySignatureName; - $resultArray['shippeddate'] = date('Y-m-d', (int) $trackInfo->ShipTimestamp); + $resultArray['shippeddate'] = Carbon::createFromTimestamp((int) $trackInfo->ShipTimestamp)->format('Y-m-d'); if (isset($trackInfo->PackageWeight) && isset($trackInfo->Units)) { $weight = (string) $trackInfo->PackageWeight; $unit = (string) $trackInfo->Units; @@ -1080,10 +1082,10 @@ protected function _parseTrackingResponse($trackingValue, $response) foreach ($events as $event) { $tempArray = []; $tempArray['activity'] = (string) $event->EventDescription; - $timestamp = strtotime((string) $event->Timestamp); + $timestamp = Carbon::parse((string) $event->Timestamp)->getTimestamp(); if ($timestamp) { - $tempArray['deliverydate'] = date('Y-m-d', $timestamp); - $tempArray['deliverytime'] = date('H:i:s', $timestamp); + $tempArray['deliverydate'] = Carbon::createFromTimestamp($timestamp)->format('Y-m-d'); + $tempArray['deliverytime'] = Carbon::createFromTimestamp($timestamp)->format('H:i:s'); } if (isset($event->Address)) { $addressArray = []; @@ -1337,10 +1339,10 @@ protected function _formShipmentRequest(Varien_Object $request) $paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER'; $requestClient = [ 'RequestedShipment' => [ - 'ShipTimestamp' => time(), + 'ShipTimestamp' => Carbon::now()->getTimestamp(), 'DropoffType' => $this->getConfigData('dropoff'), 'PackagingType' => $request->getPackagingType(), - 'ServiceType' => $request->getShippingMethod(), + 'ServiceType' => $request->getShippingMethod(), 'Shipper' => [ 'Contact' => [ 'PersonName' => $request->getShipperContactPersonName(), diff --git a/app/code/core/Mage/Weee/Model/Resource/Tax.php b/app/code/core/Mage/Weee/Model/Resource/Tax.php index f40b47b9ab1..092932490df 100644 --- a/app/code/core/Mage/Weee/Model/Resource/Tax.php +++ b/app/code/core/Mage/Weee/Model/Resource/Tax.php @@ -7,6 +7,8 @@ * @package Mage_Weee */ +use Carbon\Carbon; + /** * Wee tax resource model * @@ -70,7 +72,7 @@ public function updateProductsDiscountPercent($condition) */ protected function _updateDiscountPercents($productCondition = null) { - $now = Varien_Date::toTimestamp(Varien_Date::now()); + $now = Carbon::now()->getTimestamp(); $adapter = $this->_getWriteAdapter(); $select = $this->_getReadAdapter()->select(); diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php b/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php index 7445d88c007..76fbb7a2a54 100644 --- a/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php @@ -386,14 +386,14 @@ public function addDaysFilter($constraints) $now = Mage::getSingleton('core/date')->date(); $gmtOffset = (int) Mage::getSingleton('core/date')->getGmtOffset(); if (isset($constraints['from'])) { - $lastDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $lastDay = new Zend_Date($now, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $lastDay->subSecond($gmtOffset) ->subDay($constraints['from'] - 1); $filter['to'] = $lastDay; } if (isset($constraints['to'])) { - $firstDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $firstDay = new Zend_Date($now, Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT); $firstDay->subSecond($gmtOffset) ->subDay($constraints['to']); $filter['from'] = $firstDay; diff --git a/app/code/core/Mage/Wishlist/Model/Wishlist.php b/app/code/core/Mage/Wishlist/Model/Wishlist.php index 902a0187675..0e0a33a2f95 100644 --- a/app/code/core/Mage/Wishlist/Model/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Model/Wishlist.php @@ -193,7 +193,7 @@ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty $item = Mage::getModel('wishlist/item'); $item->setProductId($product->getId()) ->setWishlistId($this->getId()) - ->setAddedAt(Varien_Date::now()) + ->setAddedAt(now()) ->setStoreId($storeId) ->setOptions($product->getCustomOptions()) ->setProduct($product) diff --git a/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml b/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml index d40495d72c6..402e62cc7f4 100644 --- a/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml +++ b/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml @@ -12,7 +12,7 @@ */ ?> - +getTimestamp() ?>
    - +
    diff --git a/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml b/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml index b8f24dac9b5..8f5e6dc2923 100644 --- a/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml +++ b/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml @@ -21,7 +21,7 @@

    __('Rejection Of Authorization') ?>

    getMessagesBlock()->toHtml() ?> - +
    diff --git a/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml b/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml index b6111b6cfec..0a544dbec33 100644 --- a/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml +++ b/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml @@ -39,7 +39,7 @@ if (!is_null($this->getValues())): ?> getValues()->getAttributeBackend()->getImageTypes() as $type): ?> - <?php echo $image->getValue() ?>
    + <?php echo $image->getValue() ?>
    diff --git a/app/design/frontend/base/default/template/customer/orders.phtml b/app/design/frontend/base/default/template/customer/orders.phtml index 6e973d7b7bd..2d3a9ce5be7 100644 --- a/app/design/frontend/base/default/template/customer/orders.phtml +++ b/app/design/frontend/base/default/template/customer/orders.phtml @@ -29,7 +29,7 @@ getRealOrderId() ?>  - getCreatedAt())) ?>  + getCreatedAt())->format("D, j M, Y") ?>  getGrandTotal() ?>  getStatus() ?>  diff --git a/app/design/install/default/default/template/page.phtml b/app/design/install/default/default/template/page.phtml index 790bbec2863..c1fa4f0ffac 100644 --- a/app/design/install/default/default/template/page.phtml +++ b/app/design/install/default/default/template/page.phtml @@ -90,7 +90,7 @@ $('bug_tracking_link').target = "varien_external"; //]]> - __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', date('Y')) ?> + __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', \Carbon\Carbon::now()->format('Y')) ?>

    diff --git a/app/etc/modules/Mage_Admin.xml b/app/etc/modules/Mage_Admin.xml index d901ecb076c..b4f488347d0 100644 --- a/app/etc/modules/Mage_Admin.xml +++ b/app/etc/modules/Mage_Admin.xml @@ -7,7 +7,9 @@ * @package Mage_Admin */ --> - + true diff --git a/composer.json b/composer.json index 8a75b4be6af..33beb7aab96 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "flowjs/flowjs": "dev-master", "magento-hackathon/magento-composer-installer": "^3.1 || ^2.1 || ^4.0", "mklkj/tinymce-i18n": "^25.2", + "nesbot/carbon": "^2.73", "nnnick/chartjs": "^4.4", "openmage/composer-plugin": "^3.0", "pelago/emogrifier": "^7.0", diff --git a/composer.lock b/composer.lock index c4adef85bb0..fd57c611fde 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9b28e4ca972506fbf0f405c2b014d7b5", + "content-hash": "e38313278e23a31ff906c5cd679c5ac7", "packages": [ { "name": "carbonphp/carbon-doctrine-types", @@ -9257,5 +9257,5 @@ "platform-overrides": { "php": "8.1" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/get.php b/get.php index a92e2c9bbf8..491ab71acfe 100644 --- a/get.php +++ b/get.php @@ -7,6 +7,8 @@ * @package Mage */ +use Carbon\Carbon; + $start = microtime(true); /** * Error reporting @@ -55,7 +57,7 @@ $config = json_decode(file_get_contents($configCacheFile), true); //checking update time - if (filemtime($configCacheFile) + $config['update_time'] > time()) { + if (filemtime($configCacheFile) + $config['update_time'] > Carbon::now()->getTimestamp()) { $mediaDirectory = trim(str_replace($bp . $ds, '', $config['media_directory']), $ds); $allowedResources = array_merge($allowedResources, $config['allowed_resources']); } diff --git a/lib/Mage/Cache/Backend/File.php b/lib/Mage/Cache/Backend/File.php index a8e7b39dd8e..841d3257c0c 100644 --- a/lib/Mage/Cache/Backend/File.php +++ b/lib/Mage/Cache/Backend/File.php @@ -35,6 +35,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +use Carbon\Carbon; + /** * Optimized file cache backend * @@ -62,7 +64,7 @@ class Mage_Cache_Backend_File extends Zend_Cache_Backend_File /** * Prevents unnecessary checks * - * @var boolean + * @var bool */ protected $_isTagDirChecked; @@ -127,7 +129,7 @@ public function load($id, $doNotTestCacheValidity = false) return false; } [$metadatas, $data] = $cache; - if (!$doNotTestCacheValidity && time() > $metadatas['expire']) { + if (!$doNotTestCacheValidity && Carbon::now()->greaterThan($metadatas['expire'])) { // ?? $this->remove($id); return false; } @@ -181,7 +183,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false) } $metadatas = [ 'hash' => $hash, - 'mtime' => time(), + 'mtime' => Carbon::now()->getTimestamp(), 'expire' => $this->_expireTime($this->getLifetime($specificLifetime)), 'tags' => implode(',', $tags), ]; @@ -331,7 +333,7 @@ public function getMetadatas($id) * @param string $id Cache id * @param int $extraLifetime * - * @return boolean In case of success returns true + * @return bool In case of success returns true */ public function touch($id, $extraLifetime) { @@ -341,12 +343,12 @@ public function touch($id, $extraLifetime) return false; } [$metadatas, $data] = $cache; - if (time() > $metadatas['expire']) { + if (Carbon::now()->greaterThan($metadatas['expire'])) { return false; } $newMetadatas = [ 'hash' => $metadatas['hash'], - 'mtime' => time(), + 'mtime' => Carbon::now()->getTimestamp(), 'expire' => $metadatas['expire'] + $extraLifetime, 'tags' => $metadatas['tags'], ]; @@ -428,7 +430,7 @@ protected function _setMetadatas($id, $metadatas, $save = true) * Uses multiple letters for a single-level hash rather than multiple levels * * @param string $id Cache id - * @param boolean $parts If true, returns array of directory parts instead of single string + * @param bool $parts If true, returns array of directory parts instead of single string * * @return string|array Complete directory path */ @@ -465,7 +467,7 @@ protected function _path($id, $parts = false) * @param array $tags * * @throws Zend_Cache_Exception - * @return boolean In case of success returns true + * @return bool In case of success returns true * * @SuppressWarnings("PHPMD.ErrorControlOperator") */ @@ -498,7 +500,7 @@ protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = [ continue; } if ($mode == Zend_Cache::CLEANING_MODE_OLD) { - if (time() > $metadatas['expire']) { + if (Carbon::now()->greaterThan($metadatas['expire'])) { $result = $this->_remove($file) && $result; $result = $this->_updateIdsTags([$id], explode(',', $metadatas['tags']), 'diff') && $result; } @@ -541,8 +543,7 @@ protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = [ * @param string $mode Clean mode * @param array $tags Array of tags * - * @throws Zend_Cache_Exception - * @return boolean In case of success returns true + * @return bool In case of success returns true */ protected function _cleanNew($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) { @@ -686,7 +687,7 @@ protected function _getTagIds($tag) * @param array $tags * @param string $mode * - * @return boolean + * @return bool */ protected function _updateIdsTags($ids, $tags, $mode) { @@ -734,7 +735,7 @@ protected function _updateIdsTags($ids, $tags, $mode) * @param string $file File complete path * @param string $string String to put in file * - * @return boolean In case of success returns true + * @return true|int In case of success returns true * * @SuppressWarnings("PHPMD.ErrorControlOperator") */ @@ -752,7 +753,7 @@ protected function _filePutContents($file, $string) * Make the directory structure for the given id * * @param string $id cache id - * @return boolean true + * @return bool true * * @SuppressWarnings("PHPMD.ErrorControlOperator") */ diff --git a/lib/Varien/Cache/Backend/Database.php b/lib/Varien/Cache/Backend/Database.php index a70bd1857b7..c981cc99fde 100644 --- a/lib/Varien/Cache/Backend/Database.php +++ b/lib/Varien/Cache/Backend/Database.php @@ -30,6 +30,8 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8; */ +use Carbon\Carbon; + /** * Database cache backend */ @@ -54,6 +56,7 @@ class Varien_Cache_Backend_Database extends Zend_Cache_Backend implements Zend_C * Constructor * * @param array $options associative array of options + * @throws Zend_Cache_Exception */ public function __construct($options = []) { @@ -72,6 +75,7 @@ public function __construct($options = []) * Get DB adapter * * @return Zend_Db_Adapter_Abstract + * @throws Zend_Cache_Exception */ protected function _getAdapter() { @@ -115,8 +119,8 @@ protected function _getTagsTable() * * Note : return value is always "string" (unserialization is done by the core not by the backend) * - * @param string $id Cache id - * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested + * @param string $id Cache id + * @param bool $doNotTestCacheValidity If set to true, the cache validity won't be tested * @return string|false cached data */ public function load($id, $doNotTestCacheValidity = false) @@ -127,7 +131,7 @@ public function load($id, $doNotTestCacheValidity = false) ->where('id=:cache_id'); if (!$doNotTestCacheValidity) { - $select->where('expire_time=0 OR expire_time>?', time()); + $select->where('expire_time=0 OR expire_time>?', Carbon::now()->getTimestamp()); } return $this->_getAdapter()->fetchOne($select, ['cache_id' => $id]); } else { @@ -139,7 +143,7 @@ public function load($id, $doNotTestCacheValidity = false) * Test if a cache is available or not (for the given id) * * @param string $id cache id - * @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record + * @return false|null|string (a cache is not available) or "last modified" timestamp (int) of the available cache record */ public function test($id) { @@ -147,7 +151,7 @@ public function test($id) $select = $this->_getAdapter()->select() ->from($this->_getDataTable(), 'update_time') ->where('id=:cache_id') - ->where('expire_time=0 OR expire_time>?', time()); + ->where('expire_time=0 OR expire_time>?', Carbon::now()->getTimestamp()); return $this->_getAdapter()->fetchOne($select, ['cache_id' => $id]); } else { return false; @@ -175,7 +179,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false) $dataTable = $this->_getDataTable(); $lifetime = $this->getLifetime($specificLifetime); - $time = time(); + $time = Varien_Date::toTimestamp(true); $expire = ($lifetime === 0 || $lifetime === null) ? 0 : $time + $lifetime; $dataCol = $adapter->quoteIdentifier('data'); @@ -252,7 +256,9 @@ protected function _deleteCachesFromTagsTable($cacheIdsToRemove) * * @param string $mode Clean mode * @param array $tags Array of tags - * @return boolean true if no problem + * @return bool true if no problem + * @throws Zend_Cache_Exception + * @throws Zend_Db_Statement_Exception */ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) { @@ -278,7 +284,6 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) break; default: Zend_Cache::throwException('Invalid mode for clean() method'); - break; } return $result; @@ -291,7 +296,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) */ protected function _cleanOldCache() { - $time = time(); + $time = Varien_Date::toTimestamp(true); $counter = 0; $result = true; $adapter = $this->_getAdapter(); @@ -451,7 +456,7 @@ public function getMetadatas($id) * * @param string $id cache id * @param int $extraLifetime - * @return int|true if ok + * @return int|true true if ok */ public function touch($id, $extraLifetime) { @@ -459,7 +464,7 @@ public function touch($id, $extraLifetime) return $this->_getAdapter()->update( $this->_getDataTable(), ['expire_time' => new Zend_Db_Expr('expire_time+' . $extraLifetime)], - ['id=?' => $id, 'expire_time = 0 OR expire_time>?' => time()], + ['id=?' => $id, 'expire_time = 0 OR expire_time>?' => Varien_Date::toTimestamp(true)], ); } else { return true; @@ -540,6 +545,8 @@ protected function _saveTags($id, $tags) * @param string $mode * @param array $tags * @return bool + * @throws Zend_Cache_Exception + * @throws Zend_Db_Statement_Exception */ protected function _cleanByTags($mode, $tags) { @@ -561,7 +568,6 @@ protected function _cleanByTags($mode, $tags) break; default: Zend_Cache::throwException('Invalid mode for _cleanByTags() method'); - break; } $cacheIdsToRemove = []; diff --git a/lib/Varien/Data/Form/Element/Date.php b/lib/Varien/Data/Form/Element/Date.php index 9e15728cdbe..ab9a9db3d84 100644 --- a/lib/Varien/Data/Form/Element/Date.php +++ b/lib/Varien/Data/Form/Element/Date.php @@ -84,7 +84,7 @@ public function setValue($value, $format = null, $locale = null) } // last check, if input format was set if (null === $format) { - $format = Varien_Date::DATETIME_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT; if ($this->getInputFormat()) { $format = $this->getInputFormat(); } diff --git a/lib/Varien/Data/Form/Filter/Date.php b/lib/Varien/Data/Form/Filter/Date.php index 2c28988b53f..58e1cca8086 100644 --- a/lib/Varien/Data/Form/Filter/Date.php +++ b/lib/Varien/Data/Form/Filter/Date.php @@ -37,7 +37,7 @@ class Varien_Data_Form_Filter_Date implements Varien_Data_Form_Filter_Interface public function __construct($format = null, $locale = null) { if (is_null($format)) { - $format = Varien_Date::DATE_INTERNAL_FORMAT; + $format = Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT; } $this->_dateFormat = $format; $this->_locale = $locale; @@ -60,7 +60,7 @@ public function inputFilter($value) 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); @@ -81,7 +81,7 @@ public function outputFilter($value) } $filterInput = new Zend_Filter_LocalizedToNormalized([ - 'date_format' => Varien_Date::DATE_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ diff --git a/lib/Varien/Data/Form/Filter/Datetime.php b/lib/Varien/Data/Form/Filter/Datetime.php index a289c3a043d..9e21e740429 100644 --- a/lib/Varien/Data/Form/Filter/Datetime.php +++ b/lib/Varien/Data/Form/Filter/Datetime.php @@ -31,7 +31,7 @@ public function inputFilter($value) 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ - 'date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); @@ -52,7 +52,7 @@ public function outputFilter($value) } $filterInput = new Zend_Filter_LocalizedToNormalized([ - 'date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT, + 'date_format' => Mage_Core_Helper_Date::DATETIME_INTERNAL_FORMAT, 'locale' => $this->_locale, ]); $filterInternal = new Zend_Filter_NormalizedToLocalized([ diff --git a/lib/Varien/Date.php b/lib/Varien/Date.php index f6839c7525f..acf4cbb8373 100644 --- a/lib/Varien/Date.php +++ b/lib/Varien/Date.php @@ -7,11 +7,16 @@ * @package Varien_Date */ +use Carbon\Carbon; + /** * Converter of date formats * Internal dates * * @package Varien_Date + * @deprecated + * @see Carbon + * @see Mage_Core_Helper_Date */ class Varien_Date { @@ -109,17 +114,18 @@ public static function toTimestamp($date) } if ($date === true) { - return time(); + return Carbon::now()->getTimestamp(); } - return strtotime($date); + return Carbon::parse($date)->getTimestamp(); } /** * Retrieve current date in internal format * - * @param boolean $withoutTime day only flag + * @param bool $withoutTime day only flag * @return string + * @deprecated replaced by carbon */ public static function now($withoutTime = false) { @@ -157,6 +163,6 @@ public static function formatDate($date, $includeTime = true) } $format = $includeTime ? self::DATETIME_PHP_FORMAT : self::DATE_PHP_FORMAT; - return date($format, $date); + return Carbon::createFromTimestamp($date)->format($format); } } diff --git a/lib/Varien/Db/Adapter/Mysqli.php b/lib/Varien/Db/Adapter/Mysqli.php index 82f81d8762a..a188b60aaae 100644 --- a/lib/Varien/Db/Adapter/Mysqli.php +++ b/lib/Varien/Db/Adapter/Mysqli.php @@ -1,5 +1,7 @@ toString(self::ISO_DATE_FORMAT); } - return date(Varien_Db_Adapter_Pdo_Mysql::DATE_FORMAT, strtotime($date)); + return Carbon::parse($date)->format(Varien_Db_Adapter_Pdo_Mysql::DATE_FORMAT); } public function convertDateTime($datetime) @@ -112,7 +114,7 @@ public function convertDateTime($datetime) if ($datetime instanceof Zend_Date) { return $datetime->toString(self::ISO_DATETIME_FORMAT); } - return date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($datetime)); + return Carbon::parse($datetime)->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT); } // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps diff --git a/lib/Varien/Event/Observer/Cron.php b/lib/Varien/Event/Observer/Cron.php index ebeecc0d0c5..34f76f7c94b 100644 --- a/lib/Varien/Event/Observer/Cron.php +++ b/lib/Varien/Event/Observer/Cron.php @@ -7,6 +7,8 @@ * @package Varien_Event */ +use Carbon\Carbon; + /** * Event cron observer object * @@ -47,7 +49,7 @@ public function isValidFor(Varien_Event $event) public function getNow() { if (!$this->hasNow()) { - $this->setNow(time()); + $this->setNow(Carbon::now()->getTimestamp()); } return $this->getData('now'); } diff --git a/lib/Varien/File/Uploader.php b/lib/Varien/File/Uploader.php index 4bba906e57d..9bf44e9cd3b 100644 --- a/lib/Varien/File/Uploader.php +++ b/lib/Varien/File/Uploader.php @@ -32,7 +32,6 @@ class Varien_File_Uploader * Uploaded file handle (copy of $_FILES[] element) * * @var array - * @access protected */ protected $_file; @@ -40,7 +39,6 @@ class Varien_File_Uploader * Uploaded file mime type * * @var string - * @access protected */ protected $_fileMimeType; @@ -48,7 +46,6 @@ class Varien_File_Uploader * Upload type. Used to right handle $_FILES array. * * @var int Varien_File_Uploader::SINGLE_STYLE|Varien_File_Uploader::MULTIPLE_STYLE - * @access protected */ protected $_uploadType; @@ -57,7 +54,6 @@ class Varien_File_Uploader * we will change file name, this variable will be changed too. * * @var string - * @access protected */ protected $_uploadedFileName; @@ -65,7 +61,6 @@ class Varien_File_Uploader * The name of destination directory * * @var string - * @access protected */ protected $_uploadedFileDir; @@ -74,7 +69,6 @@ class Varien_File_Uploader * non-existent directories. * * @var bool - * @access protected */ protected $_allowCreateFolders = true; @@ -83,7 +77,6 @@ class Varien_File_Uploader * name already exists in the destination directory (if enabled). * * @var bool - * @access protected */ protected $_allowRenameFiles = false; @@ -91,7 +84,6 @@ class Varien_File_Uploader * If this variable is set to TRUE, files despersion will be supported. * * @var bool - * @access protected */ protected $_enableFilesDispersion = false; @@ -101,13 +93,11 @@ class Varien_File_Uploader * (e.g. NTFS->ext or ext->NTFS) * * @var bool - * @access protected */ protected $_caseInsensitiveFilenames = true; /** * @var string - * @access protected */ protected $_dispretionPath = null; @@ -126,7 +116,6 @@ class Varien_File_Uploader * Validate callbacks storage * * @var array - * @access protected */ protected $_validateCallbacks = []; @@ -176,7 +165,6 @@ protected function _afterSave($result) * * @param string $destinationFolder * @param string $newFileName - * @access public * @return array|false */ public function save($destinationFolder, $newFileName = null) @@ -248,7 +236,6 @@ protected function _moveFile($tmpPath, $destPath) /** * Validate file before save * - * @access public */ protected function _validateFile() { @@ -308,7 +295,6 @@ public function addValidateCallback($callbackName, $callbackObject, $callbackMet * Delete validation callback model for us in self::_validateFile() * * @param string $callbackName - * @access public * @return Varien_File_Uploader */ public function removeValidateCallback($callbackName) @@ -362,7 +348,6 @@ protected static function _addDirSeparator($dir) * Used to check if uploaded file mime type is valid or not * * @param array $validTypes - * @access public * @return bool */ public function checkMimeType($validTypes = []) @@ -381,7 +366,6 @@ public function checkMimeType($validTypes = []) /** * Returns a name of uploaded file * - * @access public * @return string */ public function getUploadedFileName() @@ -393,7 +377,6 @@ public function getUploadedFileName() * Used to set {@link _allowCreateFolders} value * * @param mixed $flag - * @access public * @return Varien_File_Uploader */ public function setAllowCreateFolders($flag) @@ -406,7 +389,6 @@ public function setAllowCreateFolders($flag) * Used to set {@link _allowRenameFiles} value * * @param mixed $flag - * @access public * @return Varien_File_Uploader */ public function setAllowRenameFiles($flag) @@ -419,7 +401,6 @@ public function setAllowRenameFiles($flag) * Used to set {@link _enableFilesDispersion} value * * @param mixed $flag - * @access public * @return Varien_File_Uploader */ public function setFilesDispersion($flag) diff --git a/lib/Varien/File/Uploader/Image.php b/lib/Varien/File/Uploader/Image.php index 27a2fe4f2bd..416c5ba9d5a 100644 --- a/lib/Varien/File/Uploader/Image.php +++ b/lib/Varien/File/Uploader/Image.php @@ -65,7 +65,6 @@ public function rotate($degrees = null) * * Default value is h (flip horizontally) * - * @access public * @param string $type */ public function flip($type = 'h') diff --git a/lib/Varien/Image.php b/lib/Varien/Image.php index ae3ad66928a..bc3d682cd5b 100644 --- a/lib/Varien/Image.php +++ b/lib/Varien/Image.php @@ -57,7 +57,6 @@ public function __destruct() /** * Opens an image and creates image handle * - * @access public * @return void */ public function open() @@ -74,7 +73,6 @@ public function open() /** * Display handled image in your browser * - * @access public * @return void */ public function display() @@ -87,7 +85,6 @@ public function display() * * @param string $destination. Default value is NULL * @param string $newFileName. Default value is NULL - * @access public * @return void */ public function save($destination = null, $newFileName = null) @@ -99,7 +96,6 @@ public function save($destination = null, $newFileName = null) * Rotate an image. * * @param int $angle - * @access public * @return void */ public function rotate($angle) @@ -114,7 +110,6 @@ public function rotate($angle) * @param int $left. Default value is 0 * @param int $right. Default value is 0 * @param int $bottom. Default value is 0 - * @access public * @return void */ public function crop($top = 0, $left = 0, $right = 0, $bottom = 0) @@ -127,7 +122,6 @@ public function crop($top = 0, $left = 0, $right = 0, $bottom = 0) * * @param int $width * @param int $height - * @access public * @return void */ public function resize($width, $height = null) @@ -179,7 +173,6 @@ public function quality($value) * @param int $positionY. Watermark Y position. * @param int $watermarkImageOpacity. Watermark image opacity. * @param bool $repeat. Enable or disable watermark brick. - * @access public * @return void */ public function watermark($watermarkImage, $positionX = 0, $positionY = 0, $watermarkImageOpacity = 30, $repeat = false) @@ -193,7 +186,6 @@ public function watermark($watermarkImage, $positionX = 0, $positionY = 0, $wate /** * Get mime type of handled image * - * @access public * @return string */ public function getMimeType() @@ -204,7 +196,6 @@ public function getMimeType() /** * process * - * @access public * @return void */ public function process() {} @@ -212,7 +203,6 @@ public function process() {} /** * instruction * - * @access public * @return void */ public function instruction() {} @@ -221,7 +211,6 @@ public function instruction() {} * Set image background color * * @param int $color - * @access public * @return void */ public function setImageBackgroundColor($color) diff --git a/lib/Varien/Io/File.php b/lib/Varien/Io/File.php index b862d0b0752..80a33a065a9 100644 --- a/lib/Varien/Io/File.php +++ b/lib/Varien/Io/File.php @@ -7,6 +7,8 @@ * @package Varien_Io */ +use Carbon\Carbon; + /** * Filesystem client * @@ -47,7 +49,6 @@ class Varien_Io_File extends Varien_Io_Abstract * non-existent directories. * * @var bool - * @access protected */ protected $_allowCreateFolders = false; @@ -264,8 +265,7 @@ public function streamClose() * * @param string $part the part of statistic * @param mixed $default default value for part - * @return array|bool - * + * @return array|string|false * @SuppressWarnings("PHPMD.ErrorControlOperator") */ public function streamStat($part = null, $default = null) @@ -313,7 +313,6 @@ public function open(array $args = []) * Used to set {@link _allowCreateFolders} value * * @param bool $flag - * @access public * @return $this */ public function setAllowCreateFolders($flag) @@ -770,7 +769,6 @@ public function chmod($filename, $mode) * - LS_ALL = 3 * * @param Varien_Io_File $grep const - * @access public * @return array */ public function ls($grep = null) @@ -802,7 +800,7 @@ public function ls($grep = null) } $list_item['text'] = $entry; - $list_item['mod_date'] = date(Varien_Date::DATETIME_PHP_FORMAT, filectime($fullpath)); + $list_item['mod_date'] = Carbon::createFromTimestamp(filectime($fullpath))->format(Mage_Core_Helper_Date::DATETIME_PHP_FORMAT); $list_item['permissions'] = $this->_parsePermissions(fileperms($fullpath)); $list_item['owner'] = $this->_getFileOwner($fullpath); @@ -845,7 +843,6 @@ public function ls($grep = null) * Convert integer permissions format into human readable * * @param integer $mode - * @access protected * @return string */ protected function _parsePermissions($mode) @@ -901,7 +898,6 @@ protected function _parsePermissions($mode) * Get file owner * * @param string $filename - * @access protected * @return string */ protected function _getFileOwner($filename) diff --git a/tests/unit/Mage/Reports/Helper/DataTest.php b/tests/unit/Mage/Reports/Helper/DataTest.php index 2848ba24444..519cf1a1048 100644 --- a/tests/unit/Mage/Reports/Helper/DataTest.php +++ b/tests/unit/Mage/Reports/Helper/DataTest.php @@ -53,12 +53,8 @@ public function testIsReportsEnabled(): void * @dataProvider provideReportsDateIntervals * @group Helper */ - public function testGetIntervals(int|string $expectedResult, string $from, string $to, string $period): void + public function testGetIntervals(int $expectedResult, string $from, string $to, string $period): void { - if (PHP_VERSION_ID >= 80300 && version_compare(InstalledVersions::getPrettyVersion('shardj/zf1-future'), '1.24.2', '<=')) { - static::markTestSkipped('see https://github.com/Shardj/zf1-future/pull/465'); - } - try { static::assertCount($expectedResult, self::$subject->getIntervals($from, $to, $period)); } catch (Zend_Date_Exception $exception) { diff --git a/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php b/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php index 47a1b69aff6..9c12e4e5110 100644 --- a/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php +++ b/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php @@ -10,6 +10,7 @@ namespace OpenMage\Tests\Unit\Traits\DataProvider\Mage\Core\Helper; +use Carbon\Carbon; use Generator; trait DataTrait @@ -18,9 +19,9 @@ public function provideFormatTimezoneDate(): Generator { /** @phpstan-ignore method.nonObject */ $date = date_create()->getTimestamp(); - $dateShort = date('n/j/Y', $date); - $dateLong = date('F j, Y', $date); - $dateShortTime = date('n/j/Y g:i A', $date); + $dateShort = Carbon::createFromTimestamp($date)->format('n/j/Y'); + $dateLong = Carbon::createFromTimestamp($date)->format('F j, Y'); + # $dateShortTime = Carbon::createFromTimestamp($date)->format('n/j/Y g:i A'); yield 'null' => [ $dateShort, diff --git a/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php b/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php index dfde13394c9..cb9fa71864d 100644 --- a/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php +++ b/tests/unit/Traits/DataProvider/Mage/Reports/ReportsTrait.php @@ -10,8 +10,9 @@ namespace OpenMage\Tests\Unit\Traits\DataProvider\Mage\Reports; +use Carbon\Carbon; use Generator; -use Mage_Reports_Helper_Data; +use Mage_Reports_Helper_Data as Helper; trait ReportsTrait { @@ -21,110 +22,114 @@ trait ReportsTrait public function provideReportsDateIntervals(): Generator { - $prefix = Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY . ': '; + $prefix = Helper::REPORT_PERIOD_TYPE_DAY . ': '; yield $prefix . 'no from/to' => [ 0, '', '', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'no from' => [ - 'No date part in \'\' found.', + 0, '', self::$dateFirstDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; + $date = Carbon::parse(self::$dateFirstDay); + $now = Carbon::now(); + $diff = $date->diffInDays($now); + yield $prefix . 'no to' => [ - 'No date part in \'\' found.', + $diff + 1, // +1 because we include the first day self::$dateFirstDay, '', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'same day' => [ 1, self::$dateFirstDay, self::$dateFirstDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'same and next day' => [ 2, self::$dateFirstDay, self::$dateNextDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'same and previous day' => [ 0, self::$dateNextDay, self::$dateFirstDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'year 2025' => [ 365, self::$dateFirstDay, self::$dateLastDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'year 2026' => [ 365, '2026-01-01', '2026-12-31', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'year 2027' => [ 365, '2027-01-01', '2027-12-31', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; yield $prefix . 'year 2028' => [ 366, '2028-01-01', '2028-12-31', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_DAY, + Helper::REPORT_PERIOD_TYPE_DAY, ]; - $prefix = Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH . ': '; + $prefix = Helper::REPORT_PERIOD_TYPE_MONTH . ': '; yield $prefix . 'year 2025 full' => [ 12, self::$dateFirstDay, self::$dateLastDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH, + Helper::REPORT_PERIOD_TYPE_MONTH, ]; yield $prefix . 'year 2025, half january' => [ 12, '2025-01-15', self::$dateLastDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH, + Helper::REPORT_PERIOD_TYPE_MONTH, ]; yield $prefix . 'year 2025, half december' => [ 12, self::$dateFirstDay, '2025-12-15', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_MONTH, + Helper::REPORT_PERIOD_TYPE_MONTH, ]; - $prefix = Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR . ': '; + $prefix = Helper::REPORT_PERIOD_TYPE_YEAR . ': '; yield $prefix . 'same year' => [ 1, self::$dateFirstDay, self::$dateLastDay, - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR, + Helper::REPORT_PERIOD_TYPE_YEAR, ]; yield $prefix . 'year 2025 and next' => [ 2, '2025-01-15', '2026-12-31', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR, + Helper::REPORT_PERIOD_TYPE_YEAR, ]; yield $prefix . 'year 2025, half december 2026' => [ 2, self::$dateFirstDay, '2026-12-15', - Mage_Reports_Helper_Data::REPORT_PERIOD_TYPE_YEAR, + Helper::REPORT_PERIOD_TYPE_YEAR, ]; } } diff --git a/tests/unit/Varien/ObjectTest.php b/tests/unit/Varien/ObjectTest.php index b16be5c6bc4..5b1e7f76438 100644 --- a/tests/unit/Varien/ObjectTest.php +++ b/tests/unit/Varien/ObjectTest.php @@ -238,7 +238,7 @@ public function testGetSetUnsData(): void static::assertTrue($this->subject->isEmpty()); try { - /** @phpstan-ignore-next-line */ + // @phpstan-ignore-next-line $this->subject->notData(); static::fail('Invalid __call'); } catch (Varien_Exception $exception) {