/**
  * Init active project, if we have active_project $_GET var
  *
  * @access public
  * @param void
  * @return null
  * @throws Error
  */
 private function initActiveProject()
 {
     trace(__FILE__, 'initActiveProject()');
     $project_id = array_var($_GET, 'active_project');
     if (!empty($project_id)) {
         $project = Projects::findById($project_id);
         if ($project instanceof Project) {
             $this->setProject($project);
         } else {
             $project = new Project();
             $project->setId($project_id);
             $project->setName(lang('deleted or unknown'));
             //flash_error(lang('failed to load project'));
             $this->setProject($project);
             //throw new Error(lang('failed to load project'));
         }
         // if
     }
     // if
 }
Example #2
0
 function find($criteria = null, $order = null, $limit = 1000, $from = 0)
 {
     $result = $this->database->query($this->buildFindQuery($criteria, $order, $limit, $from));
     if (!is_null($result->getError())) {
         return $result->getError();
     }
     $projects = array();
     while ($row = $result->fetchRow()) {
         $project = new Project();
         $value = $row[0];
         $project->setId($value);
         $value = $row[1];
         $project->setName($value);
         $value = $row[2];
         $project->setDescription($value);
         $value = $row[3];
         $value = $this->database->toBoolean($value);
         $project->setMove_more($value);
         $value = $row[4];
         $project->setCampaign($value);
         $value = $row[5];
         $project->setSuspending($value);
         $value = $row[6];
         $project->setEnding($value);
         $value = $row[7];
         $project->setOwner($value);
         $value = $row[8];
         $project->setCruid($value);
         $value = $row[9];
         $project->setPkey($value);
         $value = $row[10];
         $project->setRsskey($value);
         $value = $row[11];
         $project->setR_date($value);
         $value = $row[12];
         $project->setR_user($value);
         if ($order != null) {
             array_push($projects, $project);
         } else {
             $projects[$project->getId()] = $project;
         }
     }
     return $projects;
 }
Example #3
0
 /**
  * Return the personal project of the user
  *
  * @access public
  * @param void
  * @return Project
  */
 function getPersonalProject()
 {
     if (is_null($this->personal_project)) {
         $this->personal_project = Projects::findById($this->getPersonalProjectId());
         if (!$this->personal_project instanceof Project) {
             $this->personal_project = new Project();
             $this->personal_project->setId(0);
             $this->personal_project->setColor(0);
             $this->personal_project->setParentWorkspace(null);
         }
     }
     // if
     return $this->personal_project;
 }
Example #4
0
 function actionSave($currentUser)
 {
     $backUrl = $this->context->getFlowScopeAttr("backUrl");
     $oldRssKey = null;
     $project = new Project();
     $projectErrs = array();
     $project->setId($this->context->getRequestAttr("id"));
     if (!is_null($project->getId())) {
         $oldProject = $this->projectDao->get($project->getId());
         if (is_null($oldProject) || is_string($oldProject)) {
             $this->context->setRequestScopeAttr("error", "error.dberror");
             if (!is_null($backUrl)) {
                 header("Location: " . $backUrl);
                 return true;
             }
             return false;
         }
     }
     $project->setName($this->context->getRequestAttr("name"));
     if (!is_null($project->getName())) {
         $project->setName(trim($project->getName()));
         if (strlen($project->getName()) < 1) {
             $project->setName(null);
         }
     }
     if (is_null($project->getName())) {
         $projectErrs["name"] = "field.error.empty";
     }
     $project->setDescription($this->context->getRequestAttr("description"));
     if (!is_null($project->getDescription())) {
         $project->setDescription(trim($project->getDescription()));
         if (strlen($project->getDescription()) < 1) {
             $project->setDescription(null);
         }
     }
     $project->setCampaign($this->context->getRequestAttr("campaign"));
     if (!is_null($project->getCampaign())) {
         $project->setCampaign(trim($project->getCampaign()));
         if (strlen($project->getCampaign()) < 1) {
             $project->setCampaign(null);
         }
     }
     $project->setSuspending($this->context->getRequestAttr("suspending"));
     if (!is_null($project->getSuspending())) {
         $project->setSuspending(trim($project->getSuspending()));
         if (strlen($project->getSuspending()) < 1) {
             $project->setSuspending(null);
         }
     }
     $project->setEnding($this->context->getRequestAttr("ending"));
     if (!is_null($project->getEnding())) {
         $project->setEnding(trim($project->getEnding()));
         if (strlen($project->getEnding()) < 1) {
             $project->setEnding(null);
         }
     }
     $move_more = $this->context->getRequestAttr("move_more");
     $project->setMove_more($move_more == 1 ? true : false);
     $timeZone = new DateTimeZone("Europe/Vilnius");
     $time = new DateTime("now", $timeZone);
     $project->setR_date($time->format("Y-m-d H:i:s"));
     $project->setR_user($currentUser->getId());
     if (is_null($project->getId())) {
         $project->setOwner($currentUser->getId());
         $project->setCruid($this->generateCode());
         $project->setPkey($this->generateCode());
         $project->setRsskey($this->generateCode());
     } else {
         $project->setCruid($oldProject->getCruid());
         $project->setRsskey($oldProject->getRssKey());
     }
     $this->context->setFlashScopeAttr("project", $project);
     $this->context->setFlashScopeAttr("projectErrs", $projectErrs);
     if (count($projectErrs) >= 1) {
         if (!is_null($backUrl)) {
             header("Location: " . $backUrl);
             return true;
         }
         return false;
     }
     $store = $this->storeProject($project);
     if (!$store) {
         if (!is_null($backUrl)) {
             header("Location: " . $backUrl);
             return true;
         }
         return false;
     }
     $rss = new Rss($project->getRsskey());
     if (!$rss->storeProjectRssFile($project)) {
         $this->context->setRequestScopeAttr("errortxt", "Nepavyko sukurti/atnaujinti RSS failo!");
     }
     /* Issaugom pasirinktas grupes */
     $groups = $this->context->getRequestAttr("groups");
     $selectedProjects = $this->context->getRequestAttr("selectedProjects");
     if (is_null($selectedProjects) && !is_null($groups)) {
         $this->saveProjectGroups($project->getId(), $groups);
     }
     if (!is_null($selectedProjects) && is_null($groups)) {
         $this->removeProjectFromGroups($currentUser->getId(), $project->getId());
     }
     if (!is_null($selectedProjects) && !is_null($groups)) {
         $toRemove = array_diff(json_decode($selectedProjects), $groups);
         if (count($toRemove) > 0) {
             foreach ($toRemove as $gp) {
                 $this->removeFromGroup($gp, $project->getId());
             }
         }
         $toAdd = array_diff($groups, json_decode($selectedProjects));
         if (count($toAdd) > 0) {
             $this->saveProjectGroups($project->getId(), $toAdd);
         }
     }
     $this->cancelEdit();
     if (!is_null($backUrl)) {
         header("Location: " . $backUrl);
         return true;
     }
     return false;
 }
