run() public static method

public static run ( string $command, string &$output = null, integer &$returnCode = null )
$command string
$output string
$returnCode integer
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws RuntimeException
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $opener = '';
     if (OperatingSystem::isMacOs()) {
         $opener = 'open';
     } elseif (OperatingSystem::isWindows()) {
         $opener = 'start';
     } else {
         // Linux
         if (exec('which xde-open')) {
             $opener = 'xdg-open';
         } elseif (exec('which gnome-open')) {
             $opener = 'gnome-open';
         } elseif (exec('which kde-open')) {
             $opener = 'kde-open';
         }
     }
     if (empty($opener)) {
         throw new RuntimeException('No opener command like xde-open, gnome-open, kde-open was found.');
     }
     $this->detectMagento($output);
     if ($this->initMagento($output)) {
         $store = $this->getHelperSet()->get('parameter')->askStore($input, $output, 'store', true);
         if ($store->getId() == Store::DEFAULT_STORE_ID) {
             $url = $this->getBackendStoreUrl($store);
         } else {
             $url = $this->getFrontendStoreUrl($store);
         }
         $output->writeln('Opening URL <comment>' . $url . '</comment> in browser');
         Exec::run(escapeshellcmd($opener . ' ' . $url));
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws RuntimeException
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $opener = '';
     if (OperatingSystem::isMacOs()) {
         $opener = 'open';
     } elseif (OperatingSystem::isWindows()) {
         $opener = 'start';
     } else {
         // Linux
         if (exec('which xde-open')) {
             $opener = 'xdg-open';
         } elseif (exec('which gnome-open')) {
             $opener = 'gnome-open';
         } elseif (exec('which kde-open')) {
             $opener = 'kde-open';
         }
     }
     if (empty($opener)) {
         throw new RuntimeException('No opener command like xde-open, gnome-open, kde-open was found.');
     }
     $this->detectMagento($output);
     if ($this->initMagento($output)) {
         $store = $this->getHelperSet()->get('parameter')->askStore($input, $output, 'store', true);
         if ($store->getId() == \Mage_Core_Model_App::ADMIN_STORE_ID) {
             $adminFrontName = (string) \Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
             $url = rtrim($store->getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_WEB), '/') . '/' . $adminFrontName;
         } else {
             $url = $store->getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_LINK) . '?___store=' . $store->getCode();
         }
         $output->writeln('Opening URL <comment>' . $url . '</comment> in browser');
         Exec::run(escapeshellcmd($opener . ' ' . $url));
     }
 }
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->detectDbSettings($output);
     $query = $this->getOrAskForArgument('query', $input, $output, 'SQL Query');
     $query = $this->getEscapedSql($query);
     $exec = 'mysql ' . $this->getMysqlClientToolConnectionString() . " -e '" . $query . "'";
     if ($input->getOption('only-command')) {
         $output->writeln($exec);
     } else {
         Exec::run($exec, $commandOutput, $returnValue);
         $output->writeln($commandOutput);
         if ($returnValue > 0) {
             $output->writeln('<error>' . $commandOutput . '</error>');
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectDbSettings($output);
     $query = $this->getOrAskForArgument('query', $input, $output, 'SQL Query');
     /** @var $helper \N98\Util\Console\Helper\DatabaseHelper */
     $helper = $this->getHelper('database');
     $exec = sprintf('mysql %s -e %s', $helper->getMysqlClientToolConnectionString(), escapeshellarg($query));
     if ($input->getOption('only-command')) {
         $output->writeln($exec);
     } else {
         Exec::run($exec, $commandOutput, $returnValue);
         $output->writeln($commandOutput);
         if ($returnValue > 0) {
             $output->writeln('<error>' . $commandOutput . '</error>');
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws RuntimeException
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     if (!$this->initMagento()) {
         return;
     }
     $store = $this->getHelper('parameter')->askStore($input, $output, 'store', true);
     if ($store->getId() == \Mage_Core_Model_App::ADMIN_STORE_ID) {
         $adminFrontName = (string) \Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
         $url = rtrim($store->getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_WEB), '/') . '/' . $adminFrontName;
     } else {
         $url = $store->getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_LINK) . '?___store=' . $store->getCode();
     }
     $output->writeln('Opening URL <comment>' . $url . '</comment> in browser');
     $opener = $this->resolveOpenerCommand($output);
     Exec::run(escapeshellcmd($opener . ' ' . $url));
 }
Ejemplo n.º 6
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws RuntimeException
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     if (!$this->initMagento()) {
         return;
     }
     /** @var $parameter ParameterHelper */
     $parameter = $this->getHelper('parameter');
     $store = $parameter->askStore($input, $output, 'store', true);
     if ($store->getId() == Store::DEFAULT_STORE_ID) {
         $url = $this->getBackendStoreUrl($store);
     } else {
         $url = $this->getFrontendStoreUrl($store);
     }
     $output->writeln('Opening URL <comment>' . $url . '</comment> in browser');
     $opener = $this->resolveOpenerCommand($output);
     Exec::run(escapeshellcmd($opener . ' ' . $url));
 }
