From f03596e6dab3c252b8f3d92aac765037f8722b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez?= Date: Thu, 12 Oct 2017 19:56:07 +0200 Subject: [PATCH 1/3] Support to manage multiple instances in the same crontab, based on installation directory --- app/code/Magento/Cron/etc/di.xml | 2 +- .../Framework/Crontab/CrontabManager.php | 51 ++++++++++++++----- .../Crontab/Test/Unit/CrontabManagerTest.php | 43 ++++++++-------- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index d355debfa703b..a37f3760b70a5 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -43,7 +43,7 @@ - + Magento\Framework\App\Shell diff --git a/lib/internal/Magento/Framework/Crontab/CrontabManager.php b/lib/internal/Magento/Framework/Crontab/CrontabManager.php index cd0dcdaeaa6a1..1f079b766c22e 100644 --- a/lib/internal/Magento/Framework/Crontab/CrontabManager.php +++ b/lib/internal/Magento/Framework/Crontab/CrontabManager.php @@ -5,11 +5,11 @@ */ namespace Magento\Framework\Crontab; -use Magento\Framework\ShellInterface; -use Magento\Framework\Phrase; +use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem; -use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Phrase; +use Magento\Framework\ShellInterface; /** * Manager works with cron tasks @@ -38,6 +38,30 @@ public function __construct( $this->filesystem = $filesystem; } + /** + * @return string + */ + private function getTasksBlockStart() + { + $tasksBlockStart = self::TASKS_BLOCK_START; + if (defined('BP')) { + $tasksBlockStart .= ' ' . md5(BP); + } + return $tasksBlockStart; + } + + /** + * @return string + */ + private function getTasksBlockEnd() + { + $tasksBlockEnd = self::TASKS_BLOCK_END; + if (defined('BP')) { + $tasksBlockEnd .= ' ' . md5(BP); + } + return $tasksBlockEnd; + } + /** * {@inheritdoc} */ @@ -45,7 +69,7 @@ public function getTasks() { $this->checkSupportedOs(); $content = $this->getCrontabContent(); - $pattern = '!(' . self::TASKS_BLOCK_START . ')(.*?)(' . self::TASKS_BLOCK_END . ')!s'; + $pattern = '!(' . $this->getTasksBlockStart() . ')(.*?)(' . $this->getTasksBlockEnd() . ')!s'; if (preg_match($pattern, $content, $matches)) { $tasks = trim($matches[2], PHP_EOL); @@ -61,14 +85,14 @@ public function getTasks() */ public function saveTasks(array $tasks) { - $this->checkSupportedOs(); - $baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath(); - $logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); - if (!$tasks) { throw new LocalizedException(new Phrase('List of tasks is empty')); } + $this->checkSupportedOs(); + $baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath(); + $logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + foreach ($tasks as $key => $task) { if (empty($task['expression'])) { $tasks[$key]['expression'] = '* * * * *'; @@ -114,11 +138,11 @@ public function removeTasks() private function generateSection($content, $tasks = []) { if ($tasks) { - $content .= self::TASKS_BLOCK_START . PHP_EOL; + $content .= $this->getTasksBlockStart() . PHP_EOL; foreach ($tasks as $task) { - $content .= $task['expression'] . ' ' . PHP_BINARY . ' '. $task['command'] . PHP_EOL; + $content .= $task['expression'] . ' ' . PHP_BINARY . ' ' . $task['command'] . PHP_EOL; } - $content .= self::TASKS_BLOCK_END . PHP_EOL; + $content .= $this->getTasksBlockEnd() . PHP_EOL; } return $content; @@ -133,7 +157,8 @@ private function generateSection($content, $tasks = []) private function cleanMagentoSection($content) { $content = preg_replace( - '!' . preg_quote(self::TASKS_BLOCK_START) . '.*?' . preg_quote(self::TASKS_BLOCK_END . PHP_EOL) . '!s', + '!' . preg_quote($this->getTasksBlockStart()) . '.*?' + . preg_quote($this->getTasksBlockEnd() . PHP_EOL) . '!s', '', $content ); @@ -192,7 +217,7 @@ private function checkSupportedOs() { if (stripos(PHP_OS, 'WIN') === 0) { throw new LocalizedException( - new Phrase('Your operation system is not supported to work with this command') + new Phrase('Your operating system is not supported to work with this command') ); } } diff --git a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php index e4088b1e4befc..3327d10f2041b 100644 --- a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php +++ b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php @@ -87,17 +87,17 @@ public function getTasksDataProvider() return [ [ 'content' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, 'tasks' => ['* * * * * /bin/php /var/www/magento/bin/magento cron:run'], ], [ 'content' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento setup:cron:run' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, 'tasks' => [ '* * * * * /bin/php /var/www/magento/bin/magento cron:run', '* * * * * /bin/php /var/www/magento/bin/magento setup:cron:run', @@ -165,17 +165,17 @@ public function removeTasksDataProvider() return [ [ 'contentBefore' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, 'contentAfter' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL ], [ 'contentBefore' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento setup:cron:run' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, 'contentAfter' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL ], [ @@ -198,14 +198,13 @@ public function testSaveTasksWithEmptyTasksList() { $baseDirMock = $this->getMockBuilder(ReadInterface::class) ->getMockForAbstractClass(); - $baseDirMock->expects($this->once()) + $baseDirMock->expects($this->never()) ->method('getAbsolutePath') ->willReturn('/var/www/magento2/'); $logDirMock = $this->getMockBuilder(ReadInterface::class) ->getMockForAbstractClass(); - $logDirMock->expects($this->once()) - ->method('getAbsolutePath') - ->willReturn('/var/www/magento2/var/log/'); + $logDirMock->expects($this->never()) + ->method('getAbsolutePath'); $this->filesystemMock->expects($this->any()) ->method('getDirectoryRead') @@ -292,9 +291,9 @@ public function testSaveTasks($tasks, $content, $contentToSave) public function saveTasksDataProvider() { $content = '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * /bin/php /var/www/magento/bin/magento cron:run' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL; + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL; return [ [ @@ -303,9 +302,9 @@ public function saveTasksDataProvider() ], 'content' => $content, 'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * ' . PHP_BINARY . ' run.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, ], [ 'tasks' => [ @@ -313,9 +312,9 @@ public function saveTasksDataProvider() ], 'content' => $content, 'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '1 2 3 4 5 ' . PHP_BINARY . ' run.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, ], [ 'tasks' => [ @@ -323,10 +322,10 @@ public function saveTasksDataProvider() ], 'content' => $content, 'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php >>' . ' /var/www/magento2/var/log/cron.log' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, ], [ 'tasks' => [ @@ -334,10 +333,10 @@ public function saveTasksDataProvider() ], 'content' => $content, 'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php' . ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, ], ]; } From 4aadf36c90d0003a9c184ac9bc15f1311b90dc96 Mon Sep 17 00:00:00 2001 From: Mayank Date: Fri, 13 Oct 2017 15:47:03 +0530 Subject: [PATCH 2/3] Product Repeat Isuue after filter on category listing page.Issue : #11139 --- .../Magento/Catalog/Block/Product/ProductList/Toolbar.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php index c7dd1bfab7947..46080ab5c3330 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -193,7 +193,10 @@ public function setCollection($collection) } if ($this->getCurrentOrder()) { if (($this->getCurrentOrder()) == 'position') { - $this->_collection->addAttributeToSort($this->getCurrentOrder(), $this->getCurrentDirection())->addAttributeToSort('entity_id', $this->getCurrentDirection()); + $this->_collection->addAttributeToSort( + $this->getCurrentOrder(), + $this->getCurrentDirection() + )->addAttributeToSort('entity_id', $this->getCurrentDirection()); } else { $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); } From f59cfe252d2f04fcc7a7e04dea95202d1e8ffc15 Mon Sep 17 00:00:00 2001 From: Oleksii Korshenko Date: Mon, 16 Oct 2017 18:09:03 -0400 Subject: [PATCH 3/3] MAGETWO-81646: PHP Livecodetest testCodeStyle() method does not use whitelist files #11362 --- .../static/testsuite/Magento/Test/Php/LiveCodeTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php index 5058ef402cbd2..e2a550d6751d3 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php @@ -206,10 +206,12 @@ public function testCodeStyle() $reportFile = self::$reportDir . '/phpcs_report.txt'; $codeSniffer = new CodeSniffer('Magento', $reportFile, new Wrapper()); + $result = $codeSniffer->run($whiteList); + $report = file_exists($reportFile) ? file_get_contents($reportFile) : ''; $this->assertEquals( 0, - $result = $codeSniffer->run($whiteList), - "PHP Code Sniffer detected {$result} violation(s): " . PHP_EOL . file_get_contents($reportFile) + $result, + "PHP Code Sniffer detected {$result} violation(s): " . PHP_EOL . $report ); }