Example #5
0
 /**
  *
  * @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;
 }
 public function setId($id)
 {
     $this->__load();
     return parent::setId($id);
 }
 /**
  * Finish the installation - create owner company and administrator
  *
  * @param void
  * @return null
  */
 function complete_installation()
 {
     if (Companies::getOwnerCompany() instanceof Company) {
         die('Owner company already exists');
         // Somebody is trying to access this method even if the user already exists
     }
     // if
     $form_data = array_var($_POST, 'form');
     tpl_assign('form_data', $form_data);
     if (array_var($form_data, 'submited') == 'submited') {
         try {
             $admin_password = trim(array_var($form_data, 'admin_password'));
             $admin_password_a = trim(array_var($form_data, 'admin_password_a'));
             if (trim($admin_password) == '') {
                 throw new Error(lang('password value required'));
             }
             // if
             if ($admin_password != $admin_password_a) {
                 throw new Error(lang('passwords dont match'));
             }
             // if
             DB::beginWork();
             Users::delete();
             // clear users table
             Companies::delete();
             // clear companies table
             // Create the administrator user
             $administrator = new User();
             $administrator->setId(1);
             $administrator->setCompanyId(1);
             $administrator->setUsername(array_var($form_data, 'admin_username'));
             $administrator->setEmail(array_var($form_data, 'admin_email'));
             $administrator->setPassword($admin_password);
             $administrator->setCanEditCompanyData(true);
             $administrator->setCanManageConfiguration(true);
             $administrator->setCanManageSecurity(true);
             $administrator->setCanManageWorkspaces(true);
             $administrator->setCanManageContacts(true);
             $administrator->setCanManageTemplates(true);
             $administrator->setCanManageReports(true);
             $administrator->setCanManageTime(true);
             $administrator->setCanAddMailAccounts(true);
             $administrator->setAutoAssign(false);
             $administrator->setPersonalProjectId(1);
             $administrator->setType('admin');
             $administrator->save();
             $group = new Group();
             $group->setName('administrators');
             $group->setAllPermissions(true);
             $group->setId(Group::CONST_ADMIN_GROUP_ID);
             $group->save();
             $group_user = new GroupUser();
             $group_user->setGroupId(Group::CONST_ADMIN_GROUP_ID);
             $group_user->setUserId($administrator->getId());
             $group_user->save();
             $project = new Project();
             $project->setId(1);
             $project->setP1(1);
             $project->setName(new_personal_project_name($administrator->getUsername()));
             $project->setDescription(lang('files'));
             $project->setCreatedById($administrator->getId());
             $project->save();
             $project_user = new ProjectUser();
             $project_user->setProjectId($project->getId());
             $project_user->setUserId($administrator->getId());
             $project_user->setCreatedById($administrator->getId());
             $project_user->setAllPermissions(true);
             $project_user->save();
             // Create a company
             $company = new Company();
             $company->setId(1);
             $company->setClientOfId(0);
             $company->setName(array_var($form_data, 'company_name'));
             $company->setCreatedById(1);
             $company->save();
             DB::commit();
             $this->redirectTo('access', 'login');
         } catch (Exception $e) {
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if
 }