/** * Adds a new GOCDB project. * @param array $values array containing name and description of the new project * @param \user $user User making the change, only admin users may add projects * @return \Project * @throws \Exception * @throws \org\gocdb\services\Exception */ public function addProject($values, \user $user = null) { //Check the portal is not in read only mode, throws exception if it is $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user); //Throws exception if user is not an administrator $this->checkUserIsAdmin($user); //Check all the required values are present and validate the new values using the GOCDB schema file $this->validate($values); //check the name is unique if (!$this->projectNameIsUnique($values['Name'])) { throw new \Exception("Project names must be unique, '" . $values['Name'] . "' is already in use"); } //Start transaction $this->em->getConnection()->beginTransaction(); // suspend auto-commit try { //new project object $project = new \Project($values['Name']); //set description $project->setDescription($values['Description']); $this->em->persist($project); $this->em->flush(); $this->em->getConnection()->commit(); } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } return $project; }
public function testTpConfig() { $project = new Project(); $project->setName('name'); $project->setDescription('description'); $project->setKeywords(['k1', 'k2']); $project->setHomepage('http://homepage.com'); $project->addAuthor(new Author('author-name <*****@*****.**>')); $project->addPackage($this->buildPackage('namespace1', ['path1.1', 'path1.2'])); $this->assertSame(['name' => 'name', 'description' => 'description', 'keywords' => ['k1', 'k2'], 'homepage' => 'http://homepage.com', 'authors' => [['name' => 'author-name', 'email' => '*****@*****.**']], 'autoload' => ['psr-4' => ['namespace1\\' => ['path1.1', 'path1.2']]]], $project->toConfig()); }
protected function processCreate(sfWebRequest $request, ProjectFormCustom $form) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $values = $form->getValues(); // Slugify name, and check if slug generated does not already exist and generate a new one if needed if (empty($values['name_slug'])) { $slug = MiscUtils::slugify($values['name']); } else { $slug = $values['name_slug']; } $size = 1; while (Doctrine_Core::getTable("Project")->checkSlugForProject(NULL, $slug, true)) { $slug = MiscUtils::slugify($values['name']) . substr(microtime(), -$size); $size++; } // Create the project into database $projectObject = new Project(); $projectObject->setName($values['name']); $projectObject->setDescription($values['description']); $projectObject->setUserId($values['user_id']); $projectObject->setCreatedAt($values['created_at']); $projectObject->setStatus($values['status']); $projectObject->setSecurityLevel($values['security_level']); $projectObject->setNameSlug($slug); $projectObject->save(); // Get the project's id $projectId = $projectObject->getId(); // Create a new relationship between projects, products and project groups for each checked form's product foreach ($values['product'] as $product) { $ptpObject = new ProjectToProduct(); $ptpObject->setProjectGroupId($values['group']); $ptpObject->setProjectId($projectId); $ptpObject->setProductId($product); $ptpObject->save(); } if ($request->hasParameter('_save_and_add')) { $this->getUser()->setFlash('notice', $notice . ' You can add another one below.'); $this->redirect('@project_new'); } else { $this->getUser()->setFlash('notice', $notice); $this->redirect(array('sf_route' => 'project_edit', 'sf_subject' => $projectObject)); } } else { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
class Project { protected $description; public function setDescription($description) { $this->description = $description; return $this; } public function getDescription() { return $this->description; } } $project_one = new Project(); $project_one->setDescription("This is my first test project"); echo $project_one->getDescription(); echo "<br>"; $project_two = $project_one; // Copying by value? echo $project_two->getDescription(); echo "<br>"; $project_two->setDescription("This is my second test project"); echo $project_two->getDescription(); echo "<br>"; echo $project_one->getDescription(); echo "<br>"; echo "Cloning.."; $project_three = clone $project_one; echo $project_three->getDescription(); $project_three->setDescription("This is my third test project");
public function executeSaveNew() { $project = new Project(); $culture = $this->getUser()->getCulture(); // TODO: Implement multiple owners / project leads, if necessary $project->setCreatedBy($this->getUser()->getGuardUser()->getId()); $project->setOwnerId($this->getUser()->getGuardUser()->getId()); $project->setDepartmentId($this->getRequestParameter('department_id') ? $this->getRequestParameter('department_id') : null); $project->setTitle($this->getRequestParameter('title')); $project->setDescription($this->getRequestParameter('description')); $project->setNotes($this->getRequestParameter('notes')); $project->setKeywords($this->getRequestParameter('tags_as_text')); if ($this->getRequestParameter('begin')) { list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('begin'), $this->getUser()->getCulture()); $project->setBegin("{$y}-{$m}-{$d}"); } if ($this->getRequestParameter('finish')) { list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('finish'), $this->getUser()->getCulture()); $project->setFinish("{$y}-{$m}-{$d}"); } $this->logMessage('Dates Saved'); $project->setCampusId($this->getRequestParameter('campus')); $project->setPublished($this->getRequestParameter('published', 0)); $project->save(); $this->logMessage('Project Saved'); $project->createDefaultPermissions(); return $this->redirect('project/awaitApproval'); }
/** * Save Customer * @param sfWebRequest $request * @return unknown_type */ public function executeSaveProject(sfWebRequest $request) { $projectService = new ProjectService(); if ($request->isMethod('post')) { $project = new Project(); $project->setCustomerId($request->getParameter('cmbCustomerId')); $project->setName($request->getParameter('txtName')); $project->setDescription($request->getParameter('txtDescription')); $projectService->saveProject($project); $this->setMessage('SUCCESS', array(TopLevelMessages::SAVE_SUCCESS)); $this->redirect('admin/listProject'); } $customerService = new CustomerService(); $this->listCustomer = $customerService->getCustomerList(); }
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; }
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)); } }
public function approve() { if (!$this->getIsApproved()) { $this->setIsApproved(true); $project = new Project(); $project->setCreatedBy($this->getCreatedBy()); $project->setOwnerId($this->getOwnerId()); $project->setDepartmentId($this->getDepartmentId()); $project->setCampusId($this->getCampusId()); $project->setTitle($this->getTitle()); $project->setDescription($this->getDescription()); $project->setNotes($this->getNotes()); $project->setBegin($this->getBegin()); $project->setFinish($this->getFinish()); $project->setMainForm('default'); $project->setPublished(true); $project->setIsApproved(true); $project->save(); } }
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; }
throw new fValidationException('Arrival date must be no earlier than today.'); } // from < max if (strtotime($_POST['from_date']) > strtotime("+{$maxStorageMonths} months")) { throw new fValidationException('Arrival date must be in the next 6 months.'); } // to > from if (strtotime($_POST['to_date']) < strtotime($_POST['from_date'])) { throw new fValidationException('Removal date must come after arrival date.'); } // to < max if (strtotime($_POST['to_date']) > strtotime("+{$maxStorageMonths} months", strtotime($_POST['from_date']))) { throw new fValidationException('Removal date must be 6 months after arrival.'); } $project->setName(filter_var($_POST['name'], FILTER_SANITIZE_STRING)); $project->setDescription(filter_var($_POST['description'], FILTER_SANITIZE_STRING)); if ($_POST['contact'] && $_POST['contact'] != '') { $project->setContact(filter_var($_POST['contact'], FILTER_SANITIZE_EMAIL)); } else { $project->setContact(null); } $project->setLocationId(filter_var($_POST['location_id'], FILTER_SANITIZE_STRING)); $project->setLocation(filter_var($_POST['location'], FILTER_SANITIZE_STRING)); $project->setFromDate(filter_var($_POST['from_date'], FILTER_SANITIZE_STRING)); $project->setToDate(filter_var($_POST['to_date'], FILTER_SANITIZE_STRING)); if (!$project->getId()) { $auto = true; $logDetails = "Request created"; $project->setState('Pending Approval'); $initial = true; } else {
/** * * @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; }
function create_user($user_data, $permissionsString) { $user = new User(); $user->setUsername(array_var($user_data, 'username')); $user->setDisplayName(array_var($user_data, 'display_name')); $user->setEmail(array_var($user_data, 'email')); $user->setCompanyId(array_var($user_data, 'company_id')); $user->setType(array_var($user_data, 'type')); $user->setTimezone(array_var($user_data, 'timezone')); if (!logged_user() instanceof User || can_manage_security(logged_user())) { $user->setCanEditCompanyData(array_var($user_data, 'can_edit_company_data')); $user->setCanManageSecurity(array_var($user_data, 'can_manage_security')); $user->setCanManageWorkspaces(array_var($user_data, 'can_manage_workspaces')); $user->setCanManageConfiguration(array_var($user_data, 'can_manage_configuration')); $user->setCanManageContacts(array_var($user_data, 'can_manage_contacts')); $user->setCanManageTemplates(array_var($user_data, 'can_manage_templates')); $user->setCanManageReports(array_var($user_data, 'can_manage_reports')); $user->setCanManageTime(array_var($user_data, 'can_manage_time')); $user->setCanAddMailAccounts(array_var($user_data, 'can_add_mail_accounts')); $other_permissions = array(); Hook::fire('add_user_permissions', $user, $other_permissions); foreach ($other_permissions as $k => $v) { $user->setColumnValue($k, array_var($user_data, $k)); } } if (array_var($user_data, 'password_generator', 'random') == 'random') { // Generate random password $password = UserPasswords::generateRandomPassword(); } else { // Validate input $password = array_var($user_data, 'password'); if (trim($password) == '') { throw new Error(lang('password value required')); } // if if ($password != array_var($user_data, 'password_a')) { throw new Error(lang('passwords dont match')); } // if } // if $user->setPassword($password); $user->save(); $user_password = new UserPassword(); $user_password->setUserId($user->getId()); $user_password->setPasswordDate(DateTimeValueLib::now()); $user_password->setPassword(cp_encrypt($password, $user_password->getPasswordDate()->getTimestamp())); $user_password->password_temp = $password; $user_password->save(); if (array_var($user_data, 'autodetect_time_zone', 1) == 1) { set_user_config_option('autodetect_time_zone', 1, $user->getId()); } if ($user->getType() == 'admin') { if ($user->getCompanyId() != owner_company()->getId() || logged_user() instanceof User && !can_manage_security(logged_user())) { // external users can't be admins or logged user has no rights to create admins => set as Normal $user->setType('normal'); } else { $user->setAsAdministrator(true); } } /* create contact for this user*/ if (array_var($user_data, 'create_contact', 1)) { // if contact with same email exists take it, else create new $contact = Contacts::getByEmail($user->getEmail(), true); if (!$contact instanceof Contact) { $contact = new Contact(); $contact->setEmail($user->getEmail()); } else { if ($contact->isTrashed()) { $contact->untrash(); } } $contact->setFirstname($user->getDisplayName()); $contact->setUserId($user->getId()); $contact->setTimezone($user->getTimezone()); $contact->setCompanyId($user->getCompanyId()); $contact->save(); } else { $contact_id = array_var($user_data, 'contact_id'); $contact = Contacts::findById($contact_id); if ($contact instanceof Contact) { // user created from a contact $contact->setUserId($user->getId()); $contact->save(); } else { // if contact with same email exists use it as user's contact, without changing it $contact = Contacts::getByEmail($user->getEmail(), true); if ($contact instanceof Contact) { $contact->setUserId($user->getId()); if ($contact->isTrashed()) { $contact->untrash(); } $contact->save(); } } } $contact = $user->getContact(); if ($contact instanceof Contact) { // update contact data with data entered for this user $contact->setCompanyId($user->getCompanyId()); if ($contact->getEmail() != $user->getEmail()) { // make user's email the contact's main email address if ($contact->getEmail2() == $user->getEmail()) { $contact->setEmail2($contact->getEmail()); } else { if ($contact->getEmail3() == $user->getEmail()) { $contact->setEmail3($contact->getEmail()); } else { if ($contact->getEmail2() == "") { $contact->setEmail2($contact->getEmail()); } else { $contact->setEmail3($contact->getEmail()); } } } } $contact->setEmail($user->getEmail()); $contact->save(); } if (!$user->isGuest()) { /* create personal project or assing the selected*/ //if recived a personal project assing this //project as personal project for this user $new_project = null; $personalProjectId = array_var($user_data, 'personal_project', 0); $project = Projects::findById($personalProjectId); if (!$project instanceof Project) { $project = new Project(); $wname = new_personal_project_name($user->getUsername()); $project->setName($wname); $wdesc = Localization::instance()->lang(lang('personal workspace description')); if (!is_null($wdesc)) { $project->setDescription($wdesc); } $project->setCreatedById($user->getId()); $project->save(); //Save to set an ID number $project->setP1($project->getId()); //Set ID number to the first project $project->save(); $new_project = $project; } $user->setPersonalProjectId($project->getId()); $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($user->getId()); $project_user->setCreatedById($user->getId()); $project_user->setAllPermissions(true); $project_user->save(); /* end personal project */ } $user->save(); ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD); //TODO - Make batch update of these permissions if ($permissionsString && $permissionsString != '') { $permissions = json_decode($permissionsString); } else { $permissions = null; } if (is_array($permissions) && (!logged_user() instanceof User || can_manage_security(logged_user()))) { foreach ($permissions as $perm) { if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) { if (!$personalProjectId || $personalProjectId != $perm->wsid) { $relation = new ProjectUser(); $relation->setProjectId($perm->wsid); $relation->setUserId($user->getId()); $relation->setCheckboxPermissions($perm->pc, $user->isGuest() ? false : true); $relation->setRadioPermissions($perm->pr, $user->isGuest() ? false : true); $relation->save(); } } } } // if if ($new_project instanceof Project && logged_user() instanceof User && logged_user()->isProjectUser($new_project)) { evt_add("workspace added", array("id" => $new_project->getId(), "name" => $new_project->getName(), "color" => $new_project->getColor())); } // Send notification... try { if (array_var($user_data, 'send_email_notification')) { Notifier::newUserAccount($user, $password); } // if } catch (Exception $e) { } // try return $user; }
/** * Copy project * * @param void * @return null */ function copy() { trace(__FILE__, "copy():begin"); if (!Project::canAdd(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $this->setTemplate('copy_project'); $this->setLayout('administration'); $project_data = array_var($_POST, 'project'); tpl_assign('project_data', $project_data); // Submitted... if (is_array($project_data)) { $source = Projects::findById($project_data['source']); if (!$source instanceof Project) { flash_error(lang('project dnx')); $this->redirectTo('administration', 'projects'); } // if try { $shift_dates = isset($project_data['shift_dates']) ? $project_data['shift_dates'] == 'checked' : false; $copy_details = isset($project_data['copy_details']) ? $project_data['copy_details'] == 'checked' : false; $copy_tasks = isset($project_data['copy_tasks']) ? $project_data['copy_tasks'] == 'checked' : false; $copy_milestones = isset($project_data['copy_milestones']) ? $project_data['copy_milestones'] == 'checked' : false; $copy_messages = isset($project_data['copy_messages']) ? $project_data['copy_messages'] == 'checked' : false; $copy_links = isset($project_data['copy_links']) ? $project_data['copy_links'] == 'checked' : false; $copy_files = isset($project_data['copy_files']) ? $project_data['copy_files'] == 'checked' : false; $copy_users = isset($project_data['copy_users']) ? $project_data['copy_users'] == 'checked' : false; $copy_pages = isset($project_data['copy_pages']) ? $project_data['copy_pages'] == 'checked' : false; DB::beginWork(); $project = new Project(); $new_name = lang('projects copy new name', $source->getName()); $new_name .= date(' z H:i:s'); $project->setName($new_name); if ($copy_details) { $project->setDescription($source->getDescription()); $project->setPriority($source->getPriority()); $project->setShowDescriptionInOverview($source->getShowDescriptionInOverview()); } $project->save(); $project_id = $project->getId(); $add_seconds = 0; if (isset($project_data['add_days'])) { $add_days = 0 + trim($project_data['add_days']); $add_seconds = $add_days * 24 * 60 * 60; } $source_created_on = $source->getCreatedOn(); //var_dump($source_created_on); $milestone_map = array(0 => 0); // project milestones if ($copy_milestones) { $source_milestones = $source->getAllMilestones(); if (is_array($source_milestones)) { foreach ($source_milestones as $source_milestone) { $milestone = new ProjectMilestone(); //$milestone->copy($source_milestone); $milestone->setName($source_milestone->getName()); $milestone->setDescription($source_milestone->getDescription()); if ($shift_dates) { trace(__FILE__, "copy():shift dates"); $milestone->setDueDate(DateTimeValueLib::now()); $seconds = $source_milestone->getDueDate()->difference($source_created_on); $milestone->getDueDate()->advance($seconds); } else { $milestone->setDueDate($source_milestone->getDueDate()); } $milestone->getDueDate()->advance($add_seconds); $milestone->setIsPrivate($source_milestone->getIsPrivate()); $milestone->setAssignedToUserId($source_milestone->getAssignedToUserId()); $milestone->setAssignedToCompanyId($source_milestone->getAssignedToCompanyId()); $milestone->setProjectId($project_id); $milestone->save(); $milestone_map[$source_milestone->getId()] = $milestone->getId(); } // foreach } // if } // if // project tasks if ($copy_tasks) { $source_task_lists = $source->getAllTaskLists(); if (is_array($source_task_lists)) { foreach ($source_task_lists as $source_task_list) { $task_list = new ProjectTaskList(); //$task_list->copy($source_milestone); $task_list->setName($source_task_list->getName()); $task_list->setPriority($source_task_list->getPriority()); $task_list->setDescription($source_task_list->getDescription()); if ($copy_milestones) { $task_list->setMilestoneId($milestone_map[$source_task_list->getMilestoneId()]); } $task_list->setDueDate($source_task_list->getDueDate()); if ($task_list->getDueDate() instanceof DateTimeValue) { if ($shift_dates) { trace(__FILE__, "copy():task list shift dates"); $task_list->setDueDate(DateTimeValueLib::now()); $seconds = $source_task_list->getDueDate()->difference($source_created_on); $task_list->getDueDate()->advance($seconds); } $task_list->getDueDate()->advance($add_seconds); } $task_list->setIsPrivate($source_task_list->getIsPrivate()); $task_list->setOrder($source_task_list->getOrder()); $task_list->setProjectId($project_id); $task_list->save(); $source_tasks = $source_task_list->getTasks(); if (is_array($source_tasks)) { foreach ($source_tasks as $source_task) { $task = new ProjectTask(); $task->setOrder($source_task->getOrder()); $task->setDueDate($source_task->getDueDate()); if ($task->getDueDate() instanceof DateTimeValue) { if ($shift_dates) { trace(__FILE__, "copy():task shift dates"); $task->setDueDate(DateTimeValueLib::now()); $seconds = $source_task->getDueDate()->difference($source_created_on); $task->getDueDate()->advance($seconds); } $task->getDueDate()->advance($add_seconds); } $task->setText($source_task->getText()); $task->getAssignedToUserId($source_task->getAssignedToUserId()); $task->getAssignedToCompanyId($source_task->getAssignedToCompanyId()); $task_list->attachTask($task); } } } // foreach } // if } // if // project messages if ($copy_messages) { $source_messages = $source->getAllMessages(); if (is_array($source_messages)) { foreach ($source_messages as $source_message) { $message = new ProjectMessage(); //$message->copy($source_message); $message->setTitle($source_message->getTitle()); $message->setText($source_message->getText()); $message->setAdditionalText($source_message->getAdditionalText()); if ($copy_milestones) { $message->setMilestoneId($milestone_map[$source_message->getMilestoneId()]); } $message->setIsImportant($source_message->getIsImportant()); $message->setIsPrivate($source_message->getIsPrivate()); $message->setCommentsEnabled($source_message->getCommentsEnabled()); $message->setAnonymousCommentsEnabled($source_message->getAnonymousCommentsEnabled()); $message->setProjectId($project_id); $message->save(); } // foreach } // if } // if // project links if ($copy_links) { $source_links = ProjectLinks::getAllProjectLinks($source); if (is_array($source_links)) { foreach ($source_links as $source_link) { $link = new ProjectLink(); //$folder->copy($source_link); $link->setTitle($source_link->getTitle()); $link->setUrl($source_link->getUrl()); $link->setProjectId($project_id); $link->save(); } // foreach } // if } // if // project folders & files if ($copy_files) { $folder_map = array(0 => 0); $source_folders = $source->getFolders(); if (is_array($source_folders)) { foreach ($source_folders as $source_folder) { $folder = new ProjectFolder(); //$folder->copy($source_folder); $folder->setName($source_folder->getName()); $folder->setProjectId($project_id); $folder->save(); $folder_map[$source_folder->getId()] = $folder->getId(); } // foreach } // if $source_files = ProjectFiles::getAllFilesByProject($source); if (is_array($source_files)) { foreach ($source_files as $source_file) { $file = new ProjectFile(); $file->setProjectId($project_id); $file->setFolderId($folder_map[$source_file->getFolderId()]); $file->setFileName($source_file->getFileName()); $file->setDescription($source_file->getDescription()); $file->setIsPrivate($source_file->getIsPrivate()); $file->setIsImportant($source_file->getIsImportant()); $file->setIsLocked($source_file->getIsLocked()); $file->setIsVisible($source_file->getIsVisible()); $file->setExpirationTime($source_file->getExpirationTime()); $file->setCommentsEnabled($source_file->getCommentsEnabled()); $file->setAnonymousCommentsEnabled($source_file->getAnonymousCommentsEnabled()); $file->save(); $source_revision = $source_file->getLastRevision(); if ($source_revision instanceof ProjectFileRevision) { $revision = new ProjectFileRevision(); $revision->setFileId($file->getId()); $revision->setRevisionNumber($source_revision->getRevisionNumber()); $revision->setRepositoryId($source_revision->getRepositoryId()); $revision->setFilesize($source_revision->getFilesize()); $revision->setFilename($source_revision->getFileName()); $revision->setTypeString($source_revision->getTypeString()); $revision->setThumbFilename($source_revision->getThumbFilename()); $revision->setFileTypeId($source_revision->getFileTypeId()); $revision->setComment($source_revision->getComment()); $revision->save(); } } // foreach } // if } // if if ($copy_pages) { $source_pages = Wiki::getAllProjectPages($source); if (is_array($source_pages)) { foreach ($source_pages as $source_page) { $page = new WikiPage(); $page->setProjectId($project_id); $page->setProjectIndex($source_page->getProjectIndex()); $page->setProjectSidebar($source_page->getProjectSidebar()); if (plugin_active('tags')) { //$page->setTags($source_page->getTagNames()); } //Make a new revision of this page $revision = $page->makeRevision(); $source_revision = $source_page->getLatestRevision(); //Set attributes $revision->setName($source_revision->getName()); $revision->setContent($source_revision->getContent()); $revision->setLogMessage($source_revision->getLogMessage()); //Save the page $page->save(); } // foreach } // if } // if if ($copy_users) { $source_companies = ProjectCompanies::instance()->getCompaniesByProject($source); if (is_array($source_companies)) { foreach ($source_companies as $source_company) { $project_company = new ProjectCompany(); $project_company->setCompanyId($source_company->getId()); $project_company->setProjectId($project_id); $project_company->save(); } // foreach } $source_users = ProjectUsers::instance()->getUsersByProject($source); if (is_array($source_users)) { foreach ($source_users as $source_user) { $project_user = new ProjectUser(); $project_user->setUserId($source_user->getId()); $project_user->setProjectId($project_id); $project_user->save(); } // foreach } } /* $permissions = array_keys(PermissionManager::getPermissionsText()); $auto_assign_users = owner_company()->getAutoAssignUsers(); // We are getting the list of auto assign users. If current user is not in the list // add it. He's creating the project after all... if (is_array($auto_assign_users)) { $auto_assign_logged_user = false; foreach ($auto_assign_users as $user) { if ($user->getId() == logged_user()->getId()) { $auto_assign_logged_user = true; } } // if if (!$auto_assign_logged_user) { $auto_assign_users[] = logged_user(); } } else { $auto_assign_users[] = logged_user(); } // if foreach ($auto_assign_users as $user) { $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($user->getId()); if (is_array($permissions)) { foreach ($permissions as $permission) { $user = Users::findById($project_user->getUserId()); $user->setProjectPermission($project,$permission,true); } } // if $project_user->save(); } // foreach */ ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true); DB::commit(); flash_success(lang('success copy project', $source->getName(), $project->getName())); $this->redirectToUrl($project->getPermissionsUrl()); } catch (Exception $e) { echo $e->getMessage(); tpl_assign('error', $e); DB::rollback(); } // try } // if (submitted) }
/** * 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 }