/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $options = $input->getOptions(); $languages = $input->getArgument(self::LANGUAGE_OPTION); foreach ($languages as $lang) { if (!$this->validator->isValid($lang)) { throw new \InvalidArgumentException($lang . ' argument has invalid value, please run info:language:list for list of available locales'); } } // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); $deployer = $this->objectManager->create('Magento\\Deploy\\Model\\Deployer', ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]); $deployer->deploy($this->objectManagerFactory, $languages); }
/** * Set locale * * @param string $locale * @return $this */ public function setLocale($locale = null) { $forceLocale = $this->_request->getParam('locale', null); if (!$this->_localeValidator->isValid($forceLocale)) { $forceLocale = false; } $sessionLocale = $this->_session->getSessionLocale(); $userLocale = $this->_localeManager->getUserInterfaceLocale(); $localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]); if (count($localeCodes)) { $locale = reset($localeCodes); } return parent::setLocale($locale); }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $area = $input->getOption(self::AREA_OPTION); $locale = $input->getOption(self::LOCALE_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getOption(self::TYPE_ARGUMENT); $files = $input->getArgument(self::FILE_ARGUMENT); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } if (!preg_match('#^[\\w\\-]+\\/[\\w\\-]+$#', $theme)) { throw new \InvalidArgumentException('Value "' . $theme . '" of the option "' . self::THEME_OPTION . '" has invalid format. The format should be "Vendor/theme".'); } $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type); $output->writeln($message); foreach ($files as $file) { $fileInfo = pathinfo($file); $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); try { $this->assetPublisher->publish($asset); } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) { throw new \InvalidArgumentException('Verify entered values of the argument and options. ' . $e->getMessage()); } $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>'); } $output->writeln('<info>Successfully processed.</info>'); }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $locale = $input->getOption(self::LOCALE_OPTION); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } $area = $input->getOption(self::AREA_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getArgument(self::TYPE_ARGUMENT); $this->state->setAreaCode($area); $this->objectManager->configure($this->configLoader->load($area)); $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type); foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) { $file .= '.' . $type; $output->writeln("<info>Gathering {$file} sources.</info>"); $asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); $sourceFile = $this->assetSource->findSource($asset); $relativePath = $rootDir->getRelativePath($sourceFile); $content = $rootDir->readFile($relativePath); $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]); $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); $source = $rootDir->getRelativePath($processedCoreFile); $destination = $asset->getPath(); $rootDir->copyFile($source, $destination, $targetDir); $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>"); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $options = $input->getOptions(); $languages = $input->getArgument(self::LANGUAGE_OPTION); foreach ($languages as $lang) { if (!$this->validator->isValid($lang)) { throw new \InvalidArgumentException($lang . ' argument has invalid value, please run info:language:list for list of available locales'); } } try { // run the deployment logic $filesUtil = $this->objectManager->create('\\Magento\\Framework\\App\\Utility\\Files'); $deployer = $this->objectManager->create('Magento\\Deploy\\Model\\Deployer', ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]); $deployer->deploy($this->objectManagerFactory, $languages); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>>'); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($e->getTraceAsString()); } return; } }
/** * {@inheritdoc} * @param $languagesInclude array * @param $languagesExclude array * @throws \InvalidArgumentException */ private function checkLanguagesInput($languagesInclude, $languagesExclude) { if ($languagesInclude[0] != 'all') { foreach ($languagesInclude as $lang) { if (!$this->validator->isValid($lang)) { throw new \InvalidArgumentException($lang . ' argument has invalid value, please run info:language:list for list of available locales'); } } } if ($languagesInclude[0] != 'all' && $languagesExclude[0] != 'none') { throw new \InvalidArgumentException('--language (-l) and --exclude-language cannot be used at the same time'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>You need to install the Magento application before running this utility.</info>"); return; } $options = $input->getOptions(); $languages = $input->getArgument(self::LANGUAGE_OPTION); foreach ($languages as $lang) { if (!$this->validator->isValid($lang)) { throw new \InvalidArgumentException( $lang . ' argument has invalid value, please run info:language:list for list of available locales' ); } } try { $objectManager = $this->objectManagerProvider->get(); // run the deployment logic $filesUtil = $objectManager->create( '\Magento\Framework\App\Utility\Files', ['pathToSource' => BP] ); $objectManagerFactory = $this->objectManagerProvider->getObjectManagerFactory(); /** @var \Magento\Setup\Model\Deployer $deployer */ $deployer = $objectManager->create( 'Magento\Setup\Model\Deployer', ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] ); $deployer->deploy($objectManagerFactory, $languages); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>>'); if ($output->isVerbose()) { $output->writeln($e->getTraceAsString()); } return; } }
/** * @inheritdoc * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $area = $input->getOption(self::AREA_OPTION); $locale = $input->getOption(self::LOCALE_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getOption(self::TYPE_ARGUMENT); $files = $input->getArgument(self::FILE_ARGUMENT); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type); $output->writeln($message); foreach ($files as $file) { $fileInfo = pathinfo($file); $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); $this->assetPublisher->publish($asset); $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>'); } $output->writeln('<info>Successfully processed.</info>'); }
/** * Validate codes for languages, currencies or timezones * * @param Locale|Timezone|Currency $lists * @param string $code * @param string $type * @return string */ private function validateCodes($lists, $code, $type) { $errorMsg = ''; if (!$lists->isValid($code)) { $errorMsg = '<error>' . 'Command option \'' . $type . '\': Invalid value. To see possible values, ' . "run command 'bin/magento info:" . $type . ':list\'.</error>'; } return $errorMsg; }