From 1da665e431359f35058b2c210d1b95c86a14613b Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Tue, 5 Apr 2016 16:53:47 +0300 Subject: [PATCH 01/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Framework/Stdlib/DateTime/Filter/Date.php | 43 +------------------ 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 43c05e99084b5..8d0f12f02a7e2 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -7,43 +7,8 @@ */ namespace Magento\Framework\Stdlib\DateTime\Filter; -use Magento\Framework\Stdlib\DateTime\TimezoneInterface; - class Date implements \Zend_Filter_Interface { - /** - * Filter that converts localized input into normalized format - * - * @var \Zend_Filter_LocalizedToNormalized - */ - protected $_localToNormalFilter; - - /** - * Filter that converts normalized input into internal format - * - * @var \Zend_Filter_NormalizedToLocalized - */ - protected $_normalToLocalFilter; - - /** - * @var TimezoneInterface - */ - protected $_localeDate; - - /** - * @param TimezoneInterface $localeDate - */ - public function __construct(TimezoneInterface $localeDate) - { - $this->_localeDate = $localeDate; - $this->_localToNormalFilter = new \Zend_Filter_LocalizedToNormalized( - ['date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)] - ); - $this->_normalToLocalFilter = new \Zend_Filter_NormalizedToLocalized( - ['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT] - ); - } - /** * Convert date from localized to internal format * @@ -52,11 +17,7 @@ public function __construct(TimezoneInterface $localeDate) */ public function filter($value) { - $value = $this->_normalToLocalFilter->filter($this->_localToNormalFilter->filter($value)); - - /** - * @todo MAGETWO-51391 - */ - return str_replace("\xc2\xa0", '', $value); + $value = new \DateTime($value, new \DateTimeZone('UTC')); + return $value->format('Y-m-d H:i:s'); } } From bbe26f83c9f0b0aa48639f902c63f2c092d56807 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Tue, 5 Apr 2016 19:33:44 +0300 Subject: [PATCH 02/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Product/Initialization/Helper.php | 6 +-- .../Controller/Adminhtml/Product/Validate.php | 6 +-- .../Product/Initialization/HelperTest.php | 2 +- .../Framework/Stdlib/DateTime/Filter/Date.php | 46 ++++++++++++++++++- .../Stdlib/DateTime/Filter/DateTime.php | 15 ++++++ 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index b399d2a46bf95..f79dbee81ece3 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -39,7 +39,7 @@ class Helper protected $jsHelper; /** - * @var \Magento\Framework\Stdlib\DateTime\Filter\Date + * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime */ protected $dateFilter; @@ -75,7 +75,7 @@ class Helper * @param StockDataFilter $stockFilter * @param ProductLinks $productLinks * @param \Magento\Backend\Helper\Js $jsHelper - * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter + * @param \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter */ public function __construct( \Magento\Framework\App\RequestInterface $request, @@ -83,7 +83,7 @@ public function __construct( StockDataFilter $stockFilter, \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks, \Magento\Backend\Helper\Js $jsHelper, - \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter + \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter ) { $this->request = $request; $this->storeManager = $storeManager; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php index 2845e900f93d8..b7ce0e22499e6 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php @@ -17,7 +17,7 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product { /** - * @var \Magento\Framework\Stdlib\DateTime\Filter\Date + * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime */ protected $_dateFilter; @@ -42,7 +42,7 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product /** * @param Action\Context $context * @param Builder $productBuilder - * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter + * @param \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter * @param \Magento\Catalog\Model\Product\Validator $productValidator * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory @@ -51,7 +51,7 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product public function __construct( \Magento\Backend\App\Action\Context $context, Product\Builder $productBuilder, - \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, + \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter, \Magento\Catalog\Model\Product\Validator $productValidator, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory, diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php index 6755f5abda7d4..608440c10f9cc 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -15,7 +15,7 @@ use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Api\Data\WebsiteInterface; use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\Stdlib\DateTime\Filter\Date as DateFilter; +use Magento\Framework\Stdlib\DateTime\Filter\DateTime as DateFilter; use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory; use Magento\Catalog\Api\Data\ProductCustomOptionInterface; use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks; diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 8d0f12f02a7e2..ca533c395235c 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -7,17 +7,61 @@ */ namespace Magento\Framework\Stdlib\DateTime\Filter; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; + class Date implements \Zend_Filter_Interface { + /** + * Filter that converts localized input into normalized format + * + * @var \Zend_Filter_LocalizedToNormalized + * + * @deprecated + */ + protected $_localToNormalFilter; + + /** + * Filter that converts normalized input into internal format + * + * @var \Zend_Filter_NormalizedToLocalized + * + * @deprecated + */ + protected $_normalToLocalFilter; + + /** + * @var TimezoneInterface + * + * @deprecated + */ + protected $_localeDate; + + /** + * @param TimezoneInterface $localeDate + * + * @deprecated + */ + public function __construct(TimezoneInterface $localeDate) + { + $this->_localeDate = $localeDate; + $this->_localToNormalFilter = new \Zend_Filter_LocalizedToNormalized( + ['date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)] + ); + $this->_normalToLocalFilter = new \Zend_Filter_NormalizedToLocalized( + ['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT] + ); + } + /** * Convert date from localized to internal format * * @param string $value * @return string */ + public function filter($value) { $value = new \DateTime($value, new \DateTimeZone('UTC')); - return $value->format('Y-m-d H:i:s'); + return $value->format('Y-m-d'); } } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index cf2982be04aee..a51b3eb8001da 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -11,6 +11,8 @@ class DateTime extends Date { /** * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate + * + * @deprecated */ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate) { @@ -26,4 +28,17 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface ['date_format' => \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT] ); } + + /** + * Convert date from localized to internal format + * + * @param string $value + * @return string + */ + + public function filter($value) + { + $value = new \DateTime($value, new \DateTimeZone('UTC')); + return $value->format('Y-m-d H:i:s'); + } } From 54d002cb07db7d914584566840d3554323f1d52e Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Wed, 6 Apr 2016 15:27:26 +0300 Subject: [PATCH 03/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Product/Initialization/Helper.php | 29 ++++++++++++++++--- .../Controller/Adminhtml/Product/Validate.php | 27 +++++++++++++++-- .../Product/Initialization/HelperTest.php | 2 +- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index f79dbee81ece3..37755d320929a 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -39,7 +39,9 @@ class Helper protected $jsHelper; /** - * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime + * @var \Magento\Framework\Stdlib\DateTime\Filter\Date + * + * @deprecated */ protected $dateFilter; @@ -68,6 +70,11 @@ class Helper */ private $linkResolver; + /** + * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime + */ + private $dateTimeFilter; + /** * Helper constructor. * @param \Magento\Framework\App\RequestInterface $request @@ -75,7 +82,7 @@ class Helper * @param StockDataFilter $stockFilter * @param ProductLinks $productLinks * @param \Magento\Backend\Helper\Js $jsHelper - * @param \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter + * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter */ public function __construct( \Magento\Framework\App\RequestInterface $request, @@ -83,7 +90,7 @@ public function __construct( StockDataFilter $stockFilter, \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks, \Magento\Backend\Helper\Js $jsHelper, - \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter + \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter ) { $this->request = $request; $this->storeManager = $storeManager; @@ -142,7 +149,7 @@ public function initialize(\Magento\Catalog\Model\Product $product) foreach ($attributes as $attrKey => $attribute) { if ($attribute->getBackend()->getType() == 'datetime') { if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') { - $dateFieldFilters[$attrKey] = $this->dateFilter; + $dateFieldFilters[$attrKey] = $this->getDateTimeFilter(); } } } @@ -340,4 +347,18 @@ private function getLinkResolver() } return $this->linkResolver; } + + /** + * @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime + * + * @deprecated + */ + private function getDateTimeFilter() + { + if ($this->dateTimeFilter === null) { + $this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class); + } + return $this->dateTimeFilter; + } } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php index b7ce0e22499e6..74d32acfffbe9 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php @@ -18,6 +18,8 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product { /** * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime + * + * @deprecated */ protected $_dateFilter; @@ -39,10 +41,15 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product /** @var \Magento\Catalog\Model\ProductFactory */ protected $productFactory; + /** + * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime + */ + private $dateTimeFilter; + /** * @param Action\Context $context * @param Builder $productBuilder - * @param \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter + * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter * @param \Magento\Catalog\Model\Product\Validator $productValidator * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory @@ -51,7 +58,7 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product public function __construct( \Magento\Backend\App\Action\Context $context, Product\Builder $productBuilder, - \Magento\Framework\Stdlib\DateTime\Filter\DateTime $dateFilter, + \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, \Magento\Catalog\Model\Product\Validator $productValidator, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory, @@ -108,7 +115,7 @@ public function execute() foreach ($attributes as $attrKey => $attribute) { if ($attribute->getBackend()->getType() == 'datetime') { if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') { - $dateFieldFilters[$attrKey] = $this->_dateFilter; + $dateFieldFilters[$attrKey] = $this->getDateTimeFilter(); } } } @@ -140,4 +147,18 @@ public function execute() return $this->resultJsonFactory->create()->setData($response); } + + /** + * @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime + * + * @deprecated + */ + private function getDateTimeFilter() + { + if ($this->dateTimeFilter === null) { + $this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class); + } + return $this->dateTimeFilter; + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php index 608440c10f9cc..6755f5abda7d4 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -15,7 +15,7 @@ use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Api\Data\WebsiteInterface; use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\Stdlib\DateTime\Filter\DateTime as DateFilter; +use Magento\Framework\Stdlib\DateTime\Filter\Date as DateFilter; use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory; use Magento\Catalog\Api\Data\ProductCustomOptionInterface; use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks; From e6e866b4454d6402699b985fb78e3c554e8736ef Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Wed, 6 Apr 2016 15:30:06 +0300 Subject: [PATCH 04/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Magento/Catalog/Controller/Adminhtml/Product/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php index 74d32acfffbe9..01bfe3a81de5d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php @@ -17,7 +17,7 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product { /** - * @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime + * @var \Magento\Framework\Stdlib\DateTime\Filter\Date * * @deprecated */ From c0833a7387d679c4939c346fb0a44ba9786589be Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Wed, 6 Apr 2016 16:02:05 +0300 Subject: [PATCH 05/12] MAGETWO-51407: Cannot save product after update for it is applied --- lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index ca533c395235c..8eb748fea7526 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -58,7 +58,6 @@ public function __construct(TimezoneInterface $localeDate) * @param string $value * @return string */ - public function filter($value) { $value = new \DateTime($value, new \DateTimeZone('UTC')); From ace9a32f7dc975bc68cf8675f9181892853a7a32 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Wed, 6 Apr 2016 16:50:11 +0300 Subject: [PATCH 06/12] MAGETWO-51407: Cannot save product after update for it is applied --- lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php | 2 +- .../Magento/Framework/Stdlib/DateTime/Filter/DateTime.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 8eb748fea7526..8c7ee3edf47bc 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -60,7 +60,7 @@ public function __construct(TimezoneInterface $localeDate) */ public function filter($value) { - $value = new \DateTime($value, new \DateTimeZone('UTC')); + $value = new \DateTime($value); return $value->format('Y-m-d'); } } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index a51b3eb8001da..e17a6249a7b64 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -38,7 +38,7 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface public function filter($value) { - $value = new \DateTime($value, new \DateTimeZone('UTC')); + $value = new \DateTime($value); return $value->format('Y-m-d H:i:s'); } } From 1b5b40484507529ff744b4682fd5346757a6ab04 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Wed, 6 Apr 2016 16:52:57 +0300 Subject: [PATCH 07/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Magento/Framework/Stdlib/DateTime/Filter/DateTime.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index e17a6249a7b64..820d6e992ddd1 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -35,7 +35,6 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface * @param string $value * @return string */ - public function filter($value) { $value = new \DateTime($value); From 2e86f3a8609384cb96534469d0ea44701074258c Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Wed, 6 Apr 2016 17:44:27 +0300 Subject: [PATCH 08/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php | 3 ++- .../Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php index f7d88d270a985..aba674c5278cc 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Stdlib\Test\Unit\DateTime\Filter; use \Magento\Framework\Stdlib\DateTime\Filter\Date; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class DateTest extends \PHPUnit_Framework_TestCase { @@ -23,6 +24,6 @@ public function testFilter() ); $model = new Date($localeMock); // Check that date is converted to 'yyyy-MM-dd' format - $this->assertEquals('2241-12-31', $model->filter('12-31-2241')); + $this->assertEquals('2241-12-31', $model->filter('12/31/2241')); } } diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php index ea441856348aa..86b481e884926 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php @@ -23,6 +23,6 @@ public function testFilter() ); $model = new DateTime($localeMock); // Check that datetime is converted to 'yyyy-MM-dd HH:mm:ss' format - $this->assertEquals('2241-12-31 23:59:53', $model->filter('23:59:53 12-31-2241')); + $this->assertEquals('2241-12-31 23:59:53', $model->filter('23:59:53 12/31/2241')); } } From 8c8f58dcd6f2c5109a1f2055ee562d7b1605ee25 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Thu, 7 Apr 2016 12:49:09 +0300 Subject: [PATCH 09/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Framework/Stdlib/DateTime/Filter/Date.php | 14 ++++- .../Stdlib/DateTime/Filter/DateTime.php | 12 +++- .../Test/Unit/DateTime/Filter/DateTest.php | 58 +++++++++++++++++-- .../Unit/DateTime/Filter/DateTimeTest.php | 58 ++++++++++++++++++- 4 files changed, 130 insertions(+), 12 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 8c7ee3edf47bc..955cdb9cb484d 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -8,6 +8,7 @@ namespace Magento\Framework\Stdlib\DateTime\Filter; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use Magento\Framework\Exception\LocalizedException; class Date implements \Zend_Filter_Interface { @@ -54,13 +55,20 @@ public function __construct(TimezoneInterface $localeDate) /** * Convert date from localized to internal format - * + * * @param string $value * @return string + * @throws LocalizedException */ public function filter($value) { - $value = new \DateTime($value); - return $value->format('Y-m-d'); + try { + $value = new \DateTime($value); + return $value->format('Y-m-d'); + } catch (\Exception $e) { + throw new LocalizedException( + __('Invalid input date format') + ); + } } } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index 820d6e992ddd1..4766173652e46 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -6,6 +6,7 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\Stdlib\DateTime\Filter; +use Magento\Framework\Exception\LocalizedException; class DateTime extends Date { @@ -34,10 +35,17 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface * * @param string $value * @return string + * @throws LocalizedException */ public function filter($value) { - $value = new \DateTime($value); - return $value->format('Y-m-d H:i:s'); + try { + $value = new \DateTime($value); + return $value->format('Y-m-d H:i:s'); + } catch (\Exception $e) { + throw new LocalizedException( + __('Invalid input date format') + ); + } } } diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php index aba674c5278cc..057f2c4260d26 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php @@ -6,11 +6,16 @@ namespace Magento\Framework\Stdlib\Test\Unit\DateTime\Filter; use \Magento\Framework\Stdlib\DateTime\Filter\Date; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class DateTest extends \PHPUnit_Framework_TestCase { - public function testFilter() + /** + * @param string $inputData + * @param string $expectedDate + * + * @dataProvider dateFilterDataProvider + */ + public function testFilter($inputData, $expectedDate) { $localeMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); $localeMock->expects( @@ -23,7 +28,52 @@ public function testFilter() $this->returnValue('MM-dd-yyyy') ); $model = new Date($localeMock); - // Check that date is converted to 'yyyy-MM-dd' format - $this->assertEquals('2241-12-31', $model->filter('12/31/2241')); + + $this->assertEquals($expectedDate, $model->filter($inputData)); + } + + /** + * @return array + */ + public function dateFilterDataProvider() + { + return [ + ['2000-01-01', '2000-01-01'], + ['2014-03-30T02:30:00', '2014-03-30'], + ['12/31/2000', '2000-12-31'] + ]; + } + + /** + * @dataProvider dateFilterWithExceptionDataProvider + */ + public function testFilterWithException($inputData) + { + $this->setExpectedException('\Magento\Framework\Exception\LocalizedException'); + + $localeMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); + $localeMock->expects( + $this->once() + )->method( + 'getDateFormat' + )->with( + \IntlDateFormatter::SHORT + )->will( + $this->returnValue('MM-dd-yyyy') + ); + $model = new Date($localeMock); + + $model->filter($inputData); + } + + /** + * @return array + */ + public function dateFilterWithExceptionDataProvider() + { + return [ + ['12-31-2000'], + ['22/2000-01'], + ]; } } diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php index 86b481e884926..aedc21ef77104 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php @@ -9,7 +9,13 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase { - public function testFilter() + /** + * @param string $inputData + * @param string $expectedDate + * + * @dataProvider dateTimeFilterDataProvider + */ + public function testFilter($inputData, $expectedDate) { $localeMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); $localeMock->expects( @@ -22,7 +28,53 @@ public function testFilter() $this->returnValue('HH:mm:ss MM-dd-yyyy') ); $model = new DateTime($localeMock); - // Check that datetime is converted to 'yyyy-MM-dd HH:mm:ss' format - $this->assertEquals('2241-12-31 23:59:53', $model->filter('23:59:53 12/31/2241')); + + $this->assertEquals($expectedDate, $model->filter($inputData)); + } + + /** + * @return array + */ + public function dateTimeFilterDataProvider() + { + return [ + ['2000-01-01 02:30:00', '2000-01-01 02:30:00'], + ['2014-03-30T02:30:00', '2014-03-30 02:30:00'], + ['12/31/2000 02:30:00', '2000-12-31 02:30:00'], + ['02:30:00 12/31/2000', '2000-12-31 02:30:00'], + ]; + } + + /** + * @dataProvider dateTimeFilterWithExceptionDataProvider + */ + public function testFilterWithException($inputData) + { + $this->setExpectedException('\Magento\Framework\Exception\LocalizedException'); + + $localeMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); + $localeMock->expects( + $this->once() + )->method( + 'getDateFormat' + )->with( + \IntlDateFormatter::SHORT + )->will( + $this->returnValue('MM-dd-yyyy') + ); + $model = new DateTime($localeMock); + + $model->filter($inputData); + } + + /** + * @return array + */ + public function dateTimeFilterWithExceptionDataProvider() + { + return [ + ['12-31-2000 22:22:22'], + ['22/2000-01 22:22:22'], + ]; } } From c301858b1242bf63a7fd6e658f3fc5ce488941ac Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Thu, 7 Apr 2016 14:55:30 +0300 Subject: [PATCH 10/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Magento/Framework/Stdlib/DateTime/Filter/Date.php | 3 ++- .../Magento/Framework/Stdlib/DateTime/Filter/DateTime.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 955cdb9cb484d..86bb7602162d8 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -9,6 +9,7 @@ use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; class Date implements \Zend_Filter_Interface { @@ -67,7 +68,7 @@ public function filter($value) return $value->format('Y-m-d'); } catch (\Exception $e) { throw new LocalizedException( - __('Invalid input date format') + new Phrase('Invalid input date format') ); } } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index 4766173652e46..a9078dbf3e60e 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -6,7 +6,9 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\Stdlib\DateTime\Filter; + use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; class DateTime extends Date { @@ -44,7 +46,7 @@ public function filter($value) return $value->format('Y-m-d H:i:s'); } catch (\Exception $e) { throw new LocalizedException( - __('Invalid input date format') + new Phrase('Invalid input date format') ); } } From 3e9ec7c76a69ceb416e72bf4830f55029cffa78a Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Thu, 7 Apr 2016 18:20:45 +0300 Subject: [PATCH 11/12] MAGETWO-45318: New Accounts Report does not work correctly --- .../Model/ResourceModel/Report/Collection.php | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php index 7aea7ed1ab1a1..3c34476807ec7 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php @@ -176,8 +176,8 @@ protected function _getDayInterval(\DateTime $dateStart) \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE ), - 'start' => $dateStart->format('Y-m-d 00:00:00'), - 'end' => $dateStart->format('Y-m-d 23:59:59'), + 'start' => $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 00:00:00')), + 'end' => $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 23:59:59')), ]; return $interval; } @@ -195,21 +195,25 @@ protected function _getMonthInterval(\DateTime $dateStart, \DateTime $dateEnd, $ $interval = []; $interval['period'] = $dateStart->format('m/Y'); if ($firstInterval) { - $interval['start'] = $dateStart->format('Y-m-d 00:00:00'); + $interval['start'] = $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 00:00:00')); } else { - $interval['start'] = $dateStart->format('Y-m-01 00:00:00'); + $interval['start'] = $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-01 00:00:00')); } if ($dateStart->diff($dateEnd)->m == 0) { - $interval['end'] = $dateStart->setDate( - $dateStart->format('Y'), - $dateStart->format('m'), - $dateEnd->format('d') - )->format( - 'Y-m-d 23:59:59' + $interval['end'] = $this->_localeDate->convertConfigTimeToUtc( + $dateStart->setDate( + $dateStart->format('Y'), + $dateStart->format('m'), + $dateEnd->format('d') + )->format( + 'Y-m-d 23:59:59' + ) ); } else { - $interval['end'] = $dateStart->format('Y-m-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59'); + $interval['end'] = $this->_localeDate->convertConfigTimeToUtc( + $dateStart->format('Y-m-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59') + ); } $dateStart->modify('+1 month'); @@ -234,13 +238,15 @@ protected function _getYearInterval(\DateTime $dateStart, \DateTime $dateEnd, $f $interval = []; $interval['period'] = $dateStart->format('Y'); $interval['start'] = $firstInterval - ? $dateStart->format('Y-m-d 00:00:00') - : $dateStart->format('Y-01-01 00:00:00'); + ? $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 00:00:00')) + : $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-01-01 00:00:00')); $interval['end'] = $dateStart->diff($dateEnd)->y == 0 - ? $dateStart->setDate($dateStart->format('Y'), $dateEnd->format('m'), $dateEnd->format('d')) - ->format('Y-m-d 23:59:59') - : $dateStart->format('Y-12-31 23:59:59'); + ? $this->_localeDate->convertConfigTimeToUtc( + $dateStart->setDate($dateStart->format('Y'), $dateEnd->format('m'), $dateEnd->format('d')) + ->format('Y-m-d 23:59:59') + ) + : $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-12-31 23:59:59')); $dateStart->modify('+1 year'); if ($dateStart->diff($dateEnd)->y == 0) { @@ -355,7 +361,7 @@ public function getReports() } return $this->_reports; } - + /** * Load data * From 691b812ec95fabf75b85497720d5d147bbb4dddc Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Fri, 8 Apr 2016 16:42:59 +0300 Subject: [PATCH 12/12] MAGETWO-51407: Cannot save product after update for it is applied --- .../Magento/Framework/Stdlib/DateTime/Filter/Date.php | 4 +--- .../Magento/Framework/Stdlib/DateTime/Filter/DateTime.php | 4 +--- .../Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php | 2 +- .../Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 86bb7602162d8..8f30a8149c14d 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -67,9 +67,7 @@ public function filter($value) $value = new \DateTime($value); return $value->format('Y-m-d'); } catch (\Exception $e) { - throw new LocalizedException( - new Phrase('Invalid input date format') - ); + throw new \Exception('Invalid input date format'); } } } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index a9078dbf3e60e..8838d915619f5 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -45,9 +45,7 @@ public function filter($value) $value = new \DateTime($value); return $value->format('Y-m-d H:i:s'); } catch (\Exception $e) { - throw new LocalizedException( - new Phrase('Invalid input date format') - ); + throw new \Exception('Invalid input datetime format'); } } } diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php index 057f2c4260d26..08075da4d2d81 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php @@ -49,7 +49,7 @@ public function dateFilterDataProvider() */ public function testFilterWithException($inputData) { - $this->setExpectedException('\Magento\Framework\Exception\LocalizedException'); + $this->setExpectedException('\Exception'); $localeMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); $localeMock->expects( diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php index aedc21ef77104..5ca6f9c52ee78 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php @@ -50,7 +50,7 @@ public function dateTimeFilterDataProvider() */ public function testFilterWithException($inputData) { - $this->setExpectedException('\Magento\Framework\Exception\LocalizedException'); + $this->setExpectedException('\Exception'); $localeMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); $localeMock->expects(