/** * @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)); } }
protected function runSampleDataInstaller() { $installationArgs = $this->config->getArray('installation_args'); $processBuilder = new ProcessBuilder(['php', 'bin/magento', 'sampledata:deploy']); if (!OperatingSystem::isWindows()) { $processBuilder->setPrefix('/usr/bin/env'); } $process = $processBuilder->getProcess(); $process->setTimeout(86400); $process->start(); $process->wait(function ($type, $buffer) { $this->output->write($buffer, false); }); // @TODO Refactor code duplication if (!OperatingSystem::isWindows()) { $processBuilder->setPrefix('/usr/bin/env'); } $processBuilder = new ProcessBuilder(array('php', 'bin/magento', 'setup:upgrade')); $process = $processBuilder->getProcess(); $process->setTimeout(86400); $process->start(); $process->wait(function ($type, $buffer) { $this->output->write($buffer, false); }); }
/** * @param OutputInterface $output * @return string */ private function resolveOpenerCommand(OutputInterface $output) { $opener = ''; if (OperatingSystem::isMacOs()) { $opener = 'open'; } elseif (OperatingSystem::isWindows()) { $opener = 'start'; } else { // Linux if (exec('which xdg-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 xdg-open, gnome-open, kde-open was found.'); } if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) { $message = sprintf('open command is "%s"', $opener); $output->writeln('<debug>' . $message . '</debug>'); } return $opener; }
/** * @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)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $this->detectMagento($output); if (!$this->initMagento()) { return; } // this command will not run on windows. if (OperatingSystem::isWindows()) { $output->writeln('<error>This command is not compatible with windows.</error>'); return; } $this->writeSection($output, 'Top log messages.'); $logPath = $this->findLogPath($input->getOption('log')); if ($logPath) { $process = new Process("cut -d ' ' -f 2- " . $logPath . " | sort | uniq -c | sort -n -k 1 | tail -" . $input->getArgument('top') . ""); $process->run(function ($type, $buffer) { if (Process::STATUS_READY) { $this->_result = $buffer; } }); $results = array_reverse(array_filter(explode("\n", $this->_result))); $i = 1; foreach ($results as $result) { $output->writeln('<comment>' . $i . '.</comment>' . " : " . $result); $i++; } } else { $output->writeln('<error>Could not find the path to the system.log</error>'); } }
/** * @return bool */ public function isEnabled() { if (OperatingSystem::isWindows()) { return false; } if ($this->getApplication()->isPharMode()) { $pharFile = $_SERVER['argv'][0]; return substr($pharFile, -5) == '.phar'; } return true; }
/** * @return void */ private function runMagentoCommand($command) { $processBuilder = new ProcessBuilder(['php', 'bin/magento', $command]); if (!OperatingSystem::isWindows()) { $processBuilder->setPrefix('/usr/bin/env'); } $process = $processBuilder->getProcess(); $process->setTimeout(86400); $process->start(); $process->wait(function ($type, $buffer) { $this->output->write('bin/magento > ' . $buffer, false); }); }
/** * Display a warning if a running n98-magerun as root user * * @param Event $event * @return void */ public function checkRunningAsRootUser(Event $event) { if ($this->_isSkipRootCheck($event->getInput())) { return; } $config = $event->getApplication()->getConfig(); if (!$config['application']['check-root-user']) { return; } if (OperatingSystem::isRoot()) { $output = $event->getOutput(); $output->writeln(array('', self::WARNING_ROOT_USER, '')); } }
/** * Display a warning if a running n98-magerun as root user * * @param ConsoleEvent $event * @return void */ public function checkRunningAsRootUser(ConsoleEvent $event) { $output = $event->getOutput(); if ($output instanceof ConsoleOutput) { $errorOutput = $output->getErrorOutput(); if (OperatingSystem::isLinux() || OperatingSystem::isMacOs()) { if (function_exists('posix_getuid')) { if (posix_getuid() === 0) { $errorOutput->writeln(''); $errorOutput->writeln(self::WARNING_ROOT_USER); $errorOutput->writeln(''); } } } } }
/** * @param array $scriptFolders * @param string $magentoRootFolder */ public function __construct(array $scriptFolders, $magentoRootFolder = null) { $this->_magentoRootFolder = $magentoRootFolder; if (OperatingSystem::isWindows()) { $this->_homeScriptFolder = OperatingSystem::getHomeDir() . '/n98-magerun2/scripts'; } else { $this->_homeScriptFolder = OperatingSystem::getHomeDir() . '/.n98-magerun2/scripts'; } $this->_scriptFolders = $scriptFolders; $this->_scriptFolders[] = $this->_homeScriptFolder; foreach ($this->_scriptFolders as $key => $scriptFolder) { if (!is_dir($scriptFolder)) { unset($this->_scriptFolders[$key]); } } if (count($this->_scriptFolders)) { $this->findScripts(); } }
/** * Display a warning if a running n98-magerun as root user * * @param ConsoleEvent $event * @return void */ public function checkRunningAsRootUser(Event $event) { if ($this->_isSkipRootCheck()) { return; } $config = $event->getApplication()->getConfig(); if (!$config['application']['check-root-user']) { return; } $output = $event->getOutput(); if (OperatingSystem::isLinux() || OperatingSystem::isMacOs()) { if (function_exists('posix_getuid')) { if (posix_getuid() === 0) { $output->writeln(''); $output->writeln(self::WARNING_ROOT_USER); $output->writeln(''); } } } }
/** * @return string * @throws \Exception */ protected function downloadComposer() { $this->output->writeln('<info>Could not find composer. Try to download it.</info>'); $io = new ConsoleIO($this->input, $this->output, $this->getCommand()->getHelperSet()); $rfs = new RemoteFilesystem($io); $composerInstaller = $rfs->getContents('getcomposer.org', 'https://getcomposer.org/installer', true); $tempComposerInstaller = $this->config['installationFolder'] . '/_composer_installer.php'; file_put_contents($tempComposerInstaller, $composerInstaller); if (OperatingSystem::isWindows()) { $installCommand = 'php ' . $tempComposerInstaller . ' --force'; } else { $installCommand = '/usr/bin/env php ' . $tempComposerInstaller . ' --force'; } $this->output->writeln('<comment>' . $installCommand . '</comment>'); exec($installCommand, $installationOutput, $returnStatus); unlink($tempComposerInstaller); $installationOutput = implode(PHP_EOL, $installationOutput); if ($returnStatus !== self::EXEC_STATUS_OK) { throw new \Exception('Installation failed.' . $installationOutput); } else { $this->output->writeln('<info>Successfully installed composer to Magento root</info>'); } return $this->config['installationFolder'] . '/composer.phar'; }
/** * @return string */ protected function _checkRootDirOption() { $specialGlobalOptions = getopt('', array('root-dir:')); if (count($specialGlobalOptions) > 0) { if (isset($specialGlobalOptions['root-dir'][0]) && $specialGlobalOptions['root-dir'][0] == '~') { $specialGlobalOptions['root-dir'] = OperatingSystem::getHomeDir() . substr($specialGlobalOptions['root-dir'], 1); } $folder = realpath($specialGlobalOptions['root-dir']); $this->_directRootDir = true; if (is_dir($folder)) { \chdir($folder); return; } } }
public function operatingSystemIsNotWindows() { $this->assert(!OperatingSystem::isWindows(), "operating system is windows"); }
/** * @return bool */ public function isEnabled() { return function_exists('exec') && !OperatingSystem::isWindows(); }
/** * Check if there is a user config file. ~/.n98-magerun.yaml * * @param array $config * @param string $magentoRootFolder * * @return array */ public function loadUserConfig($config, $magentoRootFolder = null) { if ($this->_userConfig == null) { $this->_userConfig = array(); $homeDirectory = OperatingSystem::getHomeDir(); if (OperatingSystem::isWindows()) { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . $this->_customConfigFilename; } else { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . '.' . $this->_customConfigFilename; } if ($homeDirectory && file_exists($personalConfigFile)) { $userConfig = $this->applyVariables(\file_get_contents($personalConfigFile), $magentoRootFolder, null); $this->_userConfig = Yaml::parse($userConfig); return $config; } } $config = ArrayFunctions::mergeArrays($config, $this->_userConfig); return $config; }
/** * @param InputInterface $input * @return string */ protected function _checkRootDirOption(InputInterface $input) { $definedRootDir = $input->getParameterOption('--root-dir'); if (!empty($definedRootDir)) { if ($definedRootDir[0] == '~') { $definedRootDir = OperatingSystem::getHomeDir() . substr($definedRootDir, 1); } $folder = realpath($definedRootDir); $this->_directRootDir = true; if (is_dir($folder)) { \chdir($folder); return; } } }
/** * Set root dir (chdir()) of magento directory * * @param string $path to Magento directory */ private function setRootDir($path) { if (isset($path[0]) && '~' === $path[0]) { $path = OperatingSystem::getHomeDir() . substr($path, 1); } $folder = realpath($path); $this->_directRootDir = true; if (is_dir($folder)) { chdir($folder); } }
/** * 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>'); }
/** * Check if there is a user config file. ~/.n98-magerun.yaml * * @param array $config * @param string $magentoRootFolder * * @return array */ public function loadUserConfig($config, $magentoRootFolder = null) { if ($this->_userConfig == null) { $this->_userConfig = array(); $homeDirectory = OperatingSystem::getHomeDir(); if (OperatingSystem::isWindows()) { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . $this->_customConfigFilename; } else { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . '.' . $this->_customConfigFilename; } if ($homeDirectory && file_exists($personalConfigFile)) { $userConfig = $this->applyVariables(\file_get_contents($personalConfigFile), $magentoRootFolder, null); $this->_userConfig = Yaml::parse($userConfig); if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) { $this->_output->writeln('<debug>Load user config <comment>' . $personalConfigFile . '</comment></debug>'); } return $config; } } $config = ArrayFunctions::mergeArrays($config, $this->_userConfig); return $config; }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function chooseInstallationFolder(InputInterface $input, OutputInterface $output) { /** * @param string $folderName * * @return string */ $validateInstallationFolder = function ($folderName) use($input) { $folderName = rtrim(trim($folderName, ' '), '/'); // resolve folder-name to current working directory if relative if (substr($folderName, 0, 1) == '.') { $cwd = OperatingSystem::getCwd(); $folderName = $cwd . substr($folderName, 1); } if (empty($folderName)) { throw new InvalidArgumentException('Installation folder cannot be empty'); } if (!is_dir($folderName)) { if (!@mkdir($folderName, 0777, true)) { throw new InvalidArgumentException('Cannot create folder.'); } return $folderName; } if ($input->hasOption('noDownload') && $input->getOption('noDownload')) { /** @var MagentoHelper $magentoHelper */ $magentoHelper = new MagentoHelper(); $magentoHelper->detect($folderName); if ($magentoHelper->getRootFolder() !== $folderName) { throw new InvalidArgumentException(sprintf('Folder %s is not a Magento working copy.', $folderName)); } $localXml = $folderName . '/app/etc/local.xml'; if (file_exists($localXml)) { throw new InvalidArgumentException(sprintf('Magento working copy in %s seems already installed. Please remove %s and retry.', $folderName, $localXml)); } } return $folderName; }; if (($installationFolder = $input->getOption('installationFolder')) == null) { $defaultFolder = './magento'; $question[] = "<question>Enter installation folder:</question> [<comment>" . $defaultFolder . "</comment>]"; $installationFolder = $this->getHelper('dialog')->askAndValidate($output, $question, $validateInstallationFolder, false, $defaultFolder); } else { // @Todo improve validation and bring it to 1 single function $installationFolder = $validateInstallationFolder($installationFolder); } $this->config['installationFolder'] = realpath($installationFolder); \chdir($this->config['installationFolder']); }
/** * @return array */ private function getUserConfigFilePaths() { $paths = array(); $homeDirectory = OperatingSystem::getHomeDir(); if (!strlen($homeDirectory)) { return $paths; } if (!is_dir($homeDirectory)) { throw new RuntimeException(sprintf("Home-directory '%s' is not a directory.", $homeDirectory)); } $basename = $this->customConfigFilename; if (OperatingSystem::isWindows()) { $paths[] = $homeDirectory . '/' . $basename; } $paths[] = $homeDirectory . '/.' . $basename; return $paths; }
/** * Returns the path to composer bin * * @return string */ public function getBinPath() { $composerBin = ''; if (OperatingSystem::isProgramInstalled('composer.phar')) { $composerBin = 'composer.phar'; } elseif (OperatingSystem::isProgramInstalled('composer')) { $composerBin = 'composer'; } elseif (OperatingSystem::isProgramInstalled('composer.bat')) { $composerBin = 'composer'; } return $composerBin; }
/** * @param InputInterface $input * @param OutputInterface $output * @throws \Exception * @return array */ 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); } $argv = array('license_agreement_accepted' => 'yes', 'locale' => $locale, 'timezone' => $timezone, 'db_host' => $this->config['db_host'], 'db_name' => $this->config['db_name'], 'db_user' => $this->config['db_user'], 'db_pass' => $this->config['db_pass'], '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 ' . $this->getInstallScriptPath() . ' ' . $installArgs; } else { $installCommand = '/usr/bin/env php ' . $this->getInstallScriptPath() . ' ' . $installArgs; } $output->writeln('<comment>' . $installCommand . '</comment>'); exec($installCommand, $installationOutput, $returnStatus); $installationOutput = implode(PHP_EOL, $installationOutput); if ($returnStatus !== self::EXEC_STATUS_OK) { throw new \Exception('Installation failed.' . $installationOutput); } 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>'); }
/** * Load config from all installed bundles * * @param array $config * @param string $magentoRootFolder * * @return array */ public function loadPluginConfig(array $config, $magentoRootFolder) { if ($this->_pluginConfig == null) { $this->_pluginConfig = array(); $moduleBaseFolders = array(); $customFilename = $this->_customConfigFilename; $customName = pathinfo($customFilename, PATHINFO_FILENAME); if (OperatingSystem::isWindows()) { $config['plugin']['folders'][] = getenv('WINDIR') . '/' . $customName . '/modules'; $config['plugin']['folders'][] = OperatingSystem::getHomeDir() . '/' . $customName . '/modules'; } else { $config['plugin']['folders'][] = OperatingSystem::getHomeDir() . '/.' . $customName . '/modules'; } $config['plugin']['folders'][] = $magentoRootFolder . '/lib/' . $customName . '/modules'; foreach ($config['plugin']['folders'] as $folder) { if (is_dir($folder)) { $moduleBaseFolders[] = $folder; } } /** * Allow modules to be placed vendor folder if not in phar mode */ if (!$this->_isPharMode) { if (is_dir($this->getVendorDir())) { $finder = Finder::create(); $finder->files()->depth(2)->followLinks()->ignoreUnreadableDirs(true)->name($customFilename)->in($this->getVendorDir()); foreach ($finder as $file) { /* @var $file SplFileInfo */ $this->registerPluginConfigFile($magentoRootFolder, $file); } } } if (count($moduleBaseFolders) > 0) { // Glob plugin folders $finder = Finder::create(); $finder->files()->depth(1)->followLinks()->ignoreUnreadableDirs(true)->name($customFilename)->in($moduleBaseFolders); foreach ($finder as $file) { /* @var $file SplFileInfo */ $this->registerPluginConfigFile($magentoRootFolder, $file); } } } $config = ArrayFunctions::mergeArrays($config, $this->_pluginConfig); return $config; }
/** * Check whether pv is installed * * @return bool */ protected function hasPipeViewer() { return OperatingSystem::isProgramInstalled('pv'); }
/** * @param string $installArgs * * @throws Exception */ protected function _runInstaller($installArgs) { $installationOutput = null; $returnStatus = null; if (OperatingSystem::isWindows()) { $installCommand = 'php ' . $this->getInstallScriptPath() . ' setup:install ' . $installArgs; } else { $installCommand = '/usr/bin/env php ' . $this->getInstallScriptPath() . ' setup:install ' . $installArgs; } $this->output->writeln('<comment>' . $installCommand . '</comment>'); exec($installCommand, $installationOutput, $returnStatus); $installationOutput = implode(PHP_EOL, $installationOutput); if ($returnStatus !== self::EXEC_STATUS_OK) { throw new \RuntimeException('Installation failed.' . $installationOutput, 1); } else { $this->output->writeln('<info>Successfully installed Magento</info>'); $encryptionKey = trim(substr($installationOutput, strpos($installationOutput, ':') + 1)); $this->output->writeln('<comment>Encryption Key:</comment> <info>' . $encryptionKey . '</info>'); } }
/** * @return string */ private function getUserConfigFilePath() { $homeDirectory = OperatingSystem::getHomeDir(); if (!$homeDirectory) { throw new RuntimeException('Unable to get home-directory to obtain user-config-file.'); } if (!is_dir($homeDirectory)) { throw new RuntimeException(sprintf("Home-directory '%s' is not a directory.", $homeDirectory)); } $basename = $this->customConfigFilename; if (!OperatingSystem::isWindows()) { $basename = ".{$basename}"; } return $homeDirectory . '/' . $basename; }