Ejemplo n.º 1
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if ($this->initMagento()) {
         $codeArgument = String::trimExplodeEmpty(',', $input->getArgument('code'));
         $this->saveCacheStatus($codeArgument, true);
         if (count($codeArgument) > 0) {
             foreach ($codeArgument as $code) {
                 $output->writeln('<info>Cache <comment>' . $code . '</comment> enabled</info>');
             }
         } else {
             $output->writeln('<info>Caches enabled</info>');
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if ($this->initMagento()) {
         $codeArgument = String::trimExplodeEmpty(',', $input->getArgument('code'));
         $this->saveCacheStatus($codeArgument, false);
         if (empty($codeArgument)) {
             $this->_getCacheModel()->flush();
         } else {
             foreach ($codeArgument as $type) {
                 $this->_getCacheModel()->cleanType($type);
             }
         }
         if (count($codeArgument) > 0) {
             foreach ($codeArgument as $code) {
                 $output->writeln('<info>Cache <comment>' . $code . '</comment> disabled</info>');
             }
         } else {
             $output->writeln('<info>Caches disabled</info>');
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if ($this->initMagento()) {
         $this->writeSection($output, 'Reindex');
         $this->disableObservers();
         $indexCode = $input->getArgument('index_code');
         $indexerList = $this->getIndexerList();
         if ($indexCode === null) {
             $question = array();
             foreach ($indexerList as $key => $indexer) {
                 $question[] = '<comment>' . str_pad('[' . ($key + 1) . ']', 4, ' ', STR_PAD_RIGHT) . '</comment> ' . str_pad($indexer['code'], 40, ' ', STR_PAD_RIGHT) . ' <info>(last runtime: ' . $indexer['last_runtime'] . ')</info>' . "\n";
             }
             $question[] = '<question>Please select a indexer:</question>';
             $indexCodes = $this->getHelper('dialog')->askAndValidate($output, $question, function ($typeInput) use($indexerList) {
                 if (strstr($typeInput, ',')) {
                     $typeInputs = \N98\Util\String::trimExplodeEmpty(',', $typeInput);
                 } else {
                     $typeInputs = array($typeInput);
                 }
                 $returnCodes = array();
                 foreach ($typeInputs as $typeInput) {
                     if (!isset($indexerList[$typeInput - 1])) {
                         throw new \InvalidArgumentException('Invalid indexer');
                     }
                     $returnCodes[] = $indexerList[$typeInput - 1]['code'];
                 }
                 return $returnCodes;
             });
         } else {
             // take cli argument
             $indexCodes = \N98\Util\String::trimExplodeEmpty(',', $indexCode);
         }
         foreach ($indexCodes as $indexCode) {
             try {
                 \Mage::dispatchEvent('shell_reindex_init_process');
                 $process = $this->_getIndexerModel()->getProcessByCode($indexCode);
                 if (!$process) {
                     throw new \InvalidArgumentException('Indexer was not found!');
                 }
                 $output->writeln('<info>Started reindex of: <comment>' . $indexCode . '</comment></info>');
                 /**
                  * Try to estimate runtime. If index was aborted or never created we have a timestamp < 0
                  */
                 $runtimeInSeconds = $this->getRuntimeInSeconds($process);
                 if ($runtimeInSeconds > 0) {
                     $estimatedEnd = new \DateTime('now', new \DateTimeZone('UTC'));
                     $estimatedEnd->add(new \DateInterval('PT' . $runtimeInSeconds . 'S'));
                     $output->writeln('<info>Estimated end: <comment>' . $estimatedEnd->format('Y-m-d H:i:s T') . '</comment></info>');
                 }
                 $startTime = new \DateTime('now');
                 $dateTimeUtils = new \N98\Util\DateTime();
                 $process->reindexEverything();
                 \Mage::dispatchEvent($process->getIndexerCode() . '_shell_reindex_after');
                 $endTime = new \DateTime('now');
                 $output->writeln('<info>Successfully reindexed <comment>' . $indexCode . '</comment> (Runtime: <comment>' . $dateTimeUtils->getDifferenceAsString($startTime, $endTime) . '</comment>)</info>');
                 \Mage::dispatchEvent('shell_reindex_finalize_process');
             } catch (\Exception $e) {
                 $output->writeln('<error>' . $e->getMessage() . '</error>');
                 \Mage::dispatchEvent('shell_reindex_finalize_process');
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \InvalidArgumentException
  */
 protected function createDatabase(InputInterface $input, OutputInterface $output)
 {
     $dbOptions = array('--dbHost', '--dbUser', '--dbPass', '--dbName');
     $dbOptionsFound = 0;
     foreach ($dbOptions as $dbOption) {
         foreach ($this->getCliArguments() as $definedCliOption) {
             if (String::startsWith($definedCliOption, $dbOption)) {
                 $dbOptionsFound++;
             }
         }
     }
     $hasAllOptions = $dbOptionsFound == 4;
     // if all database options were passed in at cmd line
     if ($hasAllOptions) {
         $this->config['db_host'] = $input->getOption('dbHost');
         $this->config['db_user'] = $input->getOption('dbUser');
         $this->config['db_pass'] = $input->getOption('dbPass');
         $this->config['db_name'] = $input->getOption('dbName');
         $this->config['db_port'] = $input->getOption('dbPort');
         $db = $this->validateDatabaseSettings($output, $input);
         if ($db === false) {
             throw new \InvalidArgumentException("Database configuration is invalid", null);
         }
     } else {
         $dialog = $this->getHelperSet()->get('dialog');
         do {
             $this->config['db_host'] = $dialog->askAndValidate($output, '<question>Please enter the database host:</question> <comment>[localhost]</comment>: ', $this->notEmptyCallback, false, 'localhost');
             $this->config['db_user'] = $dialog->askAndValidate($output, '<question>Please enter the database username:</question> ', $this->notEmptyCallback);
             $this->config['db_pass'] = $dialog->ask($output, '<question>Please enter the database password:</question> ');
             $this->config['db_name'] = $dialog->askAndValidate($output, '<question>Please enter the database name:</question> ', $this->notEmptyCallback);
             $this->config['db_port'] = $dialog->askAndValidate($output, '<question>Please enter the database port:</question> <comment>[3306]</comment>: ', $this->notEmptyCallback, false, 3306);
             $db = $this->validateDatabaseSettings($output, $input);
         } while ($db === false);
     }
     $this->config['db'] = $db;
 }
Ejemplo n.º 5
0
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (String::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
Ejemplo n.º 6
0
 /**
  * @param OutputInterface $output
  * @param string $commandString
  * @throws \RuntimeException
  * @return void
  */
 protected function registerVariable(OutputInterface $output, $commandString)
 {
     if (preg_match('/^(\\$\\{[a-zA-Z0-9-_.]+\\})=(.+)/', $commandString, $matches)) {
         if (isset($matches[2]) && $matches[2][0] == '?') {
             // Variable is already defined
             if (isset($this->scriptVars[$matches[1]])) {
                 return $this->scriptVars[$matches[1]];
             }
             $dialog = $this->getHelperSet()->get('dialog');
             /* @var $dialog DialogHelper */
             /**
              * Check for select "?["
              */
             if (isset($matches[2][1]) && $matches[2][1] == '[') {
                 if (preg_match('/\\[(.+)\\]/', $matches[2], $choiceMatches)) {
                     $choices = String::trimExplodeEmpty(',', $choiceMatches[1]);
                     $selectedIndex = $dialog->select($output, '<info>Please enter a value for <comment>' . $matches[1] . '</comment>:</info> ', $choices);
                     $this->scriptVars[$matches[1]] = $choices[$selectedIndex];
                 } else {
                     throw new \RuntimeException('Invalid choices');
                 }
             } else {
                 // normal input
                 $this->scriptVars[$matches[1]] = $dialog->askAndValidate($output, '<info>Please enter a value for <comment>' . $matches[1] . '</comment>:</info> ', function ($value) {
                     if ($value == '') {
                         throw new \Exception('Please enter a value');
                     }
                     return $value;
                 });
             }
         } else {
             $this->scriptVars[$matches[1]] = $this->_replaceScriptVars($matches[2]);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (String::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
         if ($path === "") {
             throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file));
         }
         if ($path === false) {
             $this->_output->writeln(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     if ($localPluginConfig === false) {
         $this->_output->writeln(sprintf("<error>Failed to read from plugin config file '%s'</error>", $file));
     }
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
Ejemplo n.º 8
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @return \Symfony\Component\Console\Input\ArgvInput|\Symfony\Component\Console\Input\InputInterface
  */
 protected function checkConfigCommandAlias(InputInterface $input)
 {
     if ($this->hasConfigCommandAliases()) {
         foreach ($this->config['commands']['aliases'] as $alias) {
             if (is_array($alias)) {
                 $aliasCommandName = key($alias);
                 if ($input->getFirstArgument() == $aliasCommandName) {
                     $aliasCommandParams = array_slice(String::trimExplodeEmpty(' ', $alias[$aliasCommandName]), 1);
                     if (count($aliasCommandParams) > 0) {
                         // replace with aliased data
                         $mergedParams = array_merge(array_slice($_SERVER['argv'], 0, 2), $aliasCommandParams, array_slice($_SERVER['argv'], 2));
                         $input = new ArgvInput($mergedParams);
                     }
                 }
             }
         }
         return $input;
     }
     return $input;
 }