protected function execute(InputInterface $input, OutputInterface $output) { $configHelper = $this->getHelper('configuration'); /* @var $configHelper GlobalConfigurationHelper */ $vhostConfigs = $input->getArgument('vhosts'); if (!$input->getOption('force')) { $vhostConfigs = array_filter($vhostConfigs, function (VhostConfiguration $vhostConfiguration) { return $vhostConfiguration->isDisabled(); }); } foreach ($vhostConfigs as $vhostConfig) { /* @var $vhostConfig VhostConfiguration */ if ($input->getOption('force') || $vhostConfig->getLink()->isLink() && $vhostConfig->getLink()->getLinkTarget() === $vhostConfig->getTarget()->getPathname()) { FsUtil::unlink($vhostConfig->getLink()); $output->writeln(sprintf('Removed <info>%s</info>', $vhostConfig->getLink()), OutputInterface::VERBOSITY_VERBOSE); } else { throw new InvalidLinkTargetException($vhostConfig->getLink(), $vhostConfig->getTarget()); } $vhostConfig->setDisabled(false); FsUtil::symlink($vhostConfig->getTarget(), $vhostConfig->getLink()); $output->writeln(sprintf('Linked <info>%s</info> to <info>%s</info>', $vhostConfig->getLink(), $vhostConfig->getTarget()), OutputInterface::VERBOSITY_VERBOSE); $output->writeln(sprintf('Enabled vhost <info>%s</info>', $vhostConfig->getName())); } $configHelper->getConfiguration()->write(); }
protected function execute(InputInterface $input, OutputInterface $output) { $configHelper = $this->getHelper('configuration'); /* @var $configHelper GlobalConfigurationHelper */ $exitCode = 0; foreach ($input->getArgument('vhosts') as $vhostConfig) { /* @var $vhostConfig VhostConfiguration */ try { if (!$vhostConfig->getLink()->isLink()) { throw new NotALinkException($vhostConfig->getLink()); } if (!$input->getOption('force')) { if ($vhostConfig->getTarget()->getPathname() !== $vhostConfig->getLink()->getLinkTarget()) { throw new InvalidLinkTargetException($vhostConfig->getLink(), $vhostConfig->getTarget()); } } FsUtil::unlink($vhostConfig->getLink()); $output->writeln(sprintf('Removed vhost <info>%s</info>', $vhostConfig->getName())); $configHelper->getConfiguration()->removeVhostConfiguration($vhostConfig->getName()); } catch (FileException $ex) { $output->writeln(sprintf('<error>Could not remove vhost "%s": %s</error>', $vhostConfig->getName(), $ex->getMessage())); $exitCode = 1; } } $configHelper->getConfiguration()->write(); return $exitCode; }
public function write() { if (file_exists($this->getConfigFile()->getPathname())) { $backupDir = $this->getClicDirectory() . '/settings-backup/' . sha1($this->getConfigFile()->getPathname()); if (!is_dir($backupDir)) { FsUtil::mkdir($backupDir, true); } $backupFile = $backupDir . '/' . time(); FsUtil::rename($this->getConfigFile()->getPathname(), $backupFile); if (file_exists($backupDir . '/prev')) { FsUtil::unlink($backupDir . '/prev'); } FsUtil::symlink($backupFile, $backupDir . '/prev'); } parent::write(); }
private function extractFile(OutputInterface $output, $configFile) { if (is_file($configFile)) { // Try to JSON decode the file first $data = @json_decode(file_get_contents($configFile)); if ($data !== null) { return $configFile; } // And then extract if it is not valid json $configHelper = $this->getHelper('configuration'); /* @var $configHelper GlobalConfigurationHelper */ $extractHelper = $this->getHelper('extract'); /* @var $extractHelper ExtractHelper */ $overridesDir = $configHelper->getConfiguration()->getOverridesDirectory(); $overridesDir .= '/' . sha1($configFile) . '-' . basename($configFile); $extractHelper->extractArchive($configFile, $overridesDir, $output); FsUtil::unlink($configFile); $configFile = $overridesDir; } if (is_dir($configFile)) { return $this->findConfigJsonInDirectory($configFile); } throw new \RuntimeException(sprintf('Could not identify the override file, please add it manually. Files are in %s', $configFile)); }
/** * @param OutputInterface $output * @param $file */ private function unlinkFile(OutputInterface $output, $file) { try { FsUtil::unlink($file); $output->writeln(sprintf('Removed file <info>%s</info>', $file)); } catch (FilesystemOperationFailedException $ex) { $output->writeln(sprintf('<error>Could not remove file %s: %s</error>', $ex->getFilename(), $ex->getMessage())); } }