/** * Update the properties of a given project. * @param Project $project * @param string $title * @param string $type * @param string $reference * @param array $options * @return \PHPCI\Model\Project */ public function updateProject(Project $project, $title, $type, $reference, $options = array()) { // Set basic properties: $project->setTitle($title); $project->setType($type); $project->setReference($reference); $project->setAllowPublicStatus(0); // Handle extra project options: if (array_key_exists('ssh_private_key', $options)) { $project->setSshPrivateKey($options['ssh_private_key']); } if (array_key_exists('ssh_public_key', $options)) { $project->setSshPublicKey($options['ssh_public_key']); } if (array_key_exists('build_config', $options)) { $project->setBuildConfig($options['build_config']); } if (array_key_exists('allow_public_status', $options)) { $project->setAllowPublicStatus((int) $options['allow_public_status']); } if (array_key_exists('archived', $options)) { $project->setArchived((bool) $options['archived']); } if (array_key_exists('branch', $options)) { $project->setBranch($options['branch']); } // Allow certain project types to set access information: $this->processAccessInformation($project); // Save and return the project: return $this->projectStore->save($project); }
/** * Edit a project. Handles both the form and processing. */ public function edit($projectId) { if (!$_SESSION['user']->getIsAdmin()) { throw new ForbiddenException('You do not have permission to do that.'); } $method = $this->request->getMethod(); $project = $this->projectStore->getById($projectId); if (empty($project)) { throw new NotFoundException('Project with id: ' . $projectId . ' not found'); } $this->config->set('page_title', 'Edit: ' . $project->getTitle()); $values = $project->getDataArray(); $values['key'] = $values['ssh_private_key']; $values['pubkey'] = $values['ssh_public_key']; if ($values['type'] == "gitlab") { $accessInfo = $project->getAccessInformation(); $reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $project->getReference() . ".git"; $values['reference'] = $reference; } if ($method == 'POST') { $values = $this->getParams(); } $form = $this->projectForm($values, 'edit/' . $projectId); if ($method != 'POST' || $method == 'POST' && !$form->validate()) { $view = new b8\View('ProjectForm'); $view->type = 'edit'; $view->project = $project; $view->form = $form; $view->key = null; return $view->render(); } $values = $form->getValues(); $values['ssh_private_key'] = $values['key']; $values['ssh_public_key'] = $values['pubkey']; if ($values['type'] == "gitlab") { preg_match('`^(.*)@(.*):(.*)/(.*)\\.git`', $values['reference'], $matches); $info = array(); $info["user"] = $matches[1]; $info["domain"] = $matches[2]; $values['access_information'] = serialize($info); $values['reference'] = $matches[3] . "/" . $matches[4]; } $project->setValues($values); $project = $this->projectStore->save($project); header('Location: ' . PHPCI_URL . 'project/view/' . $project->getId()); die; }