Ejemplo n.º 7
0
 /**
  * @param string[] $execs
  * @param string $fileName
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 private function runExecs(array $execs, $fileName, InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('only-command') && !$input->getOption('print-only-filename')) {
         foreach ($execs as $exec) {
             $output->writeln($exec);
         }
     } else {
         if (!$input->getOption('stdout') && !$input->getOption('only-command') && !$input->getOption('print-only-filename')) {
             $output->writeln('<comment>Start dumping database <info>' . $this->dbSettings['dbname'] . '</info> to file <info>' . $fileName . '</info>');
         }
         if ($input->getOption('dry-run')) {
             $execs = array();
         }
         foreach ($execs as $exec) {
             $commandOutput = '';
             if ($input->getOption('stdout')) {
                 passthru($exec, $returnValue);
             } else {
                 Exec::run($exec, $commandOutput, $returnValue);
             }
             if ($returnValue > 0) {
                 $output->writeln('<error>' . $commandOutput . '</error>');
                 $output->writeln('<error>Return Code: ' . $returnValue . '. ABORTED.</error>');
                 return;
             }
         }
         if (!$input->getOption('stdout') && !$input->getOption('print-only-filename')) {
             $output->writeln('<info>Finished</info>');
         }
     }
     if ($input->getOption('print-only-filename')) {
         $output->writeln($fileName);
     }
 }
Ejemplo n.º 8
0
 /**
  * @param OutputInterface $output
  * @param string          $fileName
  * @param string          $exec
  *
  * @return void
  */
 protected function doImport(OutputInterface $output, $fileName, $exec)
 {
     $returnValue = null;
     $commandOutput = null;
     $output->writeln('<comment>Importing SQL dump <info>' . $fileName . '</info> to database <info>' . $this->dbSettings['dbname'] . '</info>');
     Exec::run($exec, $commandOutput, $returnValue);
     if ($returnValue != 0) {
         $output->writeln('<error>' . $commandOutput . '</error>');
     }
     $output->writeln('<info>Finished</info>');
 }
