/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $acronym = $input->getArgument('acronym'); $database = new ProjectDatabase(Application::getDatabase()); try { $project = $database->getProjectByAcronym($acronym); $database->removeProject($project); $output->writeln(sprintf('<info>Successfully</info> unregistered project <info>%s</info>', $acronym)); } catch (DatabaseQueryException $e) { $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { // Get the project. $database = new ProjectDatabase(Application::getDatabase()); $acronym = $input->getArgument('project_acronym'); $project = null; try { $project = $database->getProjectByAcronym($input->getArgument('project_acronym')); Application::getDocker()->removeEnvironment($project, $input->getArgument('feature_branch')); } catch (DatabaseQueryException $e) { $output->writeln(sprintf('Unable to find <error>project</error> by acronym <error>%s</error>.', $acronym)); } }
protected function execute(InputInterface $input, OutputInterface $output) { // Read in the arguments. $acronym = $input->getArgument('project_acronym'); $branch = $input->getArgument('feature_branch'); $installProfile = $input->getArgument('drupal_install_profile'); $project = null; try { // Get the project. $projectDatabase = new ProjectDatabase(Application::getDatabase()); $project = $projectDatabase->getProjectByAcronym($input->getArgument('project_acronym')); // Create the docker environment. Application::getDocker()->createEnvironment($project, $branch, $installProfile); } catch (DockerManagerCreateEnvironmentException $e) { $output->writeln(sprintf('<error>Failed</error> to create <error>environment</error> [project: %s, branch: %s]', $acronym, $branch)); } catch (DatabaseQueryException $e) { $output->writeln(sprintf('Unable to find <error>project</error> by acronym <error>%s</error>.', $acronym)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { // Get all projects. try { $database = new ProjectDatabase(Application::getDatabase()); $projects = $database->getProjects(); if ($projects == array()) { $output->writeln('<comment>Currently there are no projects registered.</comment>'); return; } $table = new Table($output); $table->setHeaders(['ID', 'Project', 'Acronym', 'Git URL', 'Web URL']); foreach ($projects as $project) { $table->addRow([$project->getId(), $project->getFullName(), $project->getShortName(), $project->getGitRepositoryUrl(), 'http://' . $project->getVhostName()]); } $table->render(); } catch (DatabaseQueryException $e) { $output->writeln('<error>Failed to retrieve list of registered projects from database.</error>'); } }
/** * Prepares the data for statement execution. * * @param string $type * The type can be either CREATE or UPDATE. * @param array $data * The data array in field => value format. * @param $table * The name of the database table. * * @return bool|\SQLite3Stmt * The statement or false. */ protected function prepareStatement($type, array $data, $table) { switch ($type) { case self::STMT_CREATE: $type = 'INSERT INTO'; break; case self::STMT_UPDATE: break; default: return false; } $database = Application::getDatabase(); $values = []; foreach ($data as $field => $value) { $values[':' . $field] = $value; } // Create the query. $query = sprintf('%s %s (%s) VALUES (%s)', $type, $table, join(',', array_keys($data)), join(',', array_keys($values))); $stmt = $database->prepare($query); foreach ($values as $key => $value) { $stmt->bindValue($key, $value); } return $stmt; }
/** * Checks if the entity by id exists already in the database. * * @return bool * TRUE if the entity is stored in the database, otherwise false. */ public function entityExists() { // Before we ask the database we want to make sure we have an id. if ($this->environment->getId() == null) { // No database request is needed in this case. return false; } // Define the query. $query = sprintf('SELECT COUNT(id) AS num FROM environments WHERE %s = :id', Environment::FIELD_ID); // Get the database instance. $database = Application::getDatabase(); // Prepare the statement. $stmt = $database->prepare($query); $stmt->bindValue(':id', $this->environment->getId()); // Get the result from statement execution. $result = $stmt->execute()->fetchArray(SQLITE3_ASSOC); // Close the statement to free memory. $stmt->close(); // Check if the project was found. if ($result['num'] >= 1) { return true; } return false; }