/** * @{inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $question = '<info>Please enter the full name of the project:</info>'; $name = Application::ask($question, $input, $output, function ($answer) { if ($answer == null) { throw new \RuntimeException('The name of the project can\'t be empty.'); } return $answer; }); $question = '<info>Please enter the short name (acronym) of the project:</info>'; $acronym = Application::ask($question, $input, $output, function ($answer) { if ($answer == null) { throw new \RuntimeException('The acronym of the project can\'t be empty.'); } return $answer; }); $question = '<info>Please enter the git repository url:</info>'; $repositoryUrl = Application::ask($question, $input, $output, function ($answer) { if ($answer == null) { throw new \RuntimeException('The git repository url can\'t be empty.'); } return $answer; }); $question = '<info>Please enter the url to be able to open the website in your browser:</info>'; $webserverUrl = Application::ask($question, $input, $output, function ($answer) { if ($answer == null) { throw new \RuntimeException('The webserver url can\'t be empty.'); } return $answer; }); // Create a new Project $project = ProjectModel::buildEntity([Project::FIELD_NAME => $name, Project::FIELD_SHORT_NAME => $acronym, Project::FIELD_REPOSITORY_URL => $repositoryUrl, Project::FIELD_VHOST_NAME => $webserverUrl]); $model = new ProjectModel($project); $project = $model->persist(); if ($project) { $output->writeln(sprintf('Project <info>%s</info> (Acronym: <info>%s</info>) successful registered.', $project->getFullName(), $project->getShortName())); } else { $output->writeln(sprintf('Failed to register project <error>%s</error> (Acronym: <error>%s</error>).', $project->getFullName(), $project->getShortName())); } }
/** * Returns the project by acronym from database. * * @param string $acronym * The acronym to search for. * * @return \commpress\Cli\Entity\Project * The project. * * @throws \commpress\Cli\Service\Database\Exception\DatabaseQueryException * If something goes wrong. */ public function getProjectByAcronym($acronym) { $project = null; $query = sprintf('SELECT * FROM %s WHERE %s = :acronym', self::TABLE_PROJECTS, Project::FIELD_SHORT_NAME); $stmt = $this->database->prepare($query); $stmt->bindValue(':acronym', $acronym); $result = $stmt->execute(); if ($result) { $data = $result->fetchArray(SQLITE3_ASSOC); if (!$data) { throw new DatabaseQueryException(sprintf('Unable to get project with acronym "%s" from database.', $acronym)); } $project = ProjectModel::buildEntity($data); $stmt->close(); } return $project; }