Ejemplo n.º 9
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return array
  * @throws InvalidArgumentException parameter mismatch (e.g. base-url components like hostname)
  * @throws RuntimeException
  */
 protected function installMagento(InputInterface $input, OutputInterface $output)
 {
     $this->getApplication()->setAutoExit(false);
     $dialog = $this->getHelperSet()->get('dialog');
     $defaults = $this->commandConfig['installation']['defaults'];
     $useDefaultConfigParams = $this->_parseBoolOption($input->getOption('useDefaultConfigParams'));
     $sessionSave = $useDefaultConfigParams ? $defaults['session_save'] : $dialog->ask($output, '<question>Please enter the session save:</question> <comment>[' . $defaults['session_save'] . ']</comment>: ', $defaults['session_save']);
     $adminFrontname = $useDefaultConfigParams ? $defaults['admin_frontname'] : $dialog->askAndValidate($output, '<question>Please enter the admin frontname:</question> <comment>[' . $defaults['admin_frontname'] . ']</comment> ', $this->notEmptyCallback, false, $defaults['admin_frontname']);
     $currency = $useDefaultConfigParams ? $defaults['currency'] : $dialog->askAndValidate($output, '<question>Please enter the default currency code:</question> <comment>[' . $defaults['currency'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['currency']);
     $locale = $useDefaultConfigParams ? $defaults['locale'] : $dialog->askAndValidate($output, '<question>Please enter the locale code:</question> <comment>[' . $defaults['locale'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['locale']);
     $timezone = $useDefaultConfigParams ? $defaults['timezone'] : $dialog->askAndValidate($output, '<question>Please enter the timezone:</question> <comment>[' . $defaults['timezone'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['timezone']);
     $adminUsername = $useDefaultConfigParams ? $defaults['admin_username'] : $dialog->askAndValidate($output, '<question>Please enter the admin username:</question> <comment>[' . $defaults['admin_username'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_username']);
     $adminPassword = $useDefaultConfigParams ? $defaults['admin_password'] : $dialog->askAndValidate($output, '<question>Please enter the admin password:</question> <comment>[' . $defaults['admin_password'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_password']);
     $adminFirstname = $useDefaultConfigParams ? $defaults['admin_firstname'] : $dialog->askAndValidate($output, '<question>Please enter the admin\'s firstname:</question> <comment>[' . $defaults['admin_firstname'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_firstname']);
     $adminLastname = $useDefaultConfigParams ? $defaults['admin_lastname'] : $dialog->askAndValidate($output, '<question>Please enter the admin\'s lastname:</question> <comment>[' . $defaults['admin_lastname'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_lastname']);
     $adminEmail = $useDefaultConfigParams ? $defaults['admin_email'] : $dialog->askAndValidate($output, '<question>Please enter the admin\'s email:</question> <comment>[' . $defaults['admin_email'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_email']);
     $validateBaseUrl = function ($input) {
         if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $input)) {
             throw new InvalidArgumentException('Please enter a valid URL');
         }
         if (parse_url($input, \PHP_URL_HOST) == 'localhost') {
             throw new InvalidArgumentException('localhost cause problems! Please use 127.0.0.1 or another hostname');
         }
         return $input;
     };
     $baseUrl = $input->getOption('baseUrl') !== null ? $input->getOption('baseUrl') : $dialog->askAndValidate($output, '<question>Please enter the base url:</question> ', $validateBaseUrl, false);
     $baseUrl = rtrim($baseUrl, '/') . '/';
     // normalize baseUrl
     /**
      * Correct session save (common mistake)
      */
     if ($sessionSave == 'file') {
         $sessionSave = 'files';
     }
     /**
      * Try to create session folder
      */
     $defaultSessionFolder = $this->config['installationFolder'] . DIRECTORY_SEPARATOR . 'var/session';
     if ($sessionSave == 'files' && !is_dir($defaultSessionFolder)) {
         @mkdir($defaultSessionFolder);
     }
     $dbHost = $this->config['db_host'];
     if ($this->config['db_port'] != 3306) {
         $dbHost .= ':' . $this->config['db_port'];
     }
     $argv = array('license_agreement_accepted' => 'yes', 'locale' => $locale, 'timezone' => $timezone, 'db_host' => $dbHost, 'db_name' => $this->config['db_name'], 'db_user' => $this->config['db_user'], 'db_pass' => $this->config['db_pass'], 'db_prefix' => $this->config['db_prefix'], 'url' => $baseUrl, 'use_rewrites' => 'yes', 'use_secure' => 'no', 'secure_base_url' => '', 'use_secure_admin' => 'no', 'admin_username' => $adminUsername, 'admin_lastname' => $adminLastname, 'admin_firstname' => $adminFirstname, 'admin_email' => $adminEmail, 'admin_password' => $adminPassword, 'session_save' => $sessionSave, 'admin_frontname' => $adminFrontname, 'backend_frontname' => $adminFrontname, 'default_currency' => $currency, 'skip_url_validation' => 'yes');
     if ($useDefaultConfigParams) {
         if (strlen($defaults['encryption_key']) > 0) {
             $argv['encryption_key'] = $defaults['encryption_key'];
         }
         if (strlen($defaults['use_secure']) > 0) {
             $argv['use_secure'] = $defaults['use_secure'];
             $argv['secure_base_url'] = str_replace('http://', 'https://', $baseUrl);
         }
         if (strlen($defaults['use_rewrites']) > 0) {
             $argv['use_rewrites'] = $defaults['use_rewrites'];
         }
     }
     $installArgs = '';
     foreach ($argv as $argName => $argValue) {
         $installArgs .= '--' . $argName . ' ' . escapeshellarg($argValue) . ' ';
     }
     $output->writeln('<info>Start installation process.</info>');
     if (OperatingSystem::isWindows()) {
         $installCommand = 'php -f ' . escapeshellarg($this->getInstallScriptPath()) . ' -- ' . $installArgs;
     } else {
         $installCommand = '/usr/bin/env php -f ' . escapeshellarg($this->getInstallScriptPath()) . ' -- ' . $installArgs;
     }
     $output->writeln('<comment>' . $installCommand . '</comment>');
     Exec::run($installCommand, $installationOutput, $returnStatus);
     if ($returnStatus !== self::EXEC_STATUS_OK) {
         $this->getApplication()->setAutoExit(true);
         throw new RuntimeException('Installation failed.' . $installationOutput, 1);
     } else {
         $output->writeln('<info>Successfully installed Magento</info>');
         $encryptionKey = trim(substr($installationOutput, strpos($installationOutput, ':') + 1));
         $output->writeln('<comment>Encryption Key:</comment> <info>' . $encryptionKey . '</info>');
     }
     $dialog = $this->getHelperSet()->get('dialog');
     /**
      * Htaccess file
      */
     if ($input->getOption('useDefaultConfigParams') == null || $input->getOption('replaceHtaccessFile') != null) {
         $replaceHtaccessFile = false;
         if ($this->_parseBoolOption($input->getOption('replaceHtaccessFile'))) {
             $replaceHtaccessFile = true;
         } elseif ($dialog->askConfirmation($output, '<question>Write BaseURL to .htaccess file?</question> <comment>[n]</comment>: ', false)) {
             $replaceHtaccessFile = true;
         }
         if ($replaceHtaccessFile) {
             $this->replaceHtaccessFile($baseUrl);
         }
     }
     \chdir($this->config['installationFolder']);
     $this->getApplication()->reinit();
     $output->writeln('<info>Reindex all after installation</info>');
     $this->getApplication()->run(new StringInput('index:reindex:all'), $output);
     $this->getApplication()->run(new StringInput('sys:check'), $output);
     $output->writeln('<info>Successfully installed magento</info>');
 }
Ejemplo n.º 10
0
 /**
  * @test
  *
  * @expectedException RuntimeException
  */
 public function exception()
 {
     Exec::run('foobar');
 }
Ejemplo n.º 11
0
 /**
  * Invoke Magento PHP install script shell/install.php
  *
  * @param OutputInterface $output
  * @param string $installationFolder folder where magento is installed in, must exists setup script in
  * @param array $argv
  * @return void
  */
 private function runInstallScriptCommand(OutputInterface $output, $installationFolder, array $argv)
 {
     $installArgs = '';
     foreach ($argv as $argName => $argValue) {
         $installArgs .= '--' . $argName . ' ' . escapeshellarg($argValue) . ' ';
     }
     $output->writeln('<info>Start installation process.</info>');
     $installCommand = sprintf('%s -ddisplay_startup_errors=1 -ddisplay_errors=1 -derror_reporting=-1 -f %s -- %s', OperatingSystem::getPhpBinary(), escapeshellarg($installationFolder . '/' . self::MAGENTO_INSTALL_SCRIPT_PATH), $installArgs);
     $output->writeln('<comment>' . $installCommand . '</comment>');
     $installException = null;
     $installationOutput = null;
     $returnStatus = null;
     try {
         Exec::run($installCommand, $installationOutput, $returnStatus);
     } catch (Exception $installException) {
     }
     if (isset($installException) || $returnStatus !== Exec::CODE_CLEAN_EXIT) {
         $this->getApplication()->setAutoExit(true);
         throw new RuntimeException(sprintf('Installation failed (Exit code %s). %s', $returnStatus, $installationOutput), 1, $installException);
     }
     $output->writeln('<info>Successfully installed Magento</info>');
     $encryptionKey = trim(substr(strstr($installationOutput, ':'), 1));
     $output->writeln('<comment>Encryption Key:</comment> <info>' . $encryptionKey . '</info>');
 }