/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('catalog');
     /** @var ProductCollection $productCollection */
     $productCollection = $this->productCollectionFactory->create();
     $productIds = $productCollection->getAllIds();
     if (!count($productIds)) {
         $output->writeln("<info>No product images to resize</info>");
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
     }
     try {
         foreach ($productIds as $productId) {
             try {
                 /** @var Product $product */
                 $product = $this->productRepository->getById($productId);
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var ImageCache $imageCache */
             $imageCache = $this->imageCacheFactory->create();
             $imageCache->generate($product);
             $output->write(".");
         }
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
     $output->write("\n");
     $output->writeln("<info>Product images resized successfully</info>");
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('catalog');
     /** @var ProductCollection $productCollection */
     $productCollection = $this->productCollectionFactory->create();
     $productIds = $productCollection->getAllIds();
     if (!count($productIds)) {
         $output->writeln("<info>No product images to resize</info>");
         return;
     }
     try {
         foreach ($productIds as $productId) {
             try {
                 /** @var Product $product */
                 $product = $this->productRepository->getById($productId);
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var ImageCache $imageCache */
             $imageCache = $this->imageCacheFactory->create();
             $imageCache->generate($product);
             $output->write(".");
         }
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         return;
     }
     $output->write("\n");
     $output->writeln("<info>Product images resized successfully</info>");
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->setDecorated(true);
     $this->appState->setAreaCode('catalog');
     $connection = $this->attributeResource->getConnection();
     $attributeTables = $this->getAttributeTables();
     $progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables));
     $progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%');
     $this->attributeResource->beginTransaction();
     try {
         // Find and remove unused attributes
         foreach ($attributeTables as $attributeTable) {
             $progress->setMessage($attributeTable . ' ');
             $affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable);
             if (count($affectedIds) > 0) {
                 $connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]);
             }
             $progress->advance();
         }
         $this->attributeResource->commit();
         $output->writeln("");
         $output->writeln("<info>Unused product attributes successfully cleaned up:</info>");
         $output->writeln("<comment>  " . implode("\n  ", $attributeTables) . "</comment>");
     } catch (\Exception $exception) {
         $this->attributeResource->rollBack();
         $output->writeln("");
         $output->writeln("<error>{$exception->getMessage()}</error>");
     }
 }
示例#4
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $this->_state->setAreaCode('crontab');
     $this->_eventManager->dispatch('default');
     $this->_response->setCode(0);
     return $this->_response;
 }
示例#5
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Some error
  */
 public function testEmulateAreaCodeException()
 {
     $areaCode = 'original code';
     $emulatedCode = 'emulated code';
     $this->scopeMock->expects($this->once())->method('setCurrentScope')->with($areaCode);
     $this->model->setAreaCode($areaCode);
     $this->model->emulateAreaCode($emulatedCode, [$this, 'emulateAreaCodeCallbackException']);
     $this->assertEquals($this->model->getAreaCode(), $areaCode);
 }
示例#6
0
 /**
  * {@inheritdoc}
  **/
 public function launch()
 {
     $areaCode = 'adminhtml';
     $this->appState->setAreaCode($areaCode);
     $this->objectManager->configure($this->configLoader->load($areaCode));
     /** @var \Magento\Tools\SampleData\Logger $sampleDataLogger */
     $sampleDataLogger = $this->objectManager->get('Magento\\Tools\\SampleData\\Logger');
     $sampleDataLogger->setSubject($this->objectManager->get('Magento\\Setup\\Model\\ConsoleLogger'));
     $this->installer->run($this->userFactory->create()->loadByUsername($this->adminUserName));
     return $this->response;
 }
示例#7
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $this->_state->setAreaCode(Area::AREA_CRONTAB);
     $configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
     $this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
     /** @var \Magento\Framework\Event\ManagerInterface $eventManager */
     $eventManager = $this->objectManager->get('Magento\\Framework\\Event\\ManagerInterface');
     $eventManager->dispatch('default');
     $this->_response->setCode(0);
     return $this->_response;
 }
 /**
  * {@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>");
     }
 }
示例#9
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     $areaCode = 'install';
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_loader->load($areaCode));
     if (isset($this->_arguments['uninstall'])) {
         $sessionConsole = $this->_objectManager->create('\\Magento\\Framework\\Session\\SessionConsole');
         $installerModel = $this->_objectManager->create('Magento\\Install\\Model\\Installer', ['session' => $sessionConsole]);
         $installer = $this->_installerFactory->create(['installArgs' => $this->_arguments, 'installer' => $installerModel]);
     } else {
         $installer = $this->_installerFactory->create(array('installArgs' => $this->_arguments));
     }
     if (isset($this->_arguments['show_locales'])) {
         $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableLocales()));
     } elseif (isset($this->_arguments['show_currencies'])) {
         $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableCurrencies()));
     } elseif (isset($this->_arguments['show_timezones'])) {
         $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableTimezones()));
     } elseif (isset($this->_arguments['show_install_options'])) {
         $this->_output->readableOutput(PHP_EOL . 'Required parameters:');
         $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getRequiredParams()));
         $this->_output->readableOutput(PHP_EOL . 'Optional parameters:');
         $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getOptionalParams()));
         $this->_output->readableOutput(PHP_EOL . 'Flag values are considered positive if set to 1, y, true or yes.' . 'Any other value is considered as negative.' . PHP_EOL);
     } else {
         $this->_handleInstall($installer);
     }
     $this->_response->setCode(0);
     return $this->_response;
 }
示例#10
0
 /**
  * Finds requested resource and provides it to the client
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \Exception
  */
 public function launch()
 {
     $appMode = $this->state->getMode();
     if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
         $this->response->setHttpResponseCode(404);
     } else {
         try {
             $path = $this->request->get('resource');
             $params = $this->parsePath($path);
             $this->state->setAreaCode($params['area']);
             $this->objectManager->configure($this->configLoader->load($params['area']));
             $file = $params['file'];
             unset($params['file']);
             $asset = $this->assetRepo->createAsset($file, $params);
             $this->response->setFilePath($asset->getSourceFile());
             $this->publisher->publish($asset);
         } catch (\Exception $e) {
             if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
                 throw $e;
             }
             $this->response->setHttpResponseCode(404);
         }
     }
     return $this->response;
 }
