/** * Search for magento root folder * * @param InputInterface|null $input [optional] * @param OutputInterface|null $output [optional] * @return void */ public function detectMagento(InputInterface $input = null, OutputInterface $output = null) { // do not detect magento twice if ($this->_magentoDetected) { return; } if ($this->getMagentoRootFolder() === null) { $this->_checkRootDirOption(); $folder = OperatingSystem::getCwd(); } else { $folder = $this->getMagentoRootFolder(); } $this->getHelperSet()->set(new MagentoHelper($input, $output), 'magento'); $magentoHelper = $this->getHelperSet()->get('magento'); /* @var $magentoHelper MagentoHelper */ if (!$this->_directRootDir) { $subFolders = $this->config->getDetectSubFolders(); } else { $subFolders = array(); } $this->_magentoDetected = $magentoHelper->detect($folder, $subFolders); $this->_magentoRootFolder = $magentoHelper->getRootFolder(); $this->_magentoEnterprise = $magentoHelper->isEnterpriseEdition(); $this->_magentoMajorVersion = $magentoHelper->getMajorVersion(); $this->_magerunStopFileFound = $magentoHelper->isMagerunStopFileFound(); $this->_magerunStopFileFolder = $magentoHelper->getMagerunStopFileFolder(); }
/** * @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']); }