public static function project_new() { $postVars = array(); foreach ($_POST['newProjectContainer'] as $name => $value) { if (isset($value['value'])) { $postVars[$name] = $value['value']; } } // // Check for mandatory attributes // if (!isset($postVars['title']) || empty($postVars['title']) || !isset($postVars['scmConnectorType']) || empty($postVars['scmConnectorType']) || !isset($postVars['scmRemoteRepository']) || empty($postVars['scmRemoteRepository'])) { // // TODO: Error notification!!! // SystemEvent::raise(SystemEvent::DEBUG, "Project creation failed, required attributes were empty.", __METHOD__); echo json_encode(array('success' => false, 'error' => 'Missing required attributes. Make sure all attributes not marked as optional are filled.')); exit; } else { $GLOBALS['project'] = null; $project = new Project(); $project->setTitle($postVars['title']); $project->setReleaseLabel($postVars['releaseLabel']); $project->setScmConnectorType($postVars['scmConnectorType']); $project->setScmRemoteRepository($postVars['scmRemoteRepository']); $project->setScmUsername($postVars['scmUsername']); $project->setScmPassword($postVars['scmPassword']); $project->addToUsers($GLOBALS['user'], Access::OWNER); if (!$project->init()) { SystemEvent::raise(SystemEvent::ERROR, "Could not initialize project. Try again later.", __METHOD__); echo json_encode(array('success' => false, 'error' => 'The project was created but could not be initialized. Please check the logs and/or try the first build manually.')); exit; } $GLOBALS['project'] = $project; $GLOBALS['project']->log("Project created.", $GLOBALS['user']->getUsername()); echo json_encode(array('success' => true, 'error' => 'Project successfully created, taking you back to your dashboard. Stand by...')); exit; } }
/** * * @param unknown_type $rs */ private static function &_getObject(Resultset $rs, array $options = array()) { isset($options['loadUsers']) ?: ($options['loadUsers'] = true); $ret = new Project(); $ret->setAvatar($rs->getAvatar()); $ret->setScmConnectorType($rs->getScmConnectorType()); $ret->setScmRemoteRepository($rs->getScmRemoteRepository()); $ret->setScmUsername($rs->getScmUsername()); $ret->setScmPassword($rs->getScmPassword()); $ret->setScmCheckChangesTimeout($rs->getScmCheckChangesTimeout()); $ret->setWorkDir($rs->getWorkDir()); $ret->setReleaseLabel($rs->getReleaseLabel()); $ret->setDateCreation($rs->getDateCreation()); $ret->setDateCheckedForChanges($rs->getDateCheckedForChanges()); $ret->setDescription($rs->getDescription()); $ret->setId($rs->getId()); $specialTasks = @unserialize($rs->getSpecialTasks()); if ($specialTasks === false) { $specialTasks = array(); } $ret->setSpecialTasks($specialTasks); $ret->setStatsNumBuilds($rs->getStatsNumBuilds()); $ret->setStatus($rs->getStatus()); $ret->setTitle($rs->getTitle()); $ret->setVisits($rs->getVisits()); $ret->setOptionReleasePackage($rs->getOptionReleasePackage()); $ret->setScmEnvVars($rs->getScmEnvVars()); // // Builders // // // The following is a workaround on the fact that the translation of this // serialized object to the database gets all broken, due to the fact of PHP // introducing NULL bytes around the '*' that is prepended before protected // variable members, in the serialized mode. This method replaces those // problematic NULL bytes with an identifier string '~~NULL_BYTE~~', // rendering serialization and unserialization of these specific kinds of // object safe. Credits to travis@travishegner.com on: // http://pt.php.net/manual/en/function.serialize.php#96504 // $unsafeSerializedIntegrationBuilder = str_replace(CINTIENT_NULL_BYTE_TOKEN, "", $rs->getIntegrationBuilder()); if (($integrationBuilder = unserialize($unsafeSerializedIntegrationBuilder)) === false) { SystemEvent::raise(SystemEvent::ERROR, "Couldn't unserialize integration builder for this project [PID={$ret->getId()}]"); $integrationBuilder = new Build_BuilderElement_Project(); } $ret->setIntegrationBuilder($integrationBuilder); $unsafeSerializedDeploymentBuilder = str_replace(CINTIENT_NULL_BYTE_TOKEN, "", $rs->getDeploymentBuilder()); if (($deploymentBuilder = unserialize($unsafeSerializedDeploymentBuilder)) === false) { SystemEvent::raise(SystemEvent::ERROR, "Couldn't unserialize deployment builder for this project [PID={$ret->getId()}]"); $deploymentBuilder = new Build_BuilderElement_Project(); } $ret->setDeploymentBuilder($deploymentBuilder); if ($options['loadUsers']) { $ret->loadUsers(); } $ret->resetSignature(); return $ret; }