public function add($name) { $this->view = null; try { $user = User::find(Session::uid()); if (!$user->getId() || !$user->getIs_admin()) { throw new Exception('Action not allowed.'); } if (!preg_match('/^\\d*[-a-zA-Z][-a-zA-Z0-9]*$/', $name)) { throw new Exception('The name of the project can only contain alphanumeric characters plus dashes and must have 1 alpha character at least'); } try { $project = Project::find($name); } catch (Exception $e) { } if (is_object($project) && $project->getProjectId($name)) { throw new Exception('Project with the same name already exists!'); } $file = new File(); $logo = ''; if (!empty($_POST['logo'])) { $file->findFileById($_POST['logo']); $logo = basename($file->getUrl()); } $project = new Project(); $project->setName($name); $project->setDescription($_POST['description']); $project->setWebsite($_POST['website']); $project->setContactInfo($user->getUsername()); $project->setOwnerId($user->getId()); $project->setActive(true); $project->setInternal(true); $project->setRequireSandbox(true); $project->setLogo($logo); $project->setRepo_type('git'); $project->setRepository($_POST['github_repo_url']); $project->setGithubId($_POST['github_client_id']); $project->setGithubSecret($_POST['github_client_secret']); $project->save(); if ($file->getId()) { $file->setProjectId($project->getProjectId()); $file->save(); } $journal_message = '@' . $user->getNickname() . ' added project *' . $name . '*'; Utils::systemNotification($journal_message); echo json_encode(array('success' => true, 'message' => $journal_message)); } catch (Exception $e) { $error = $e->getMessage(); echo json_encode(array('success' => false, 'message' => $error)); } }