示例#11
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     //
     //        /** @var \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory */
     //        $eavSetupFactory = $objectManager->get('Magento\Eav\Setup\EavSetupFactory');
     //
     //        $setup = $objectManager->get('Magento\Framework\Setup\ModuleDataSetupInterface');
     //
     //        $eavSetup = $eavSetupFactory->create(['setup' => $setup]);
     //
     //        for ($i = 1; $i < 400; $i++) {
     //            $eavSetup->addAttribute(
     //                \Magento\Catalog\Model\Product::ENTITY,
     //                substr(md5($i), 0, 5) . '_sample_attribute_' . $i,
     //                [
     //                    'type'                    => 'int',
     //                    'backend'                 => '',
     //                    'frontend'                => '',
     //                    'label'                   => 'Sample Atrribute ' . $i,
     //                    'input'                   => '',
     //                    'class'                   => '',
     //                    'source'                  => '',
     //                    'global'                  => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
     //                    'visible'                 => true,
     //                    'required'                => false,
     //                    'user_defined'            => true,
     //                    'default'                 => '',
     //                    'searchable'              => true,
     //                    'filterable'              => true,
     //                    'comparable'              => true,
     //                    'visible_on_front'        => true,
     //                    'used_in_product_listing' => true,
     //                    'unique'                  => false,
     //                    'apply_to'                => ''
     //                ]
     //            );
     //
     //            echo $i . PHP_EOL;
     //        }
     //
     //        die();
     try {
         $this->appState->setAreaCode('frontend');
     } catch (\Exception $e) {
     }
     $collection = $this->indexCollectionFactory->create()->addFieldToFilter('is_active', 1);
     /** @var \Mirasvit\Search\Model\Index $index */
     foreach ($collection as $index) {
         $output->write($index->getTitle() . ' [' . $index->getCode() . ']....');
         try {
             $index->getIndexInstance()->reindexAll();
             $output->writeln("<info>Done</info>");
         } catch (\Exception $e) {
             $output->writeln("Error");
             $output->writeln($e->getMessage());
         }
     }
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return null|int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     try {
         $area = $this->appState->getAreaCode();
         if ($area != Area::AREA_ADMINHTML) {
             $this->appState->setAreaCode(Area::AREA_ADMINHTML);
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->appState->setAreaCode(Area::AREA_ADMINHTML);
     }
     $area = $this->appState->getAreaCode();
     $configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
     $this->objectManager->configure($configLoader->load($area));
     $this->registry->register('isSecureArea', true);
 }
 public function __construct(ProductRepositoryInterface $productRepository, SearchCriteriaBuilder $searchCriteriaBuilder, AppState $appState)
 {
     $this->productRepository = $productRepository;
     $this->searchCriteriaBuilder = $searchCriteriaBuilder;
     try {
         $appState->setAreaCode('adminhtml');
     } catch (\Exception $e) {
     }
 }
 /**
  * Productlist constructor.
  * @param ProductTypeListInterface $productTypeList
  * @param ProductRepositoryInterface $productRepository
  * @param SearchCriteriaBuilder $searchCriteriaBuilder
  * @param Status $productStatus
  * @param \Magento\Framework\App\State $appState
  */
 public function __construct(ProductTypeListInterface $productTypeList, ProductRepositoryInterface $productRepository, SearchCriteriaBuilder $searchCriteriaBuilder, Status $productStatus, State $appState)
 {
     $this->productTypeList = $productTypeList;
     $this->productRepository = $productRepository;
     $this->searchCriteriaBuilder = $searchCriteriaBuilder;
     $this->productStatus = $productStatus;
     // Fixes error that area code should be set when using active filter
     $appState->setAreaCode('console');
 }
