diff --git a/dev/tools/performance-toolkit/fixtures/cart_price_rules.php b/dev/tools/performance-toolkit/fixtures/cart_price_rules.php index 8bb9287c3fa521d3a2560a32d8fab920ef1c9abb..03f39bac448dd0e2fe8eb39751dda43a45d278aa 100644 --- a/dev/tools/performance-toolkit/fixtures/cart_price_rules.php +++ b/dev/tools/performance-toolkit/fixtures/cart_price_rules.php @@ -20,11 +20,8 @@ class CartPriceRulesFixture extends \Magento\ToolkitFramework\Fixture public function execute() { $this->application->resetObjectManager(); - $cartPriceRulesCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('cart_price_rules', 9); - $cartPriceRulesProductsFloor = \Magento\ToolkitFramework\Config::getInstance()->getValue( - 'cart_price_rules_floor', - 3 - ); + $cartPriceRulesCount = $this->application->getValue('cart_price_rules', 9); + $cartPriceRulesProductsFloor = $this->application->getValue('cart_price_rules_floor', 3); /** @var \Magento\Store\Model\StoreManager $storeManager */ $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); diff --git a/dev/tools/performance-toolkit/fixtures/catalog_price_rules.php b/dev/tools/performance-toolkit/fixtures/catalog_price_rules.php index 8956c18ecaacee3caf98b1ba25c49b47ff6e338a..d6f9bc849bedda882d7d7966770af67ae0ab9da7 100644 --- a/dev/tools/performance-toolkit/fixtures/catalog_price_rules.php +++ b/dev/tools/performance-toolkit/fixtures/catalog_price_rules.php @@ -19,7 +19,7 @@ class CatalogPriceRulesFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $catalogPriceRulesCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('catalog_price_rules', 3); + $catalogPriceRulesCount = $this->application->getValue('catalog_price_rules', 3); $this->application->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ diff --git a/dev/tools/performance-toolkit/fixtures/categories.php b/dev/tools/performance-toolkit/fixtures/categories.php index b6bc39d83f34ad25bb0d25fd3619741549aa57fc..7e2222385d20596b29c10dcb293500150e1b5f98 100644 --- a/dev/tools/performance-toolkit/fixtures/categories.php +++ b/dev/tools/performance-toolkit/fixtures/categories.php @@ -19,8 +19,8 @@ class CategoriesFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $categoriesNumber = \Magento\ToolkitFramework\Config::getInstance()->getValue('categories', 18); - $maxNestingLevel = \Magento\ToolkitFramework\Config::getInstance()->getValue('categories_nesting_level', 3); + $categoriesNumber = $this->application->getValue('categories', 18); + $maxNestingLevel = $this->application->getValue('categories_nesting_level', 3); $this->application->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ diff --git a/dev/tools/performance-toolkit/fixtures/configs_apply.php b/dev/tools/performance-toolkit/fixtures/configs_apply.php index 99c62d1233a11370c69f1c49a2781cb18a265544..a517c91a5631fac4523bededcf6d5a91da3523e3 100644 --- a/dev/tools/performance-toolkit/fixtures/configs_apply.php +++ b/dev/tools/performance-toolkit/fixtures/configs_apply.php @@ -19,7 +19,7 @@ class ConfigsApplyFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $configs = \Magento\ToolkitFramework\Config::getInstance()->getValue('configs', array()); + $configs = $this->application->getValue('configs', array()); $this->application->resetObjectManager(); foreach ($configs['config'] as $config) { diff --git a/dev/tools/performance-toolkit/fixtures/configurable_products.php b/dev/tools/performance-toolkit/fixtures/configurable_products.php index a3aa8f8ba8d244eba56a8ca2e184be05f7cdbbce..7005c04b122b5316ea6a574c70545518d0a7de6c 100644 --- a/dev/tools/performance-toolkit/fixtures/configurable_products.php +++ b/dev/tools/performance-toolkit/fixtures/configurable_products.php @@ -820,7 +820,7 @@ class ConfigurableProductsFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $configurablesCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('configurable_products', 90); + $configurablesCount = $this->application->getValue('configurable_products', 90); $this->application->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ diff --git a/dev/tools/performance-toolkit/fixtures/customers.php b/dev/tools/performance-toolkit/fixtures/customers.php index df42bc283a2211b50db2b6a0b2c27dad1a0f095c..2ad72b2a70cc446eac093c785032e867e43a88bd 100644 --- a/dev/tools/performance-toolkit/fixtures/customers.php +++ b/dev/tools/performance-toolkit/fixtures/customers.php @@ -19,7 +19,7 @@ class CustomersFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $customersNumber = \Magento\ToolkitFramework\Config::getInstance()->getValue('customers', 10); + $customersNumber = $this->application->getValue('customers', 10); $this->application->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ diff --git a/dev/tools/performance-toolkit/fixtures/simple_products.php b/dev/tools/performance-toolkit/fixtures/simple_products.php index 26d676455aa1d4597f7cb5643e30d1c78c37033f..a061f3d30077160685577b01d5e215a3f89ec3a7 100644 --- a/dev/tools/performance-toolkit/fixtures/simple_products.php +++ b/dev/tools/performance-toolkit/fixtures/simple_products.php @@ -19,7 +19,7 @@ class SimpleProductsFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $simpleProductsCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('simple_products', 180); + $simpleProductsCount = $this->application->getValue('simple_products', 180); $this->application->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ diff --git a/dev/tools/performance-toolkit/fixtures/stores.php b/dev/tools/performance-toolkit/fixtures/stores.php index ac56367cc2701078828c3d74604042a32146d888..d568706aba55255f5c6e5389c6fd3501c18cf824 100644 --- a/dev/tools/performance-toolkit/fixtures/stores.php +++ b/dev/tools/performance-toolkit/fixtures/stores.php @@ -19,9 +19,9 @@ class StoresFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $websitesCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('websites', 2); - $storeGroupsCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('store_groups', 3); - $storesCount = \Magento\ToolkitFramework\Config::getInstance()->getValue('store_views', 5); + $websitesCount = $this->application->getValue('websites', 2); + $storeGroupsCount = $this->application->getValue('store_groups', 3); + $storesCount = $this->application->getValue('store_views', 5); $this->application->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php b/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php index 75c1a83b236f6402527dfdef743390cff6559d4d..892850a713724ea229c7ff05de7a3680c4bedbb6 100644 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php +++ b/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php @@ -10,6 +10,11 @@ namespace Magento\ToolkitFramework; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Indexer\Console\Command\IndexerReindexCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\OutputInterface; + class Application { @@ -35,11 +40,6 @@ class Application */ protected $_application; - /** - * @var \Magento\Framework\Shell - */ - protected $_shell; - /** * @var \Magento\Framework\ObjectManagerInterface */ @@ -60,24 +60,25 @@ class Application protected $_paramLabels = []; /** - * @var string + * @var array */ - protected $_applicationBaseDir; + protected $_initArguments; /** + * Configuration array + * * @var array */ - protected $_initArguments; + protected $config = []; /** - * @param string $applicationBaseDir - * @param \Magento\Framework\Shell $shell + * Constructor + * */ - public function __construct($applicationBaseDir, \Magento\Framework\Shell $shell, array $initArguments) + public function __construct(IndexerReindexCommand $reindexCommand, $initArguments = []) { - $this->_applicationBaseDir = $applicationBaseDir; - $this->_shell = $shell; $this->_initArguments = $initArguments; + $this->reindexCommand = $reindexCommand; } /** @@ -119,15 +120,11 @@ class Application /** * Run reindex - * - * @return Application */ - public function reindex() + public function reindex(OutputInterface $output) { - $this->_shell->execute( - 'php -f ' . $this->_applicationBaseDir . '/bin/magento indexer:reindex --all' - ); - return $this; + $input = new ArrayInput([]); + $this->reindexCommand->run($input, $output); } /** @@ -205,4 +202,33 @@ class Application $this->bootstrap(); return $this; } + + /** + * Load config from file + * + * @param string $filename + * @throws \Exception + * + * @return void + */ + public function loadConfig($filename) + { + if (!is_readable($filename)) { + throw new \Exception("Profile configuration file `{$filename}` is not readable or does not exists."); + } + $this->config = (new \Magento\Framework\Xml\Parser())->load($filename)->xmlToArray(); + } + + /** + * Get profile configuration value + * + * @param string $key + * @param null|mixed $default + * + * @return mixed + */ + public function getValue($key, $default = null) + { + return isset($this->config['config']['profile'][$key]) ? $this->config['config']['profile'][$key] : $default; + } } diff --git a/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php b/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..d6277e9fef3808df3ade2f7ab1867205cbc6cbb3 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php @@ -0,0 +1,118 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Magento\ToolkitFramework\Config; +use Magento\ToolkitFramework\Application; + + +class GenerateFixturesCommand extends Command +{ + /** + * Profile argument + */ + const PROFILE_ARGUMENT = 'profile'; + + /** + * @var Application + */ + private $application; + + /** + * @var Config + */ + private $config; + + /** + * @param Application $application + * @param Config $config + */ + public function __construct(Application $application, Config $config) + { + $this->config = $config; + $this->application = $application; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('setup:perf:generate-fixtures') + ->setDescription('Generates fixtures') + ->setDefinition([ + new InputArgument( + self::PROFILE_ARGUMENT, + InputArgument::REQUIRED, + 'Path to profile configuration file' + ), + ]); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + try { + $totalStartTime = microtime(true); + + + $application = $this->application; + $application->bootstrap(); + $application->loadFixtures(); + $application->loadConfig($input->getArgument(self::PROFILE_ARGUMENT)); + + $output->writeln('<info>Generating profile with following params:</info>'); + + foreach ($application->getParamLabels() as $configKey => $label) { + $output->writeln('<info> |- ' . $label . ': ' . $application->getValue($configKey) . '</info>'); + } + + /** @var $config \Magento\Indexer\Model\Config */ + $config = $application->getObjectManager()->get('Magento\Indexer\Model\Config'); + $indexerListIds = $config->getIndexers(); + /** @var $indexerRegistry \Magento\Indexer\Model\IndexerRegistry */ + $indexerRegistry = $application->getObjectManager()->create('Magento\Indexer\Model\IndexerRegistry'); + $indexersState = []; + foreach ($indexerListIds as $key => $indexerId) { + $indexer = $indexerRegistry->get($indexerId['indexer_id']); + $indexersState[$indexerId['indexer_id']] = $indexer->isScheduled(); + $indexer->setScheduled(true); + } + + foreach ($application->getFixtures() as $fixture) { + echo $fixture->getActionTitle() . '... '; + $startTime = microtime(true); + $fixture->execute(); + $endTime = microtime(true); + $resultTime = $endTime - $startTime; + echo ' done in ' . gmdate('H:i:s', $resultTime) . PHP_EOL; + } + + foreach ($indexerListIds as $indexerId) { + /** @var $indexer \Magento\Indexer\Model\Indexer */ + $indexer = $indexerRegistry->get($indexerId['indexer_id']); + $indexer->setScheduled($indexersState[$indexerId['indexer_id']]); + } + + $application->reindex($output); + $totalEndTime = microtime(true); + $totalResultTime = $totalEndTime - $totalStartTime; + + $output->writeln('<info>Total execution time: ' . gmdate('H:i:s', $totalResultTime) . '</info>'); + } catch (\Exception $e) { + $output->writeln('<error>' . $e->getMessage() . '</error>'); + } + } +} diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 6ebcc5c9850302f8ef84f6ba9ec1db88cb84a5fd..da9f1a45ff92d41769cb2898d7b2145de2b1dfb2 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -49,6 +49,7 @@ class CommandList 'Magento\Setup\Console\Command\DeployStaticContentCommand', 'Magento\Setup\Console\Command\DiCompileCommand', 'Magento\Setup\Console\Command\DiCompileMultiTenantCommand', + 'Magento\Setup\Console\Command\GenerateFixturesCommand', 'Magento\Setup\Console\Command\I18nCollectPhrasesCommand', 'Magento\Setup\Console\Command\I18nPackCommand', 'Magento\Setup\Console\Command\InfoCurrencyListCommand',