diff --git a/app/code/Magento/Bundle/Model/Resource/Indexer/Price.php b/app/code/Magento/Bundle/Model/Resource/Indexer/Price.php index decc168ec2ffff14ec7b2e01ede79d020bf7baf2..e4a7ceb99903b0987bbd38eebc3464895efe4d25 100644 --- a/app/code/Magento/Bundle/Model/Resource/Indexer/Price.php +++ b/app/code/Magento/Bundle/Model/Resource/Indexer/Price.php @@ -529,27 +529,6 @@ class Price extends \Magento\Catalog\Model\Resource\Product\Indexer\Price\Defaul $this->_prepareBundlePriceByType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED, $entityIds); $this->_prepareBundlePriceByType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC, $entityIds); - /** - * Add possibility modify prices from external events - */ - $select = $this->_getWriteAdapter()->select()->join( - ['wd' => $this->_getWebsiteDateTable()], - 'i.website_id = wd.website_id', - [] - ); - $this->_eventManager->dispatch( - 'prepare_catalog_product_price_index_table', - [ - 'index_table' => ['i' => $this->_getBundlePriceTable()], - 'select' => $select, - 'entity_id' => 'i.entity_id', - 'customer_group_id' => 'i.customer_group_id', - 'website_id' => 'i.website_id', - 'website_date' => 'wd.website_date', - 'update_fields' => ['price', 'min_price', 'max_price'] - ] - ); - $this->_calculateBundleOptionPrice(); $this->_applyCustomOption(); diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php index 6d97bd9583af83f82f7dc3a904b13a105d9a000b..b0185bcf1397171d73550b750766a591ba08487b 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php @@ -318,28 +318,6 @@ class DefaultPrice extends \Magento\Catalog\Model\Resource\Product\Indexer\Abstr $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable(), [], false); $write->query($query); - - /** - * Add possibility modify prices from external events - */ - $select = $write->select()->join( - ['wd' => $this->_getWebsiteDateTable()], - 'i.website_id = wd.website_id', - [] - ); - $this->_eventManager->dispatch( - 'prepare_catalog_product_price_index_table', - [ - 'index_table' => ['i' => $this->_getDefaultFinalPriceTable()], - 'select' => $select, - 'entity_id' => 'i.entity_id', - 'customer_group_id' => 'i.customer_group_id', - 'website_id' => 'i.website_id', - 'website_date' => 'wd.website_date', - 'update_fields' => ['price', 'min_price', 'max_price'] - ] - ); - return $this; } diff --git a/app/code/Magento/CatalogRule/Model/Observer.php b/app/code/Magento/CatalogRule/Model/Observer.php index 88f24410e253ea30111561745a82532154f4952f..9d636b0ae60b1c9288526410b048c92e3c5de6d8 100644 --- a/app/code/Magento/CatalogRule/Model/Observer.php +++ b/app/code/Magento/CatalogRule/Model/Observer.php @@ -47,11 +47,6 @@ class Observer */ protected $_customerSession; - /** - * @var Price - */ - protected $_productPrice; - /** * @var \Magento\CatalogRule\Model\Resource\Rule\CollectionFactory */ @@ -86,7 +81,6 @@ class Observer * @param Resource\RuleFactory $resourceRuleFactory * @param Resource\Rule $resourceRule * @param Resource\Rule\CollectionFactory $ruleCollectionFactory - * @param Price $productPrice * @param StoreManagerInterface $storeManager * @param TimezoneInterface $localeDate * @param CustomerModelSession $customerSession @@ -100,7 +94,6 @@ class Observer Resource\RuleFactory $resourceRuleFactory, Resource\Rule $resourceRule, Resource\Rule\CollectionFactory $ruleCollectionFactory, - Rule\Product\Price $productPrice, StoreManagerInterface $storeManager, TimezoneInterface $localeDate, CustomerModelSession $customerSession, @@ -111,7 +104,6 @@ class Observer $this->_resourceRuleFactory = $resourceRuleFactory; $this->_resourceRule = $resourceRule; $this->_ruleCollectionFactory = $ruleCollectionFactory; - $this->_productPrice = $productPrice; $this->_storeManager = $storeManager; $this->_localeDate = $localeDate; $this->_customerSession = $customerSession; @@ -215,36 +207,6 @@ class Observer $this->_rulePrices = []; } - /** - * Calculate minimal final price with catalog rule price - * - * @param EventObserver $observer - * @return $this - */ - public function prepareCatalogProductPriceIndexTable(EventObserver $observer) - { - $select = $observer->getEvent()->getSelect(); - - $indexTable = $observer->getEvent()->getIndexTable(); - $entityId = $observer->getEvent()->getEntityId(); - $customerGroupId = $observer->getEvent()->getCustomerGroupId(); - $websiteId = $observer->getEvent()->getWebsiteId(); - $websiteDate = $observer->getEvent()->getWebsiteDate(); - $updateFields = $observer->getEvent()->getUpdateFields(); - - $this->_productPrice->applyPriceRuleToIndexTable( - $select, - $indexTable, - $entityId, - $customerGroupId, - $websiteId, - $updateFields, - $websiteDate - ); - - return $this; - } - /** * @param EventObserver $observer * @return $this diff --git a/app/code/Magento/CatalogRule/etc/events.xml b/app/code/Magento/CatalogRule/etc/events.xml deleted file mode 100644 index 646d1de75082550ea731b69746dde56286d45953..0000000000000000000000000000000000000000 --- a/app/code/Magento/CatalogRule/etc/events.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0"?> -<!-- -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ ---> -<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd"> - <event name="prepare_catalog_product_price_index_table"> - <observer name="catalogrule" instance="Magento\CatalogRule\Model\Observer" method="prepareCatalogProductPriceIndexTable" /> - </event> -</config> diff --git a/app/code/Magento/Customer/etc/data_source/customer_address.xml b/app/code/Magento/Customer/etc/data_source/customer_address.xml index 3f3cdd4b0e30a273062e46dcf0fd9c770cd3a14f..e3e88b578a12604b97419639750b8317019d0e51 100644 --- a/app/code/Magento/Customer/etc/data_source/customer_address.xml +++ b/app/code/Magento/Customer/etc/data_source/customer_address.xml @@ -49,7 +49,7 @@ </field> <field name="region" source="eav" formElement="input" visible="false"/> - <field name="postcode" source="eav" formElement="post_code_fix" > + <field name="postcode" source="eav" formElement="post_code" > <constraints> <validate name="required-entry"/> </constraints> diff --git a/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..d99f32d515e38db2784169e6f21c5fa0fe4034ed --- /dev/null +++ b/app/code/Magento/Developer/Model/Less/FileGenerator/PublicationDecorator.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\Less\FileGenerator; + +use Magento\Framework\Less\FileGenerator\RelatedGenerator; +use Magento\Framework\View\Asset\LocalInterface; + +/** + * Class PublicationDecorator + * Decorates generator of related assets and publishes them + * + * @package Magento\Developer\Model\Less\FileGenerator + */ +class PublicationDecorator extends RelatedGenerator +{ + /** + * @var \Magento\Framework\App\View\Asset\Publisher + */ + private $publisher; + + /** + * @param \Magento\Framework\Filesystem $filesystem + * @param \Magento\Framework\View\Asset\Repository $assetRepo + * @param \Magento\Framework\Less\File\Temporary $temporaryFile + * @param \Magento\Framework\App\View\Asset\Publisher $publisher + */ + public function __construct( + \Magento\Framework\Filesystem $filesystem, + \Magento\Framework\View\Asset\Repository $assetRepo, + \Magento\Framework\Less\File\Temporary $temporaryFile, + \Magento\Framework\App\View\Asset\Publisher $publisher + ) { + parent::__construct($filesystem, $assetRepo, $temporaryFile); + $this->publisher = $publisher; + } + + /** + * {inheritdoc} + */ + protected function generateRelatedFile($relatedFileId, LocalInterface $asset) + { + $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); + $this->publisher->publish($relatedAsset); + return $relatedAsset; + } +} diff --git a/app/code/Magento/Quote/Model/Quote.php b/app/code/Magento/Quote/Model/Quote.php index ef130e2e6597203b74b35e6066678fedc712ac20..1f9fb10d01a1df5eded433b519aae09a7025e7c5 100644 --- a/app/code/Magento/Quote/Model/Quote.php +++ b/app/code/Magento/Quote/Model/Quote.php @@ -2042,9 +2042,7 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C return $this; } - if (is_string($message)) { - $message = $this->messageFactory->create(\Magento\Framework\Message\MessageInterface::TYPE_ERROR, $message); - } + $message = $this->messageFactory->create(\Magento\Framework\Message\MessageInterface::TYPE_ERROR, $message); $messages[$index] = $message; $this->setData('messages', $messages); diff --git a/app/etc/di.xml b/app/etc/di.xml index a3da2e85a1954b11a9415d002266b285fad6b676..cb45113bb261c8ce90486a5a1d4be251fc658744 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -557,13 +557,6 @@ <argument name="publisher" xsi:type="object">developerPublisher</argument> </arguments> </type> - <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool"> - <arguments> - <argument name="fileGeneratorTypes" xsi:type="array"> - <item name="less" xsi:type="object">Magento\Framework\Less\FileGenerator</item> - </argument> - </arguments> - </type> <virtualType name="developerPublisher" type="Magento\Framework\App\View\Asset\Publisher"> <arguments> <argument name="materializationStrategyFactory" xsi:type="object">developerMaterialization</argument> @@ -577,24 +570,23 @@ </argument> </arguments> </virtualType> - <virtualType name="lessFileGeneratorMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory"> + <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool"> <arguments> - <argument name="strategiesList" xsi:type="array"> - <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item> - <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> + <argument name="fileGeneratorTypes" xsi:type="array"> + <item name="less" xsi:type="object">fileassemblerFileGenerator</item> </argument> </arguments> - </virtualType> - <virtualType name="lessFileGeneratorPublisher" type="Magento\Framework\App\View\Asset\Publisher"> + </type> + <virtualType name="fileassemblerFileGenerator" type="Magento\Framework\Less\FileGenerator"> <arguments> - <argument name="materializationStrategyFactory" xsi:type="object">lessFileGeneratorMaterialization</argument> + <argument name="relatedGenerator" xsi:type="object">fileassemblerRelatedFilesGenerator</argument> </arguments> </virtualType> - <type name="Magento\Framework\Less\FileGenerator"> + <virtualType name="fileassemblerRelatedFilesGenerator" type="Magento\Developer\Model\Less\FileGenerator\PublicationDecorator"> <arguments> - <argument name="publisher" xsi:type="object">lessFileGeneratorPublisher</argument> + <argument name="publisher" xsi:type="object">developerPublisher</argument> </arguments> - </type> + </virtualType> <virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple"> <arguments> <argument name="cache" xsi:type="object">Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped</argument> diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index d01d17f39f1250f965c7acca5ddace4ef3d50f62..21ff60a356b59dbd10c2c7bcc2d9c5cc21c57bd4 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -2149,4 +2149,5 @@ return [ ['loadCollectionAttributes', 'Magento\Eav\Model\Config'], ['_isCacheEnabled', 'Magento\Eav\Model\Config'], ['_createCustomerAttribute', '\Magento\Customer\Model\Customer'], + ['prepareCatalogProductPriceIndexTable', 'Magento\CatalogRule\Model\Observer'], ]; diff --git a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php index fb8529dd7596966ce189816f5276a222fb7bd4fa..0a07540a19c94695f0a9454f0f5f4b3b86c12182 100644 --- a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php +++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php @@ -9,6 +9,7 @@ namespace Magento\Tools\Webdev\App; use Magento\Framework\App; use Magento\Framework\App\State; use Magento\Framework\AppInterface; +use Magento\Framework\Filesystem; use Magento\Tools\Webdev\CliParams; use Magento\Tools\View\Deployer\Log; use Magento\Framework\View\Asset\Source; @@ -18,6 +19,7 @@ use Magento\Framework\ObjectManagerInterface; use Magento\Framework\App\ObjectManager\ConfigLoader; use Magento\Framework\View\Asset\SourceFileGeneratorPool; use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; +use Magento\Framework\App\Filesystem\DirectoryList; /** * Class FileAssembler @@ -60,7 +62,7 @@ class FileAssembler implements AppInterface /** * @var \Magento\Framework\Less\FileGenerator */ - private $sourceFileGeneratorPoll; + private $sourceFileGeneratorPool; /** * @var \Magento\Framework\View\Asset\Source @@ -77,6 +79,11 @@ class FileAssembler implements AppInterface */ private $chainFactory; + /** + * @var Filesystem + */ + private $filesystem; + /** * @param ObjectManagerInterface $objectManager * @param Response $response @@ -88,6 +95,7 @@ class FileAssembler implements AppInterface * @param \Magento\Framework\View\Asset\SourceFileGeneratorPool $sourceFileGeneratorPoll * @param \Magento\Tools\View\Deployer\Log $logger * @param ChainFactoryInterface $chainFactory + * @param Filesystem $filesystem * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -101,7 +109,8 @@ class FileAssembler implements AppInterface Source $assetSource, SourceFileGeneratorPool $sourceFileGeneratorPoll, Log $logger, - ChainFactoryInterface $chainFactory + ChainFactoryInterface $chainFactory, + Filesystem $filesystem ) { $this->response = $response; $this->params = $params; @@ -109,10 +118,11 @@ class FileAssembler implements AppInterface $this->objectManager = $objectManager; $this->configLoader = $configLoader; $this->assetRepo = $assetRepo; - $this->sourceFileGeneratorPoll = $sourceFileGeneratorPoll; + $this->sourceFileGeneratorPool = $sourceFileGeneratorPoll; $this->assetSource = $assetSource; $this->logger = $logger; $this->chainFactory = $chainFactory; + $this->filesystem = $filesystem; } /** @@ -125,7 +135,7 @@ class FileAssembler implements AppInterface $this->state->setAreaCode($this->params->getArea()); $this->objectManager->configure($this->configLoader->load($this->params->getArea())); - $sourceFileGenerator = $this->sourceFileGeneratorPoll->create($this->params->getExt()); + $sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt()); foreach ($this->params->getFiles() as $file) { $file .= '.' . $this->params->getExt(); @@ -152,7 +162,13 @@ class FileAssembler implements AppInterface ] ); - $sourceFileGenerator->generateFileTree($chain); + $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); + + $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); + $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); + $source = $rootDir->getRelativePath($processedCoreFile); + $destination = $asset->getPath(); + $rootDir->copyFile($source, $destination, $targetDir); $this->logger->logMessage("Done"); } diff --git a/dev/tools/Magento/Tools/Webdev/file_assembler.php b/dev/tools/Magento/Tools/Webdev/file_assembler.php index 72ec5b0458fdf12637221079aca0457872a60bb4..669ffa8d535856606b1a86ebbf5d0882aa99f353 100644 --- a/dev/tools/Magento/Tools/Webdev/file_assembler.php +++ b/dev/tools/Magento/Tools/Webdev/file_assembler.php @@ -35,15 +35,15 @@ try { $logger = new Log($params->getVerbose()); } catch (\Zend_Console_Getopt_Exception $e) { - echo $e->getUsageMessage(); - echo 'Please, use quotes(") for wrapping strings.' . "\n"; + echo $e->getMessage() . PHP_EOL; + echo 'Please, use quotes(") for wrapping strings.' . PHP_EOL; exit(1); } $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication( - 'Magento\Tools\WebDev\App\FileAssembler', + 'Magento\Tools\Webdev\App\FileAssembler', ['params' => $params, 'logger' => $logger] ); $bootstrap->run($app); diff --git a/lib/internal/Magento/Framework/Less/Config.php b/lib/internal/Magento/Framework/Less/Config.php new file mode 100644 index 0000000000000000000000000000000000000000..88f6c27e9ee412d67f4c414f5165e449ed42fa14 --- /dev/null +++ b/lib/internal/Magento/Framework/Less/Config.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Less; + +use Magento\Framework\App\Filesystem\DirectoryList; + +class Config +{ + /** + * Temporary directory prefix + */ + const TMP_LESS_DIR = 'less'; + + /** + * Returns relative path to less materialization directory + * + * @return string + */ + public function getLessMaterializationRelativePath() + { + return DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR; + } +} diff --git a/lib/internal/Magento/Framework/Less/File/Temporary.php b/lib/internal/Magento/Framework/Less/File/Temporary.php new file mode 100644 index 0000000000000000000000000000000000000000..8da016ecde585d76b509d3e4f74e3ca9069de16a --- /dev/null +++ b/lib/internal/Magento/Framework/Less/File/Temporary.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Less\File; + +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; +use Magento\Framework\Less\Config; + +class Temporary +{ + /** + * @var Config + */ + private $config; + + /** + * @var Filesystem\Directory\WriteInterface + */ + private $tmpDirectory; + + /** + * @param Filesystem $filesystem + * @param Config $config + */ + public function __construct( + Filesystem $filesystem, + Config $config + ) { + $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + $this->config = $config; + } + + /** + * Write down contents to a temporary file and return its absolute path + * + * @param string $relativePath + * @param string $contents + * @return string + */ + public function createFile($relativePath, $contents) + { + $filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath; + + if (!$this->tmpDirectory->isExist($filePath)) { + $this->tmpDirectory->writeFile($filePath, $contents); + } + return $this->tmpDirectory->getAbsolutePath($filePath); + } +} diff --git a/lib/internal/Magento/Framework/Less/FileGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator.php index f45d462e7eaaeeff23b95633c658bf40d526f650..ab7141d29dcc196d32324778d6e8df1b114fc747 100644 --- a/lib/internal/Magento/Framework/Less/FileGenerator.php +++ b/lib/internal/Magento/Framework/Less/FileGenerator.php @@ -7,17 +7,16 @@ namespace Magento\Framework\Less; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\View\Asset\LocalInterface; use Magento\Framework\View\Asset\PreProcessor\Chain; use Magento\Framework\View\Asset\SourceFileGeneratorInterface; +/** + * Class FileGenerator + * @package Magento\Framework\Less + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class FileGenerator implements SourceFileGeneratorInterface { - /** - * Temporary directory prefix - */ - const TMP_LESS_DIR = 'less'; - /** * Max execution (locking) time for generation process (in seconds) */ @@ -28,11 +27,6 @@ class FileGenerator implements SourceFileGeneratorInterface */ const LOCK_FILE = 'less.lock'; - /** - * @var string - */ - protected $lessDirectory; - /** * @var \Magento\Framework\Filesystem\Directory\WriteInterface */ @@ -59,17 +53,29 @@ class FileGenerator implements SourceFileGeneratorInterface private $importProcessor; /** - * @var \Magento\Framework\App\View\Asset\Publisher + * @var FileGenerator\RelatedGenerator + */ + private $relatedGenerator; + + /** + * @var Config */ - private $publisher; + private $config; + + /** + * @var File\Temporary + */ + private $temporaryFile; /** * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor - * @param \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor + * @param PreProcessor\Instruction\MagentoImport $magentoImportProcessor + * @param PreProcessor\Instruction\Import $importProcessor * @param \Magento\Framework\View\Asset\Source $assetSource - * @param \Magento\Framework\App\View\Asset\Publisher $publisher + * @param FileGenerator\RelatedGenerator $relatedGenerator + * @param Config $config + * @param File\Temporary $temporaryFile */ public function __construct( \Magento\Framework\Filesystem $filesystem, @@ -77,17 +83,19 @@ class FileGenerator implements SourceFileGeneratorInterface \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor, \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor, \Magento\Framework\View\Asset\Source $assetSource, - \Magento\Framework\App\View\Asset\Publisher $publisher + \Magento\Framework\Less\FileGenerator\RelatedGenerator $relatedGenerator, + Config $config, + File\Temporary $temporaryFile ) { $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); - $this->pubDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB); - $this->lessDirectory = DirectoryList::TMP_MATERIALIZATION_DIR . '/' . self::TMP_LESS_DIR; $this->assetRepo = $assetRepo; $this->assetSource = $assetSource; $this->magentoImportProcessor = $magentoImportProcessor; $this->importProcessor = $importProcessor; - $this->publisher = $publisher; + $this->relatedGenerator = $relatedGenerator; + $this->config = $config; + $this->temporaryFile = $temporaryFile; } /** @@ -109,16 +117,14 @@ class FileGenerator implements SourceFileGeneratorInterface while ($this->isProcessLocked()) { sleep(1); } - $lockFilePath = $this->lessDirectory . '/' . self::LOCK_FILE; + $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE; $this->tmpDirectory->writeFile($lockFilePath, time()); $this->magentoImportProcessor->process($chain); $this->importProcessor->process($chain); - $this->generateRelatedFiles(); + $this->relatedGenerator->generate($this->importProcessor); $lessRelativePath = preg_replace('#\.css$#', '.less', $chain->getAsset()->getPath()); - $tmpFilePath = $this->createFile($lessRelativePath, $chain->getContent()); - - $this->createFileMain($lessRelativePath, $chain->getContent()); + $tmpFilePath = $this->temporaryFile->createFile($lessRelativePath, $chain->getContent()); $this->tmpDirectory->delete($lockFilePath); return $tmpFilePath; @@ -131,7 +137,7 @@ class FileGenerator implements SourceFileGeneratorInterface */ protected function isProcessLocked() { - $lockFilePath = $this->lessDirectory . '/' . self::LOCK_FILE; + $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE; if ($this->tmpDirectory->isExist($lockFilePath)) { $lockTime = time() - (int)$this->tmpDirectory->readFile($lockFilePath); if ($lockTime >= self::MAX_LOCK_TIME) { @@ -142,69 +148,4 @@ class FileGenerator implements SourceFileGeneratorInterface } return false; } - - /** - * Create all asset files, referenced from already processed ones - * - * @return void - */ - protected function generateRelatedFiles() - { - do { - $relatedFiles = $this->importProcessor->getRelatedFiles(); - $this->importProcessor->resetRelatedFiles(); - foreach ($relatedFiles as $relatedFileInfo) { - list($relatedFileId, $asset) = $relatedFileInfo; - $this->generateRelatedFile($relatedFileId, $asset); - } - } while ($relatedFiles); - } - - /** - * Create file, referenced relatively to an asset - * - * @param string $relatedFileId - * @param LocalInterface $asset - * @return void - */ - protected function generateRelatedFile($relatedFileId, LocalInterface $asset) - { - $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset); - $relatedAsset->getFilePath(); - - $this->createFile($relatedAsset->getPath(), $relatedAsset->getContent()); - $relatedAsset->getSourceFile(); - $this->publisher->publish($relatedAsset); - } - - /** - * Write down contents to a temporary file and return its absolute path - * - * @param string $relativePath - * @param string $contents - * @return string - */ - private function createFile($relativePath, $contents) - { - $filePath = $this->lessDirectory . '/' . $relativePath; - - if (!$this->tmpDirectory->isExist($filePath)) { - $this->tmpDirectory->writeFile($filePath, $contents); - } - return $this->tmpDirectory->getAbsolutePath($filePath); - } - - /** - * @param string $relativePath - * @param string $contents - * - * @return void - */ - private function createFileMain($relativePath, $contents) - { - $filePath = '/static/' . $relativePath; - $contents .= '@urls-resolved: true;' . PHP_EOL . PHP_EOL; - $this->pubDirectory->writeFile($filePath, $contents); - return; - } } diff --git a/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php new file mode 100644 index 0000000000000000000000000000000000000000..64564ce4c0e9f3221710fe44a40bb316db4d7cf1 --- /dev/null +++ b/lib/internal/Magento/Framework/Less/FileGenerator/RelatedGenerator.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Less\FileGenerator; + +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Less\PreProcessor\Instruction\Import; +use Magento\Framework\View\Asset\LocalInterface; + +class RelatedGenerator +{ + /** + * @var \Magento\Framework\Filesystem\Directory\WriteInterface + */ + protected $tmpDirectory; + + /** + * @var \Magento\Framework\View\Asset\Repository + */ + private $assetRepo; + + /** + * @var \Magento\Framework\Less\File\Temporary + */ + private $temporaryFile; + + /** + * @param \Magento\Framework\Filesystem $filesystem + * @param \Magento\Framework\View\Asset\Repository $assetRepo + * @param \Magento\Framework\Less\File\Temporary $temporaryFile + */ + public function __construct( + \Magento\Framework\Filesystem $filesystem, + \Magento\Framework\View\Asset\Repository $assetRepo, + \Magento\Framework\Less\File\Temporary $temporaryFile + ) { + $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + $this->assetRepo = $assetRepo; + + $this->temporaryFile = $temporaryFile; + } + + /** + * Create all asset files, referenced from already processed ones + * + * @param Import $importGenerator + * + * @return void + */ + public function generate(Import $importGenerator) + { + do { + $relatedFiles = $importGenerator->getRelatedFiles(); + $importGenerator->resetRelatedFiles(); + foreach ($relatedFiles as $relatedFileInfo) { + list($relatedFileId, $asset) = $relatedFileInfo; + + $this->generateRelatedFile($relatedFileId, $asset); + } + } while ($relatedFiles); + } + + /** + * Create file, referenced relatively to an asset + * + * @param string $relatedFileId + * @param LocalInterface $asset + * @return \Magento\Framework\View\Asset\File + */ + protected function generateRelatedFile($relatedFileId, LocalInterface $asset) + { + $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset); + $this->temporaryFile->createFile($relatedAsset->getPath(), $relatedAsset->getContent()); + + return $relatedAsset; + } +} diff --git a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php index 60293981b8f761c070b06930b9461640e90b450b..f5985fbd30f6042f10cc4bed359f95453521d678 100644 --- a/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php +++ b/lib/internal/Magento/Framework/Less/Test/Unit/FileGeneratorTest.php @@ -4,8 +4,6 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\Framework\Less\Test\Unit; class FileGeneratorTest extends \PHPUnit_Framework_TestCase @@ -41,58 +39,105 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase private $object; /** - * @var \Magento\Framework\App\View\Asset\Publisher|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Less\FileGenerator\RelatedGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + private $relatedGenerator; + + /** + * @var \Magento\Framework\Less\Config|\PHPUnit_Framework_MockObject_MockObject */ - private $publisher; + private $config; + + /** + * @var \Magento\Framework\Less\File\Temporary|\PHPUnit_Framework_MockObject_MockObject + */ + private $temporaryFile; protected function setUp() { - $this->tmpDirectory = $this->getMockForAbstractClass('\Magento\Framework\Filesystem\Directory\WriteInterface'); - $this->rootDirectory = $this->getMockForAbstractClass('\Magento\Framework\Filesystem\Directory\ReadInterface'); + $this->tmpDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); + $this->rootDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface'); $this->rootDirectory->expects($this->any()) ->method('getRelativePath') ->will($this->returnArgument(0)); $this->rootDirectory->expects($this->any()) ->method('readFile') - ->will($this->returnCallback(function ($file) { - return "content of '$file'"; - })); + ->will( + $this->returnCallback( + function ($file) { + return "content of '$file'"; + } + ) + ); $filesystem = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false); - $filesystem->expects($this->exactly(2)) + $filesystem->expects($this->once()) ->method('getDirectoryWrite') - //->with(DirectoryList::VAR_DIR) ->will($this->returnValue($this->tmpDirectory)); $this->assetRepo = $this->getMock('\Magento\Framework\View\Asset\Repository', [], [], '', false); $this->magentoImport = $this->getMock( - '\Magento\Framework\Less\PreProcessor\Instruction\MagentoImport', [], [], '', false + 'Magento\Framework\Less\PreProcessor\Instruction\MagentoImport', + [], + [], + '', + false ); $this->import = $this->getMock( - '\Magento\Framework\Less\PreProcessor\Instruction\Import', [], [], '', false + 'Magento\Framework\Less\PreProcessor\Instruction\Import', + [], + [], + '', + false ); $assetSource = $this->getMock( - 'Magento\Framework\View\Asset\Source', [], [], '', false + 'Magento\Framework\View\Asset\Source', + [], + [], + '', + false ); - $this->publisher = $this->getMock('Magento\Framework\App\View\Asset\Publisher', [], [], '', false); - + $this->relatedGenerator = $this->getMockBuilder('Magento\Framework\Less\FileGenerator\RelatedGenerator') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->config = $this->getMockBuilder('Magento\Framework\Less\Config') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->temporaryFile = $this->getMockBuilder('Magento\Framework\Less\File\Temporary') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); $this->object = new \Magento\Framework\Less\FileGenerator( - $filesystem, $this->assetRepo, $this->magentoImport, $this->import, $assetSource, $this->publisher + $filesystem, + $this->assetRepo, + $this->magentoImport, + $this->import, + $assetSource, + $this->relatedGenerator, + $this->config, + $this->temporaryFile ); } public function testGenerateLessFileTree() { - $originalContent = 'original content'; + $lessDirectory = 'path/to/less'; $expectedContent = 'updated content'; - $expectedRelativePath = 'view_preprocessed/less/some/file.less'; - $expectedPath = '/var/view_preprocessed/less/some/file.less'; + $expectedRelativePath = 'some/file.less'; + $expectedPath = $lessDirectory . '/some/file.less'; - $asset = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); - $asset->expects($this->exactly(2)) - ->method('getPath') - ->will($this->returnValue('some/file.css')); - $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($asset, $originalContent, 'less'); + + $asset = $this->getMock('Magento\Framework\View\Asset\File', [], [], '', false); + $chain = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false); + + $this->config->expects($this->any()) + ->method('getLessDirectory') + ->willReturn($lessDirectory); + $this->tmpDirectory->expects($this->once()) + ->method('isExist') + ->willReturn(true); $this->magentoImport->expects($this->once()) ->method('process') @@ -100,59 +145,28 @@ class FileGeneratorTest extends \PHPUnit_Framework_TestCase $this->import->expects($this->once()) ->method('process') ->with($chain); + $this->relatedGenerator->expects($this->once()) + ->method('generate') + ->with($this->import); - $relatedAssetOne = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); - $relatedAssetOne->expects($this->any()) + $asset->expects($this->once()) ->method('getPath') - ->will($this->returnValue('related/file_one.css')); - $relatedAssetOne->expects($this->any()) - ->method('getContent') - ->will($this->returnValue("content of 'related/file_one.css'")); - $relatedAssetTwo = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); - $relatedAssetTwo->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('related/file_two.css')); - $relatedAssetTwo->expects($this->any()) + ->will($this->returnValue('some/file.css')); + $chain->expects($this->once()) ->method('getContent') - ->will($this->returnValue("content of 'related/file_two.css'")); - $assetsMap = [ - ['related/file_one.css', $asset, $relatedAssetOne], - ['related/file_two.css', $asset, $relatedAssetTwo], - ]; - $this->assetRepo->expects($this->any()) - ->method('createRelated') - ->will($this->returnValueMap($assetsMap)); - - $relatedFilesOne = [['related/file_one.css', $asset]]; - $this->import->expects($this->at(1)) - ->method('getRelatedFiles') - ->will($this->returnValue($relatedFilesOne)); - $relatedFilesTwo = [['related/file_two.css', $asset]]; - $this->import->expects($this->at(3)) - ->method('getRelatedFiles') - ->will($this->returnValue($relatedFilesTwo)); - $this->import->expects($this->at(5)) - ->method('getRelatedFiles') - ->will($this->returnValue([])); - - $writeMap = [ - [$expectedRelativePath, $expectedContent], - ['related/file_one.css', "content of 'related/file_one.css'"], - ['related/file_two.css', "content of 'related/file_two.css'"], - ]; - $pathsMap = [ - [$expectedRelativePath, $expectedPath], - ['related/file_one.css', '/var/view_preprocessed/less/related/file_one.css'], - ['related/file_two.css', '/var/view_preprocessed/less/related/file_two.css'], - ]; - $this->tmpDirectory->expects($this->any()) - ->method('writeFile') - ->will($this->returnValueMap($writeMap)); - $this->tmpDirectory->expects($this->any()) - ->method('getAbsolutePath') - ->will($this->returnValueMap($pathsMap)); - - $actual = $this->object->generateFileTree($chain); - $this->assertSame($expectedPath, $actual); + ->willReturn($expectedContent); + $chain->expects($this->once()) + ->method('getAsset') + ->willReturn($asset); + + $this->temporaryFile->expects($this->once()) + ->method('createFile') + ->with( + $expectedRelativePath, + $expectedContent + ) + ->willReturn($expectedPath); + + $this->assertSame($expectedPath, $this->object->generateFileTree($chain)); } } diff --git a/lib/internal/Magento/Framework/Locale/Format.php b/lib/internal/Magento/Framework/Locale/Format.php index 35dec7421cd6a203d533be951be990b301b3ff61..7cec1393dbba424d625c0ca37efe4e1230bc1e50 100644 --- a/lib/internal/Magento/Framework/Locale/Format.php +++ b/lib/internal/Magento/Framework/Locale/Format.php @@ -82,12 +82,17 @@ class Format implements \Magento\Framework\Locale\FormatInterface * Functions returns array with price formatting info * * @return array + * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getPriceFormat() { - $numberElements = (new DataBundle())->get($this->_localeResolver->getLocale())['NumberElements']; - $format = $numberElements['latn']['patterns']['currencyFormat']; - $symbols = $numberElements['latn']['symbols']; + $localeData = (new DataBundle())->get($this->_localeResolver->getLocale()); + $format = $localeData['NumberElements']['latn']['patterns']['currencyFormat'] + ?: explode(';', $localeData['NumberPatterns'][1])[0]; + $decimalSymbol = $localeData['NumberElements']['latn']['symbols']['decimal'] + ?: $localeData['NumberElements'][0]; + $groupSymbol = $localeData['NumberElements']['latn']['symbols']['group'] + ?: $localeData['NumberElements'][1]; $pos = strpos($format, ';'); if ($pos !== false) { @@ -120,8 +125,8 @@ class Format implements \Magento\Framework\Locale\FormatInterface 'pattern' => $this->_scopeResolver->getScope()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, - 'decimalSymbol' => $symbols['decimal'], - 'groupSymbol' => $symbols['group'], + 'decimalSymbol' => $decimalSymbol, + 'groupSymbol' => $groupSymbol, 'groupLength' => $group, 'integerRequired' => $integerRequired, ]; diff --git a/lib/internal/Magento/Framework/Message/AbstractMessage.php b/lib/internal/Magento/Framework/Message/AbstractMessage.php index b0a096bf8040ad50ffe49846ec55bd840f0994f9..b8efb73551a72af67160e6c3d646ae166b758cd5 100644 --- a/lib/internal/Magento/Framework/Message/AbstractMessage.php +++ b/lib/internal/Magento/Framework/Message/AbstractMessage.php @@ -47,7 +47,7 @@ abstract class AbstractMessage implements MessageInterface */ public function getText() { - return $this->text; + return (string)$this->text; } /** diff --git a/lib/internal/Magento/Framework/Message/Test/Unit/AbstractMessageTest.php b/lib/internal/Magento/Framework/Message/Test/Unit/AbstractMessageTest.php index e5d8f3b30585ac7972800d6d8031cb99c69b1845..13c0698523e9058c58482eb8ae90fe93538d3821 100644 --- a/lib/internal/Magento/Framework/Message/Test/Unit/AbstractMessageTest.php +++ b/lib/internal/Magento/Framework/Message/Test/Unit/AbstractMessageTest.php @@ -31,10 +31,10 @@ class AbstractMessageTest extends \PHPUnit_Framework_TestCase * covers \Magento\Framework\Message\AbstractMessage::setText * @dataProvider setTextGetTextProvider */ - public function testSetTextGetText($text) + public function testSetTextGetText($text, $resultText) { $this->model->setText($text); - $this->assertEquals($text, $this->model->getText()); + $this->assertEquals($resultText, $this->model->getText()); } /** @@ -42,7 +42,7 @@ class AbstractMessageTest extends \PHPUnit_Framework_TestCase */ public function setTextGetTextProvider() { - return [[''], ['some text']]; + return [['', ''], ['some text', 'some text'], [new \Magento\Framework\Phrase('some text'), 'some text']]; } /** diff --git a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php index 7905393ae85405e4e9ef22c62feef972dbab5dce..4dfbbc69d060e63398a90a981e6f8ee1c151d97a 100644 --- a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php +++ b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php @@ -122,8 +122,8 @@ class Minifier implements MinifierInterface '#(?<!' . implode('|', $this->inlineHtmlTags) . ')\> \<#', '><', preg_replace( - '#(?ix)(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script|style)\b))*+)' - . '(?:<(?>textarea|pre|script|style)\b|\z))#', + '#(?ix)(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script)\b))*+)' + . '(?:<(?>textarea|pre|script)\b|\z))#', ' ', preg_replace( '#(?<!:|\\\\)//(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#', diff --git a/lib/web/mage/backend/notification.js b/lib/web/mage/backend/notification.js index eb688214155efc8314dabc25cba88f44bfd839e8..7232e0310cddd185b88cbf5128cbf2502ba0172a 100644 --- a/lib/web/mage/backend/notification.js +++ b/lib/web/mage/backend/notification.js @@ -13,7 +13,7 @@ define([ $.widget('mage.notification', { options: { templates: { - global: '<div class="messages"><div class="message <%- if (data.error) { %>error<% } %>"><div><%- data.message %></div></div></div>' + global: '<div class="messages"><div class="message <% if (data.error) { %>error<% } %>"><div><%- data.message %></div></div></div>' } },