/** * Add a new project. Handles both the form, and processing. */ public function add() { $this->layout->title = Lang::get('add_project'); $this->requireAdmin(); $method = $this->request->getMethod(); $pub = null; $values = $this->getParams(); if ($method != 'POST') { $sshKey = new SshKey(); $key = $sshKey->generate(); $values['key'] = $key['private_key']; $values['pubkey'] = $key['public_key']; $pub = $key['public_key']; } $form = $this->projectForm($values); if ($method != 'POST' || $method == 'POST' && !$form->validate()) { $view = new b8\View('ProjectForm'); $view->type = 'add'; $view->project = null; $view->form = $form; $view->key = $pub; return $view->render(); } else { $title = $this->getParam('title', 'New Project'); $reference = $this->getParam('reference', null); $type = $this->getParam('type', null); $options = array('ssh_private_key' => $this->getParam('key', null), 'ssh_public_key' => $this->getParam('pubkey', null), 'build_config' => $this->getParam('build_config', null), 'allow_public_status' => $this->getParam('allow_public_status', 0), 'branch' => $this->getParam('branch', null), 'group' => $this->getParam('group_id', null)); $project = $this->projectService->createProject($title, $type, $reference, $options); $response = new b8\Http\Response\RedirectResponse(); $response->setHeader('Location', PHPCI_URL . 'project/view/' . $project->getId()); return $response; } }
/** * Add a new project. Handles both the form, and processing. */ public function add() { $this->config->set('page_title', 'Add Project'); $this->requireAdmin(); $method = $this->request->getMethod(); $pub = null; $values = $this->getParams(); if ($method != 'POST') { $sshKey = new SshKey(); $key = $sshKey->generate(); $values['key'] = $key['private_key']; $values['pubkey'] = $key['public_key']; $pub = $key['public_key']; } $form = $this->projectForm($values); if ($method != 'POST' || $method == 'POST' && !$form->validate()) { $view = new b8\View('ProjectForm'); $view->type = 'add'; $view->project = null; $view->form = $form; $view->key = $pub; return $view->render(); } else { return $this->addProject($form); } }