Example #1
0
 /**
  * @return void
  */
 public function execute()
 {
     $this->notEmptyCallback = function ($input) {
         if (empty($input)) {
             throw new \InvalidArgumentException('Please enter a value');
         }
         return $input;
     };
     $dbOptions = array('--dbHost', '--dbUser', '--dbPass', '--dbName');
     $dbOptionsFound = 0;
     foreach ($dbOptions as $dbOption) {
         foreach ($this->getCliArguments() as $definedCliOption) {
             if (BinaryString::startsWith($definedCliOption, $dbOption)) {
                 $dbOptionsFound++;
             }
         }
     }
     $hasAllOptions = $dbOptionsFound == 4;
     // if all database options were passed in at cmd line
     if ($hasAllOptions) {
         $this->config->setString('db_host', $this->input->getOption('dbHost'));
         $this->config->setString('db_user', $this->input->getOption('dbUser'));
         $this->config->setString('db_pass', $this->input->getOption('dbPass'));
         $this->config->setString('db_name', $this->input->getOption('dbName'));
         $this->config->setInt('db_port', intval($this->input->getOption('dbPort')));
         $db = $this->validateDatabaseSettings($this->input, $this->output);
         if ($db === false) {
             throw new \InvalidArgumentException("Database configuration is invalid", null);
         }
     } else {
         $dialog = $this->getCommand()->getHelperSet()->get('dialog');
         do {
             // Host
             $dbHostDefault = $this->input->getOption('dbHost') ? $this->input->getOption('dbHost') : 'localhost';
             $this->config->setString('db_host', $dialog->askAndValidate($this->output, '<question>Please enter the database host</question> <comment>[' . $dbHostDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbHostDefault));
             // Port
             $dbPortDefault = $this->input->getOption('dbPort') ? $this->input->getOption('dbPort') : 3306;
             $this->config->setInt('db_port', intval($dialog->askAndValidate($this->output, '<question>Please enter the database port </question> <comment>[' . $dbPortDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbPortDefault)));
             // User
             $dbUserDefault = $this->input->getOption('dbUser') ? $this->input->getOption('dbUser') : 'root';
             $this->config->setString('db_user', $dialog->askAndValidate($this->output, '<question>Please enter the database username</question> <comment>[' . $dbUserDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbUserDefault));
             // Password
             $dbPassDefault = $this->input->getOption('dbPass') ? $this->input->getOption('dbPass') : '';
             $this->config->setString('db_pass', $dialog->ask($this->output, '<question>Please enter the database password</question> <comment>[' . $dbPassDefault . ']</comment>: ', $dbPassDefault));
             // DB-Name
             $dbNameDefault = $this->input->getOption('dbName') ? $this->input->getOption('dbName') : 'magento';
             $this->config->setString('db_name', $dialog->askAndValidate($this->output, '<question>Please enter the database name</question> <comment>[' . $dbNameDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbNameDefault));
             $db = $this->validateDatabaseSettings($this->input, $this->output);
         } while ($db === false);
     }
     $this->config->setObject('db', $db);
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if ($this->initMagento()) {
         $codeArgument = BinaryString::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>');
         }
     }
 }
