Example #1
0
 /**
  * Attempt to lock this command.
  *
  * @param OutputInterface $output The output object to use for any error messages
  *
  * @return void
  */
 public function lock(OutputInterface $output)
 {
     # If this command doesn't require locking then don't do anything
     if (!$this->lock) {
         return;
     }
     $path = $this->getLockPath();
     # If the lock file doesn't already exist then we are creating it, so we need to open the permissions on it
     $newFile = !file_exists($path);
     # Attempt to create/open a lock file for this command
     if (!($this->lock = fopen($path, "w"))) {
         $output->error("Unable to create a lock file (" . $path . ")");
         exit(Application::STATUS_PERMISSIONS);
     }
     # Attempt to lock the file we've just opened
     if (!flock($this->lock, LOCK_EX | LOCK_NB)) {
         fclose($this->lock);
         $output->error("Another instance of this command (" . $this->getName() . ") is currently running");
         exit(Application::STATUS_LOCKED);
     }
     # Ensure the permissions are as open as possible to allow multiple users to run the same command
     if ($newFile) {
         chmod($path, 0777);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function writeError(OutputInterface $output, \Exception $error)
 {
     if ($output instanceof SymfonyStyle) {
         $output->newLine();
         $output->error($error->getMessage());
         return;
     }
     parent::writeError($output, $error);
 }
 protected function loadConfig(OutputInterface $output)
 {
     try {
         $this->config = new Config(getcwd() . '/spacewave.yml');
     } catch (FileNotFoundException $e) {
         $output->error('Could not find spacewave.yml in directory');
         exit;
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // Database options
     $dbType = $input->getOption('db-type');
     $dbFile = $input->getOption('db-file');
     $dbHost = $input->getOption('db-host');
     $dbName = $input->getOption('db-name');
     $dbUser = $input->getOption('db-user');
     $dbPass = $input->getOption('db-pass');
     $dbPrefix = $input->getOption('db-prefix');
     $dbPort = $input->getOption('db-port');
     $databases = $this->site->getDatabaseTypes();
     if ($dbType === 'sqlite') {
         $database = array('database' => $dbFile, 'prefix' => $dbPrefix, 'namespace' => $databases[$dbType]['namespace'], 'driver' => $dbType);
     } else {
         $database = array('database' => $dbName, 'username' => $dbUser, 'password' => $dbPass, 'prefix' => $dbPrefix, 'port' => $dbPort, 'host' => $dbHost, 'namespace' => $databases[$dbType]['namespace'], 'driver' => $dbType);
     }
     $this->backupSitesFile($io);
     try {
         $this->runInstaller($io, $input, $database);
     } catch (Exception $e) {
         $output->error($e->getMessage());
         return;
     }
     $this->restoreSitesFile($io);
 }