示例#15
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = array('request' => $this->_request, 'response' => $this->_response);
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }
示例#16
0
 /**
  * Finds requested resource and provides it to the client
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \Exception
  */
 public function launch()
 {
     // disabling profiling when retrieving static resource
     \Magento\Framework\Profiler::reset();
     $appMode = $this->state->getMode();
     if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
         $this->response->setHttpResponseCode(404);
     } else {
         $path = $this->request->get('resource');
         $params = $this->parsePath($path);
         $this->state->setAreaCode($params['area']);
         $this->objectManager->configure($this->configLoader->load($params['area']));
         $file = $params['file'];
         unset($params['file']);
         $asset = $this->assetRepo->createAsset($file, $params);
         $this->response->setFilePath($asset->getSourceFile());
         $this->publisher->publish($asset);
     }
     return $this->response;
 }
 public function __construct(\Magento\Framework\App\State $state, \Magento\Store\Model\StoreManagerInterface $storeManagerInterface, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, \Magento\Framework\Api\SearchCriteria $searchCriteriaBuilder)
 {
     $state->setAreaCode('adminhtml');
     $this->_scopeConfig = $scopeConfig;
     $this->_orderRepository = $orderRepository;
     $this->_searchCriteriaBuilder = $searchCriteriaBuilder;
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $this->_orderHelper = $objectManager->get('\\Riskified\\Decider\\Api\\Order\\Helper');
     $this->_transport = new CurlTransport(new Signature\HttpDataSignature());
     $this->_transport->timeout = 15;
     parent::__construct();
 }
 /**
  * AbstractProductCommand constructor.
  * @param ProductFactory $productFactory
  * @param Client $eventClient
  * @param AppState $appState
  */
 public function __construct(ProductFactory $productFactory, Client $eventClient, Export $export, ExportFactory $exportFactory, AppState $appState, PersonalisedProductsLogger $logger)
 {
     $this->_productFactory = $productFactory;
     $this->_eventClient = $eventClient;
     $this->_export = $export;
     $this->_exportFactory = $exportFactory;
     $this->_logger = $logger;
     try {
         $appState->setAreaCode('adminhtml');
     } catch (\Exception $e) {
         $this->_logger->addCritical($e->getMessage());
     }
     parent::__construct();
 }
示例#19
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     try {
         $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
         $this->_state->setAreaCode($areaCode);
         $this->_objectManager->configure($this->_configLoader->load($areaCode));
         $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
         // This event gives possibility to launch something before sending output (allow cookie setting)
         $eventParams = array('request' => $this->_request, 'response' => $this->_response);
         $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     } catch (\Exception $exception) {
         $message = $exception->getMessage() . "\n";
         try {
             if ($this->_state->getMode() == State::MODE_DEVELOPER) {
                 $message .= '<pre>';
                 $message .= $exception->getMessage() . "\n\n";
                 $message .= $exception->getTraceAsString();
                 $message .= '</pre>';
             } else {
                 $reportData = array($exception->getMessage(), $exception->getTraceAsString());
                 // retrieve server data
                 if (isset($_SERVER)) {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $reportData['url'] = $_SERVER['REQUEST_URI'];
                     }
                     if (isset($_SERVER['SCRIPT_NAME'])) {
                         $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
                     }
                 }
                 require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
                 $processor = new \Magento\Framework\Error\Processor($this->_response);
                 $processor->saveReport($reportData);
                 $this->_response = $processor->processReport();
             }
         } catch (\Exception $exception) {
             $message .= "Unknown error happened.";
         }
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody($message);
     }
     return $this->_response;
 }
示例#20
0
 /**
  * Run application
  *
  * @throws \InvalidArgumentException
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     /** @var \Magento\Framework\App\FrontControllerInterface $frontController */
     $frontController = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface');
     $result = $frontController->dispatch($this->_request);
     // TODO: Temporary solution until all controllers return ResultInterface (MAGETWO-28359)
     if ($result instanceof ResultInterface) {
         $this->registry->register('use_page_cache_plugin', true, true);
         $result->renderResult($this->_response);
     } elseif ($result instanceof HttpInterface) {
         $this->_response = $result;
     } else {
         throw new \InvalidArgumentException('Invalid return type');
     }
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = ['request' => $this->_request, 'response' => $this->_response];
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }
示例#21
0
 /**
  * Launch application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     $this->state->setAreaCode($this->params->getArea());
     $this->objectManager->configure($this->configLoader->load($this->params->getArea()));
     $sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt());
     foreach ($this->params->getFiles() as $file) {
         $file .= '.' . $this->params->getExt();
         $this->logger->logMessage("Gathering {$file} sources.");
         $asset = $this->assetRepo->createAsset($file, ['area' => $this->params->getArea(), 'theme' => $this->params->getTheme(), 'locale' => $this->params->getLocale()]);
         $sourceFile = $this->assetSource->findSource($asset);
         $content = \file_get_contents($sourceFile);
         $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType()]);
         $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");
     }
     $this->response->setCode(Response::SUCCESS);
     return $this->response;
 }
示例#22
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->appState->setAreaCode('frontend');
     $this->warmer->warm();
 }
 /**
  * @return \CedricBlondeau\CatalogImportCommand\Model\Import
  */
 protected function getImportModel()
 {
     $this->state->setAreaCode('adminhtml');
     return $this->objectManager->create('CedricBlondeau\\CatalogImportCommand\\Model\\Import');
 }