Example #3
0
 /**
  * alias magerun command in input from config
  *
  * @param InputInterface $input
  * @return ArgvInput|InputInterface
  */
 public function checkConfigCommandAlias(InputInterface $input)
 {
     foreach ($this->getArray(array('commands', 'aliases')) as $alias) {
         if (!is_array($alias)) {
             continue;
         }
         $aliasCommandName = key($alias);
         if ($input->getFirstArgument() !== $aliasCommandName) {
             continue;
         }
         $aliasCommandParams = array_slice(BinaryString::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;
 }
Example #4
0
 /**
  * Returns the composer config key -> Composer passed json data
  *
  * @param string $key
  * @param bool $useGlobalConfig
  * @return string|object
  */
 public function getConfigValue($key, $useGlobalConfig = true)
 {
     $jsonCode = '';
     $commandArgs = [];
     if ($useGlobalConfig) {
         $commandArgs[] = 'global';
     }
     $commandArgs[] = 'config';
     $commandArgs[] = $key;
     try {
         $composerOutput = $this->run($commandArgs, true);
         $lines = explode(PHP_EOL, $composerOutput);
         foreach ($lines as $line) {
             if (BinaryString::startsWith($line, 'Changed current directory to')) {
                 continue;
             }
             $jsonCode .= $line;
         }
     } catch (\Exception $e) {
         $jsonCode = 'false';
     }
     return json_decode($jsonCode);
 }
Example #5
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output, true);
     if (!$this->initMagento()) {
         return;
     }
     $codeArgument = BinaryString::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>');
     }
 }
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::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->log(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     $this->logDebug('Load plugin config <comment>' . $path . '</comment>');
     $localPluginConfigFile = ConfigFile::createFromFile($path);
     $localPluginConfigFile->applyVariables($magentoRootFolder, $file);
     $this->_pluginConfig = $localPluginConfigFile->mergeArray($this->_pluginConfig);
 }
Example #7
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 (BinaryString::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');
         $this->config['db_prefix'] = $input->getOption('dbPrefix');
         $db = $this->validateDatabaseSettings($output, $input);
         if ($db === false) {
             throw new InvalidArgumentException("Database configuration is invalid");
         }
     } else {
         $dialog = $this->getHelperSet()->get('dialog');
         do {
             $dbHostDefault = $input->getOption('dbHost') ? $input->getOption('dbHost') : 'localhost';
             $this->config['db_host'] = $dialog->askAndValidate($output, '<question>Please enter the database host</question> <comment>[' . $dbHostDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbHostDefault);
             $dbUserDefault = $input->getOption('dbUser') ? $input->getOption('dbUser') : 'root';
             $this->config['db_user'] = $dialog->askAndValidate($output, '<question>Please enter the database username</question> <comment>[' . $dbUserDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbUserDefault);
             $dbPassDefault = $input->getOption('dbPass') ? $input->getOption('dbPass') : '';
             $this->config['db_pass'] = $dialog->ask($output, '<question>Please enter the database password</question> <comment>[' . $dbPassDefault . ']</comment>: ', $dbPassDefault);
             $dbNameDefault = $input->getOption('dbName') ? $input->getOption('dbName') : 'magento';
             $this->config['db_name'] = $dialog->askAndValidate($output, '<question>Please enter the database name</question> <comment>[' . $dbNameDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbNameDefault);
             $dbPortDefault = $input->getOption('dbPort') ? $input->getOption('dbPort') : 3306;
             $this->config['db_port'] = $dialog->askAndValidate($output, '<question>Please enter the database port </question> <comment>[' . $dbPortDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbPortDefault);
             $dbPrefixDefault = $input->getOption('dbPrefix') ? $input->getOption('dbPrefix') : '';
             $this->config['db_prefix'] = $dialog->ask($output, '<question>Please enter the table prefix</question> <comment>[' . $dbPrefixDefault . ']</comment>:', $dbPrefixDefault);
             $db = $this->validateDatabaseSettings($output, $input);
         } while ($db === false);
     }
     $this->config['db'] = $db;
 }
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::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);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
Example #9
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]];
             }
             /* @var $dialog DialogHelper */
             $dialog = $this->getHelper('dialog');
             /**
              * Check for select "?["
              */
             if (isset($matches[2][1]) && $matches[2][1] == '[') {
                 if (preg_match('/\\[(.+)\\]/', $matches[2], $choiceMatches)) {
                     $choices = BinaryString::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 RuntimeException('Please enter a value');
                     }
                     return $value;
                 });
             }
         } else {
             $this->scriptVars[$matches[1]] = $this->_replaceScriptVars($matches[2]);
         }
     }
 }
 /**
  * @param InputInterface  $input
  * @param 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\BinaryString::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\BinaryString::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');
             }
         }
     }
 }