/** * Configuration import page * * @param TBGRequest $request */ public function runImport(TBGRequest $request) { if ($request->isMethod(TBGRequest::POST)) { if ($request->getParameter('import_sample_data')) { $users = array(); $user1 = new TBGUser(); $user1->setUsername('john'); $user1->setPassword('john'); $user1->setBuddyname('John'); $user1->setRealname('John'); $user1->setActivated(); $user1->setEnabled(); $user1->save(); $users[] = $user1; $user2 = new TBGUser(); $user2->setUsername('jane'); $user2->setPassword('jane'); $user2->setBuddyname('Jane'); $user2->setRealname('Jane'); $user2->setActivated(); $user2->setEnabled(); $user2->save(); $users[] = $user2; $user3 = new TBGUser(); $user3->setUsername('jackdaniels'); $user3->setPassword('jackdaniels'); $user3->setBuddyname('Jack'); $user3->setRealname('Jack Daniels'); $user3->setActivated(); $user3->setEnabled(); $user3->save(); $users[] = $user3; $project1 = new TBGProject(); $project1->setName('Sample project 1'); $project1->setOwner($users[rand(0, 2)]); $project1->setLeader($users[rand(0, 2)]); $project1->setQaResponsible($users[rand(0, 2)]); $project1->setDescription('This is a sample project that is awesome. Try it out!'); $project1->setHomepage('http://www.google.com'); $project1->save(); $project2 = new TBGProject(); $project2->setName('Sample project 2'); $project2->setOwner($users[rand(0, 2)]); $project2->setLeader($users[rand(0, 2)]); $project2->setQaResponsible($users[rand(0, 2)]); $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!'); $project2->setHomepage('http://www.bing.com'); $project2->save(); foreach (array($project1, $project2) as $project) { for ($cc = 1; $cc <= 5; $cc++) { $milestone = new TBGMilestone(); $milestone->setName("Milestone {$cc}"); $milestone->setProject($project); $milestone->setType(TBGMilestone::TYPE_REGULAR); if ((bool) rand(0, 1)) { $milestone->setScheduledDate(NOW + 100000 * (20 * $cc)); } $milestone->save(); } } $p1_milestones = $project1->getMilestones(); $p2_milestones = $project2->getMilestones(); $issues = array(); $priorities = TBGPriority::getAll(); $categories = TBGCategory::getAll(); $severities = TBGSeverity::getAll(); $statuses = TBGStatus::getAll(); $reproducabilities = TBGReproducability::getAll(); $lorem_ipsum = TBGArticlesTable::getTable()->getArticleByName('LoremIpsum'); $lorem_ipsum = PublishFactory::article($lorem_ipsum->get(TBGArticlesTable::ID), $lorem_ipsum); $lorem_words = explode(' ', $lorem_ipsum->getContent()); foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) { $issuetype = TBGIssuetype::getIssuetypeByKeyish($issuetype); for ($cc = 1; $cc <= 10; $cc++) { $issue1 = new TBGIssue(); $issue1->setProject($project1); $issue1->setPostedBy($users[rand(0, 2)]); $issue1->setPosted(NOW - 86400 * rand(1, 30)); $title_string = ''; $description_string = ''; $rand_length = rand(4, 15); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $title_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $title_string .= '.'; $ucnext = true; } $title_string .= ' '; } $rand_length = rand(40, 500); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $description_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $description_string .= '.'; $ucnext = true; $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' '; } else { $description_string .= ' '; } } $issue1->setTitle(ucfirst($title_string)); $issue1->setDescription($description_string); $issue1->setIssuetype($issuetype); $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]); $issue1->setPriority($priorities[array_rand($priorities)]); $issue1->setCategory($categories[array_rand($categories)]); $issue1->setSeverity($severities[array_rand($severities)]); $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]); $issue1->setPercentCompleted(rand(0, 100)); $issue1->save(); $issue1->setStatus($statuses[array_rand($statuses)]); if (rand(0, 1)) { $issue1->setAssignee($users[array_rand($users)]); } $issue1->save(); $issues[] = $issue1; $issue2 = new TBGIssue(); $issue2->setProject($project2); $issue2->setPostedBy($users[rand(0, 2)]); $issue2->setPosted(NOW - 86400 * rand(1, 30)); $title_string = ''; $description_string = ''; $rand_length = rand(4, 15); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $title_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $title_string .= '.'; $ucnext = true; } $title_string .= ' '; } $rand_length = rand(40, 500); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : strtolower($word); $description_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $description_string .= '.'; $ucnext = true; $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' '; } else { $description_string .= ' '; } } $issue2->setTitle(ucfirst($title_string)); $issue2->setDescription($description_string); $issue2->setIssuetype($issuetype); $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]); $issue2->setPriority($priorities[array_rand($priorities)]); $issue2->setCategory($categories[array_rand($categories)]); $issue2->setSeverity($severities[array_rand($severities)]); $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]); $issue2->setPercentCompleted(rand(0, 100)); if (rand(0, 1)) { $issue1->setAssignee($users[array_rand($users)]); } $issue2->save(); $issue2->setStatus($statuses[array_rand($statuses)]); $issue2->save(); $issues[] = $issue2; } } $rand_issues_to_close = rand(8, 40); $resolutions = TBGResolution::getAll(); for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) { $issue = array_slice($issues, array_rand($issues), 1); $issue = $issue[0]; $issue->setResolution($resolutions[array_rand($resolutions)]); $issue->close(); $issue->save(); } $this->imported_data = true; $developer = TBGProjectAssigneesTable::getByType(TBGProjectAssigneesTable::TYPE_DEVELOPER); foreach (array($project1, $project2) as $project) { foreach ($users as $user) { $project->addAssignee($user, $developer->getID()); } } } } $project1 = TBGProject::getByKey('sampleproject1'); $project2 = TBGProject::getByKey('sampleproject2'); $this->canimport = !$project1 instanceof TBGProject && !$project2 instanceof TBGProject; }
public function perform(TBGIssue $issue, $request = null) { switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE_SELF: $issue->setAssignee(TBGContext::getUser()); break; case self::ACTION_SET_STATUS: if ($this->getTargetValue()) { $issue->setStatus(TBGContext::factory()->TBGStatus((int) $this->getTargetValue())); } else { $issue->setStatus($request['status_id']); } break; case self::ACTION_SET_MILESTONE: if ($this->getTargetValue()) { $issue->setMilestone(TBGContext::factory()->TBGMilestone((int) $this->getTargetValue())); } else { $issue->setMilestone($request['milestone_id']); } break; case self::ACTION_CLEAR_PRIORITY: $issue->setPriority(null); break; case self::ACTION_SET_PRIORITY: if ($this->getTargetValue()) { $issue->setPriority(TBGContext::factory()->TBGPriority((int) $this->getTargetValue())); } else { $issue->setPriority($request['priority_id']); } break; case self::ACTION_CLEAR_PERCENT: $issue->setPercentCompleted(0); break; case self::ACTION_SET_PERCENT: if ($this->getTargetValue()) { $issue->setPercentCompleted((int) $this->getTargetValue()); } else { $issue->setPercentCompleted((int) $request['percent_complete_id']); } break; case self::ACTION_CLEAR_DUPLICATE: $issue->setDuplicateOf(null); break; case self::ACTION_SET_DUPLICATE: $issue->setDuplicateOf($request['duplicate_issue_id']); break; case self::ACTION_CLEAR_RESOLUTION: $issue->setResolution(null); break; case self::ACTION_SET_RESOLUTION: if ($this->getTargetValue()) { $issue->setResolution(TBGContext::factory()->TBGResolution((int) $this->getTargetValue())); } else { $issue->setResolution($request['resolution_id']); } break; case self::ACTION_CLEAR_REPRODUCABILITY: $issue->setReproducability(null); break; case self::ACTION_SET_REPRODUCABILITY: if ($this->getTargetValue()) { $issue->setReproducability(TBGContext::factory()->TBGReproducability((int) $this->getTargetValue())); } else { $issue->setReproducability($request['reproducability_id']); } break; case self::ACTION_CLEAR_ASSIGNEE: $issue->clearAssignee(); break; case self::ACTION_ASSIGN_ISSUE: if ($this->getTargetValue()) { $target_details = explode('_', $this->_target_value); if ($target_details[0] == 'user') { $assignee = TBGUser::getB2DBTable()->selectById((int) $target_details[1]); } else { $assignee = TBGTeam::getB2DBTable()->selectById((int) $target_details[1]); } $issue->setAssignee($assignee); } else { $assignee = null; switch ($request['assignee_type']) { case 'user': $assignee = TBGUser::getB2DBTable()->selectById((int) $request['assignee_id']); break; case 'team': $assignee = TBGTeam::getB2DBTable()->selectById((int) $request['assignee_id']); break; } if ((bool) $request->getParameter('assignee_teamup', false) && $assignee instanceof TBGUser && $assignee->getID() != TBGContext::getUser()->getID()) { $team = new TBGTeam(); $team->setName($assignee->getBuddyname() . ' & ' . TBGContext::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($assignee); $team->addMember(TBGContext::getUser()); $assignee = $team; } $issue->setAssignee($assignee); } break; case self::ACTION_USER_START_WORKING: $issue->clearUserWorkingOnIssue(); if ($issue->getAssignee() instanceof TBGTeam && $issue->getAssignee()->isOndemand()) { $members = $issue->getAssignee()->getMembers(); $issue->startWorkingOnIssue(array_shift($members)); } elseif ($issue->getAssignee() instanceof TBGUser) { $issue->startWorkingOnIssue($issue->getAssignee()); } break; case self::ACTION_USER_STOP_WORKING: if ($request->getParameter('did', 'nothing') == 'nothing') { $issue->clearUserWorkingOnIssue(); } elseif ($request->getParameter('did', 'nothing') == 'this') { $times = array(); if ($request['timespent_manual']) { $times = TBGIssue::convertFancyStringToTime($request['timespent_manual']); } elseif ($request['timespent_specified_type']) { $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0); $times[$request['timespent_specified_type']] = $request['timespent_specified_value']; } if (array_sum($times) > 0) { $times['hours'] *= 100; $spenttime = new TBGIssueSpentTime(); $spenttime->setIssue($issue); $spenttime->setUser(TBGContext::getUser()); $spenttime->setSpentPoints($times['points']); $spenttime->setSpentHours($times['hours']); $spenttime->setSpentDays($times['days']); $spenttime->setSpentWeeks($times['weeks']); $spenttime->setSpentMonths($times['months']); $spenttime->setActivityType($request['timespent_activitytype']); $spenttime->setComment($request['timespent_comment']); $spenttime->save(); } $issue->clearUserWorkingOnIssue(); } else { $issue->stopWorkingOnIssue(); } break; } }
public function runUpdateMilestoneIssues(TBGRequest $request) { if ($request['milestone_id']) { $milestone = new TBGMilestone($request['milestone_id']); } else { $milestone = new TBGMilestone(); $milestone->setName(TBGContext::getI18n()->__('Unassigned issues / backlog')); $milestone->setId(0); $milestone->setProject($this->selected_project); } foreach ($request['issue_id'] as $issue_id) { $issue = new TBGIssue($issue_id); if (isset($request['estimated_hours'][$issue_id])) { $issue->setEstimatedHours($request['estimated_hours'][$issue_id]); } if (isset($request['estimated_points'][$issue_id])) { $issue->setEstimatedPoints($request['estimated_points'][$issue_id]); } if (isset($request['spent_hours'][$issue_id])) { $issue->setSpentHours($request['spent_hours'][$issue_id]); } if (isset($request['spent_points'][$issue_id])) { $issue->setSpentPoints($request['spent_points'][$issue_id]); } if (isset($request['priority'][$issue_id])) { $issue->setPriority($request['priority'][$issue_id]); } if (isset($request['percent_complete'][$issue_id])) { $issue->setPercentCompleted($request['percent_complete'][$issue_id]); } if (isset($request['severity'][$issue_id])) { $issue->setSeverity($request['severity'][$issue_id]); } if (isset($request['reproducability'][$issue_id])) { $issue->setReproducability($request['reproducability'][$issue_id]); } if (isset($request['category'][$issue_id])) { $issue->setCategory($request['category'][$issue_id]); } if (isset($request['customfield'])) { foreach ($request['customfield'] as $fieldkey => $data) { if (isset($data[$issue_id])) { $issue->setCustomField($fieldkey, $data[$issue_id]); } } } $issue->save(); } return $this->renderJSON(array('estimated_hours' => $milestone->getHoursEstimated(), 'estimated_points' => $milestone->getPointsEstimated(), 'message' => TBGContext::getI18n()->__('%num issue(s) updated', array('%num' => count($request['issue_id']))))); }
public function perform(TBGIssue $issue, $request = null) { switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE_SELF: $issue->setAssignee(TBGContext::getUser()); break; case self::ACTION_SET_STATUS: if ($this->getTargetValue()) { $issue->setStatus(TBGContext::factory()->TBGStatus((int) $this->getTargetValue())); } else { $issue->setStatus($request->getParameter('status_id')); } break; case self::ACTION_SET_MILESTONE: if ($this->getTargetValue()) { $issue->setMilestone(TBGContext::factory()->TBGMilestone((int) $this->getTargetValue())); } else { $issue->setMilestone($request->getParameter('milestone_id')); } break; case self::ACTION_CLEAR_PRIORITY: $issue->setPriority(null); break; case self::ACTION_SET_PRIORITY: if ($this->getTargetValue()) { $issue->setPriority(TBGContext::factory()->TBGPriority((int) $this->getTargetValue())); } else { $issue->setPriority($request->getParameter('priority_id')); } break; case self::ACTION_CLEAR_PERCENT: $issue->setPercentCompleted(0); break; case self::ACTION_SET_PERCENT: if ($this->getTargetValue()) { $issue->setPercentCompleted((int) $this->getTargetValue()); } else { $issue->setPercentCompleted((int) $request->getParameter('percent_complete_id')); } break; case self::ACTION_CLEAR_RESOLUTION: $issue->setResolution(null); break; case self::ACTION_SET_RESOLUTION: if ($this->getTargetValue()) { $issue->setResolution(TBGContext::factory()->TBGResolution((int) $this->getTargetValue())); } else { $issue->setResolution($request->getParameter('resolution_id')); } break; case self::ACTION_CLEAR_REPRODUCABILITY: $issue->setReproducability(null); break; case self::ACTION_SET_REPRODUCABILITY: if ($this->getTargetValue()) { $issue->setReproducability(TBGContext::factory()->TBGReproducability((int) $this->getTargetValue())); } else { $issue->setReproducability($request->getParameter('reproducability_id')); } break; case self::ACTION_CLEAR_ASSIGNEE: $issue->unsetAssignee(); break; case self::ACTION_ASSIGN_ISSUE: if ($this->getTargetValue()) { $issue->setAssignee(TBGContext::factory()->TBGUser((int) $this->getTargetValue())); } else { $assignee = null; switch ($request->getParameter('assignee_type')) { case TBGIdentifiableClass::TYPE_USER: $assignee = TBGContext::factory()->TBGUser($request->getParameter('assignee_id')); break; case TBGIdentifiableClass::TYPE_TEAM: $assignee = TBGContext::factory()->TBGTeam($request->getParameter('assignee_id')); break; } if ((bool) $request->getParameter('assignee_teamup', false)) { $team = new TBGTeam(); $team->setName($assignee->getBuddyname() . ' & ' . TBGContext::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($assignee); $team->addMember(TBGContext::getUser()); $assignee = $team; } $issue->setAssignee($assignee); } break; case self::ACTION_USER_START_WORKING: $issue->clearUserWorkingOnIssue(); if ($issue->getAssignee() instanceof TBGTeam && $issue->getAssignee()->isOndemand()) { $members = $issue->getAssignee()->getMembers(); $issue->startWorkingOnIssue(array_shift($members)); } else { $issue->startWorkingOnIssue($issue->getAssignee()); } break; case self::ACTION_USER_STOP_WORKING: if ($request->getParameter('did', 'nothing') == 'nothing') { $issue->clearUserWorkingOnIssue(); } else { $issue->stopWorkingOnIssue(); } break; } }
public function runDoImportCSV(TBGRequest $request) { try { if ($request['csv_data'] == '') { throw new Exception($this->getI18n()->__('No data supplied to import')); } $csv = str_replace("\r\n", "\n", $request['csv_data']); $csv = html_entity_decode($csv); $headerrow = null; $data = array(); $errors = array(); // Parse CSV $handle = fopen("php://memory", 'r+'); fputs($handle, $csv); rewind($handle); $i = 0; while (($row = fgetcsv($handle, 1000)) !== false) { if (!$headerrow) { $headerrow = $row; } else { if (count($headerrow) == count($row)) { $data[] = array_combine($headerrow, $row); } else { $errors[] = $this->getI18n()->__('Row %row does not have the same number of elements as the header row', array('%row' => $i)); } } $i++; } fclose($handle); if (empty($data)) { throw new Exception($this->getI18n()->__('Insufficient data to import')); } // Verify required columns are present based on type $requiredcols = array(self::CSV_TYPE_CLIENTS => array(self::CSV_CLIENT_NAME), self::CSV_TYPE_PROJECTS => array(self::CSV_PROJECT_NAME), self::CSV_TYPE_ISSUES => array(self::CSV_ISSUE_TITLE, self::CSV_ISSUE_PROJECT, self::CSV_ISSUE_ISSUE_TYPE)); if (!isset($requiredcols[$request['type']])) { throw new Exception('Sorry, this type is unimplemented'); } foreach ($requiredcols[$request['type']] as $col) { if (!in_array($col, $headerrow)) { $errors[] = $this->getI18n()->__('Required column \'%col\' not found in header row', array('%col' => $col)); } } // Check if rows are long enough and fields are not empty for ($i = 0; $i != count($data); $i++) { $activerow = $data[$i]; // Check if fields are empty foreach ($activerow as $col => $val) { if (strlen($val) == 0) { $errors[] = $this->getI18n()->__('Row %row column %col has no value', array('%col' => $col, '%row' => $i + 1)); } } } if (count($errors) == 0) { // Check if fields are valid switch ($request['type']) { case self::CSV_TYPE_PROJECTS: for ($i = 0; $i != count($data); $i++) { $activerow = $data[$i]; // Check if project exists $key = str_replace(' ', '', $activerow[self::CSV_PROJECT_NAME]); $key = mb_strtolower($key); $tmp = TBGProject::getByKey($key); if ($tmp !== null) { $errors[] = $this->getI18n()->__('Row %row: A project with this name already exists', array('%row' => $i + 1)); } // First off are booleans $boolitems = array(self::CSV_PROJECT_SCRUM, self::CSV_PROJECT_ALLOW_REPORTING, self::CSV_PROJECT_AUTOASSIGN, self::CSV_PROJECT_FREELANCE, self::CSV_PROJECT_EN_BUILDS, self::CSV_PROJECT_EN_COMPS, self::CSV_PROJECT_EN_EDITIONS, self::CSV_PROJECT_SHOW_SUMMARY); foreach ($boolitems as $boolitem) { if (array_key_exists($boolitem, $activerow) && isset($activerow[$boolitem]) && $activerow[$boolitem] != 1 && $activerow[$boolitem] != 0) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1/0)', array('%col' => $boolitem, '%row' => $i + 1)); } } // Now identifiables $identifiableitems = array(array(self::CSV_PROJECT_QA, self::CSV_PROJECT_QA_TYPE), array(self::CSV_PROJECT_LEAD, self::CSV_PROJECT_LEAD_TYPE), array(self::CSV_PROJECT_OWNER, self::CSV_PROJECT_OWNER_TYPE)); foreach ($identifiableitems as $identifiableitem) { if (!array_key_exists($identifiableitem[1], $activerow) && array_key_exists($identifiableitem[0], $activerow) || array_key_exists($identifiableitem[1], $activerow) && !array_key_exists($identifiableitem[0], $activerow)) { $errors[] = $this->getI18n()->__('Row %row: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row' => $i + 1)); continue; } if (array_key_exists($identifiableitem[1], $activerow) && isset($activerow[$identifiableitem[1]]) !== null && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_USER && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_TEAM) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1 for a user or 2 for a team)', array('%col' => $identifiableitem[1], '%row' => $i + 1)); } if (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && !is_numeric($activerow[$identifiableitem[0]])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } elseif (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && is_numeric($activerow[$identifiableitem[0]])) { // check if they exist switch ($activerow[$identifiableitem[1]]) { case self::CSV_IDENTIFIER_TYPE_USER: try { TBGContext::factory()->TBGUser($activerow[$identifiableitem[0]]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; case self::CSV_IDENTIFIER_TYPE_TEAM: try { TBGContext::factory()->TBGTeam($activerow[$identifiableitem[0]]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: team does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; } } } // Now check client exists if (array_key_exists(self::CSV_PROJECT_CLIENT, $activerow) && isset($activerow[self::CSV_PROJECT_CLIENT])) { if (!is_numeric($activerow[self::CSV_PROJECT_CLIENT])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_CLIENT, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGClient($activerow[self::CSV_PROJECT_CLIENT]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: client does not exist', array('%col' => self::CSV_PROJECT_CLIENT, '%row' => $i + 1)); } } } // Now check if workflow exists if (array_key_exists(self::CSV_PROJECT_WORKFLOW_ID, $activerow) && isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) { if (!is_numeric($activerow[self::CSV_PROJECT_WORKFLOW_ID])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_WORKFLOW_ID, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGWorkflowScheme($activerow[self::CSV_PROJECT_WORKFLOW_ID]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: workflow scheme does not exist', array('%col' => self::CSV_PROJECT_WORKFLOW_ID, '%row' => $i + 1)); } } } // Now check if issuetype scheme if (array_key_exists(self::CSV_PROJECT_ISSUETYPE_SCHEME, $activerow) && isset($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) { if (!is_numeric($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_ISSUETYPE_SCHEME, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGIssuetypeScheme($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: issuetype scheme does not exist', array('%col' => self::CSV_PROJECT_ISSUETYPE_SCHEME, '%row' => $i + 1)); } } } // Finally check if the summary type is valid. At this point, your error list has probably become so big it has eaten up all your available RAM... if (array_key_exists(self::CSV_PROJECT_SUMMARY_TYPE, $activerow) && isset($activerow[self::CSV_PROJECT_SUMMARY_TYPE])) { if ($activerow[self::CSV_PROJECT_SUMMARY_TYPE] != 'issuetypes' && $activerow[self::CSV_PROJECT_SHOW_SUMMARY] != 'milestones') { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be \'issuetypes\' or \'milestones\')', array('%col' => self::CSV_PROJECT_SUMMARY_TYPE, '%row' => $i + 1)); } } } break; case self::CSV_TYPE_ISSUES: for ($i = 0; $i != count($data); $i++) { $activerow = $data[$i]; // Check if project exists try { $prjtmp = TBGContext::factory()->TBGProject($activerow[self::CSV_ISSUE_PROJECT]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: Project does not exist', array('%col' => self::CSV_ISSUE_PROJECT, '%row' => $i + 1)); break; } // First off are booleans $boolitems = array(self::CSV_ISSUE_STATE, self::CSV_ISSUE_BLOCKING); foreach ($boolitems as $boolitem) { if (array_key_exists($boolitem, $activerow) && isset($activerow[$boolitem]) && $activerow[$boolitem] != 1 && $activerow[$boolitem] != 0) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1/0)', array('%col' => $boolitem, '%row' => $i + 1)); } } // Now numerics $numericitems = array(self::CSV_ISSUE_VOTES, self::CSV_ISSUE_PERCENTAGE, self::CSV_ISSUE_ISSUENO); foreach ($numericitems as $numericitem) { if (array_key_exists($numericitem, $activerow) && isset($activerow[$numericitem]) && !is_numeric($activerow[$numericitem])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $numericitem, '%row' => $i + 1)); } } // Percentage must be 0-100 if (array_key_exists(self::CSV_ISSUE_PERCENTAGE, $activerow) && isset($activerow[self::CSV_ISSUE_PERCENTAGE]) && ($activerow[self::CSV_ISSUE_PERCENTAGE] < 0 || $activerow[self::CSV_ISSUE_PERCENTAGE] > 100)) { $errors[] = $this->getI18n()->__('Row %row column %col: Percentage must be from 0 to 100 inclusive', array('%col' => self::CSV_ISSUE_PERCENTAGE, '%row' => $i + 1)); } // Now identifiables $identifiableitems = array(array(self::CSV_ISSUE_OWNER, self::CSV_ISSUE_OWNER_TYPE), array(self::CSV_ISSUE_ASSIGNED, self::CSV_ISSUE_ASSIGNED_TYPE)); foreach ($identifiableitems as $identifiableitem) { if (!array_key_exists($identifiableitem[1], $activerow) && array_key_exists($identifiableitem[0], $activerow) || array_key_exists($identifiableitem[1], $activerow) && !array_key_exists($identifiableitem[0], $activerow)) { $errors[] = $this->getI18n()->__('Row %row: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row' => $i + 1)); continue; } if (array_key_exists($identifiableitem[1], $activerow) && isset($activerow[$identifiableitem[1]]) && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_USER && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_TEAM) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1 for a user or 2 for a team)', array('%col' => $identifiableitem[1], '%row' => $i + 1)); } if (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && !is_numeric($activerow[$identifiableitem[0]])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } elseif (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && is_numeric($activerow[$identifiableitem[0]])) { // check if they exist switch ($activerow[$identifiableitem[1]]) { case self::CSV_IDENTIFIER_TYPE_USER: try { TBGContext::factory()->TBGUser($activerow[$identifiableitem[0]]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; case self::CSV_IDENTIFIER_TYPE_TEAM: try { TBGContext::factory()->TBGTeam($activerow[$identifiableitem[0]]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: team does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; } } } // Now timestamps if (array_key_exists(self::CSV_ISSUE_POSTED, $activerow) && isset($activerow[self::CSV_ISSUE_POSTED]) && (string) (int) $activerow[self::CSV_ISSUE_POSTED] !== $activerow[self::CSV_ISSUE_POSTED] && $activerow[self::CSV_ISSUE_POSTED] >= PHP_INT_MAX && $activerow[self::CSV_ISSUE_POSTED] <= ~PHP_INT_MAX) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a Unix timestamp)', array('%col' => self::CSV_ISSUE_POSTED, '%row' => $i + 1)); } // Now check user exists for postedby if (array_key_exists(self::CSV_ISSUE_POSTED_BY, $activerow) && isset($activerow[self::CSV_ISSUE_POSTED_BY])) { if (!is_numeric($activerow[self::CSV_ISSUE_POSTED_BY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_POSTED_BY, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGUser($activerow[self::CSV_ISSUE_POSTED_BY]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => self::CSV_ISSUE_POSTED_BY, '%row' => $i + 1)); } } } // Now check milestone exists and is valid if (array_key_exists(self::CSV_ISSUE_MILESTONE, $activerow) && isset($activerow[self::CSV_ISSUE_MILESTONE])) { if (!is_numeric($activerow[self::CSV_ISSUE_MILESTONE])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1)); } else { try { $milestonetmp = TBGContext::factory()->TBGMilestone($activerow[self::CSV_ISSUE_MILESTONE]); if ($milestonetmp->getProject()->getID() != $activerow[self::CSV_ISSUE_PROJECT]) { $errors[] = $this->getI18n()->__('Row %row column %col: milestone does not apply to the specified project', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1)); } } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: milestone does not exist', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1)); } } } // status if (array_key_exists(self::CSV_ISSUE_STATUS, $activerow) && isset($activerow[self::CSV_ISSUE_STATUS])) { if (!is_numeric($activerow[self::CSV_ISSUE_STATUS])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_STATUS, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGStatus($activerow[self::CSV_ISSUE_STATUS]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: status does not exist', array('%col' => self::CSV_ISSUE_STATUS, '%row' => $i + 1)); } } } // resolution if (array_key_exists(self::CSV_ISSUE_RESOLUTION, $activerow) && isset($activerow[self::CSV_ISSUE_RESOLUTION])) { if (!is_numeric($activerow[self::CSV_ISSUE_RESOLUTION])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_RESOLUTION, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGResolution($activerow[self::CSV_ISSUE_RESOLUTION]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: resolution does not exist', array('%col' => self::CSV_ISSUE_RESOLUTION, '%row' => $i + 1)); } } } // priority if (array_key_exists(self::CSV_ISSUE_PRIORITY, $activerow) && isset($activerow[self::CSV_ISSUE_PRIORITY])) { if (!is_numeric($activerow[self::CSV_ISSUE_PRIORITY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_PRIORITY, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGPriority($activerow[self::CSV_ISSUE_PRIORITY]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: priority does not exist', array('%col' => self::CSV_ISSUE_PRIORITY, '%row' => $i + 1)); } } } // category if (array_key_exists(self::CSV_ISSUE_CATEGORY, $activerow) && isset($activerow[self::CSV_ISSUE_CATEGORY])) { if (!is_numeric($activerow[self::CSV_ISSUE_CATEGORY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_CATEGORY, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGCategory($activerow[self::CSV_ISSUE_CATEGORY]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: category does not exist', array('%col' => self::CSV_ISSUE_CATEGORY, '%row' => $i + 1)); } } } // severity if (array_key_exists(self::CSV_ISSUE_SEVERITY, $activerow) && isset($activerow[self::CSV_ISSUE_SEVERITY])) { if (!is_numeric($activerow[self::CSV_ISSUE_SEVERITY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_SEVERITY, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGSeverity($activerow[self::CSV_ISSUE_SEVERITY]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: severity does not exist', array('%col' => self::CSV_ISSUE_SEVERITY, '%row' => $i + 1)); } } } // reproducability if (array_key_exists(self::CSV_ISSUE_REPRODUCIBILITY, $activerow) && isset($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) { if (!is_numeric($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_REPRODUCIBILITY, '%row' => $i + 1)); } else { try { TBGContext::factory()->TBGReproducability($activerow[self::CSV_ISSUE_REPRODUCIBILITY]); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: reproducability does not exist', array('%col' => self::CSV_ISSUE_REPRODUCIBILITY, '%row' => $i + 1)); } } } // type if (array_key_exists(self::CSV_ISSUE_ISSUE_TYPE, $activerow) && isset($activerow[self::CSV_ISSUE_ISSUE_TYPE])) { if (!is_numeric($activerow[self::CSV_ISSUE_ISSUE_TYPE])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1)); } else { try { $typetmp = TBGContext::factory()->TBGIssuetype($activerow[self::CSV_ISSUE_ISSUE_TYPE]); if (!$prjtmp->getIssuetypeScheme()->isSchemeAssociatedWithIssuetype($typetmp)) { $errors[] = $this->getI18n()->__('Row %row column %col: this project does not support issues of this type (%type)', array('%type' => $typetmp->getName(), '%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1)); } } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: issue type does not exist', array('%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1)); } } } } break; } } // Handle errors if (count($errors) != 0) { $errordiv = '<ul>'; foreach ($errors as $error) { $errordiv .= '<li>' . $error . '</li>'; } $errordiv .= '</ul>'; $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('errordetail' => $errordiv, 'error' => $this->getI18n()->__('Errors occured while importing, see the error list in the import screen for further details'))); } } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('errordetail' => $e->getMessage(), 'error' => $e->getMessage())); } if ($request['csv_dry_run']) { return $this->renderJSON(array('message' => $this->getI18n()->__('Dry-run successful, you can now uncheck the dry-run box and import your data.'))); } else { switch ($request['type']) { case self::CSV_TYPE_CLIENTS: for ($i = 0; $i != count($data); $i++) { try { $activerow = $data[$i]; $client = new TBGClient(); $client->setName($activerow[self::CSV_CLIENT_NAME]); if (isset($activerow[self::CSV_CLIENT_EMAIL])) { $client->setEmail($activerow[self::CSV_CLIENT_EMAIL]); } if (isset($activerow[self::CSV_CLIENT_WEBSITE])) { $client->setWebsite($activerow[self::CSV_CLIENT_WEBSITE]); } if (isset($activerow[self::CSV_CLIENT_FAX])) { $client->setFax($activerow[self::CSV_CLIENT_FAX]); } if (isset($activerow[self::CSV_CLIENT_TELEPHONE])) { $client->setTelephone($activerow[self::CSV_CLIENT_TELEPHONE]); } $client->save(); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage())); } } break; case self::CSV_TYPE_PROJECTS: for ($i = 0; $i != count($data); $i++) { try { $activerow = $data[$i]; $project = new TBGProject(); $project->setName($activerow[self::CSV_PROJECT_NAME]); $project->save(); if (isset($activerow[self::CSV_PROJECT_PREFIX])) { $project->setPrefix($activerow[self::CSV_PROJECT_PREFIX]); $project->setUsePrefix(true); } if (isset($activerow[self::CSV_PROJECT_SCRUM])) { if ($activerow[self::CSV_PROJECT_SCRUM] == '1') { $project->setUsesScrum(true); } } if (isset($activerow[self::CSV_PROJECT_OWNER]) && isset($activerow[self::CSV_PROJECT_OWNER_TYPE])) { switch ($activerow[self::CSV_PROJECT_OWNER_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new TBGUser($activerow[self::CSV_PROJECT_OWNER]); $project->setOwner($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new TBGTeam($activerow[self::CSV_PROJECT_OWNER]); $project->setOwner($team); break; } } if (isset($activerow[self::CSV_PROJECT_LEAD]) && isset($activerow[self::CSV_PROJECT_LEAD_TYPE])) { switch ($activerow[self::CSV_PROJECT_LEAD_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new TBGUser($activerow[self::CSV_PROJECT_LEAD]); $project->setLeader($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new TBGTeam($activerow[self::CSV_PROJECT_LEAD]); $project->setLeader($team); break; } } if (isset($activerow[self::CSV_PROJECT_QA]) && isset($activerow[self::CSV_PROJECT_QA_TYPE])) { switch ($activerow[self::CSV_PROJECT_QA_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new TBGUser($activerow[self::CSV_PROJECT_QA]); $project->setQaResponsible($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new TBGTeam($activerow[self::CSV_PROJECT_QA]); $project->setQaResponsible($team); break; } } if (isset($activerow[self::CSV_PROJECT_DESCR])) { $project->setDescription($activerow[self::CSV_PROJECT_DESCR]); } if (isset($activerow[self::CSV_PROJECT_DOC_URL])) { $project->setDocumentationUrl($activerow[self::CSV_PROJECT_DOC_URL]); } if (isset($activerow[self::CSV_PROJECT_WIKI_URL])) { $project->setWikiUrl($activerow[self::CSV_PROJECT_WIKI_URL]); } if (isset($activerow[self::CSV_PROJECT_FREELANCE])) { if ($activerow[self::CSV_PROJECT_FREELANCE] == '1') { $project->setChangeIssuesWithoutWorkingOnThem(true); } } if (isset($activerow[self::CSV_PROJECT_EN_BUILDS])) { if ($activerow[self::CSV_PROJECT_EN_BUILDS] == '1') { $project->setBuildsEnabled(true); } } if (isset($activerow[self::CSV_PROJECT_EN_COMPS])) { if ($activerow[self::CSV_PROJECT_EN_COMPS] == '1') { $project->setComponentsEnabled(true); } } if (isset($activerow[self::CSV_PROJECT_EN_EDITIONS])) { if ($activerow[self::CSV_PROJECT_EN_EDITIONS] == '1') { $project->setEditionsEnabled(true); } } if (isset($activerow[self::CSV_PROJECT_CLIENT])) { $project->setClient(TBGContext::factory()->TBGClient($activerow[self::CSV_PROJECT_CLIENT])); } if (isset($activerow[self::CSV_PROJECT_SHOW_SUMMARY])) { if ($activerow[self::CSV_PROJECT_SHOW_SUMMARY] == '1') { $project->setFrontpageSummaryVisibility(true); } } if (isset($activerow[self::CSV_PROJECT_SUMMARY_TYPE])) { $project->setFrontpageSummaryType($activerow[self::CSV_PROJECT_SUMMARY_TYPE]); } if (isset($activerow[self::CSV_PROJECT_ALLOW_REPORTING])) { $project->setLocked($activerow[self::CSV_PROJECT_ALLOW_REPORTING]); } if (isset($activerow[self::CSV_PROJECT_AUTOASSIGN])) { $project->setAutoassign($activerow[self::CSV_PROJECT_AUTOASSIGN]); } if (isset($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) { $project->setIssuetypeScheme(TBGContext::factory()->TBGIssuetypeScheme($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])); } if (isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) { } $project->setWorkflowScheme(TBGContext::factory()->TBGWorkflowScheme($activerow[self::CSV_PROJECT_WORKFLOW_ID])); $project->save(); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage())); } } break; case self::CSV_TYPE_ISSUES: for ($i = 0; $i != count($data); $i++) { try { $activerow = $data[$i]; $issue = new TBGIssue(); $issue->setTitle($activerow[self::CSV_ISSUE_TITLE]); $issue->setProject($activerow[self::CSV_ISSUE_PROJECT]); $issue->setIssuetype($activerow[self::CSV_ISSUE_ISSUE_TYPE]); $issue->save(); if (isset($activerow[self::CSV_ISSUE_DESCR])) { $issue->setDescription($activerow[self::CSV_ISSUE_DESCR]); } if (isset($activerow[self::CSV_ISSUE_REPRO])) { $issue->setReproductionSteps($activerow[self::CSV_ISSUE_REPRO]); } if (isset($activerow[self::CSV_ISSUE_STATE])) { $issue->setState($activerow[self::CSV_ISSUE_STATE]); } if (isset($activerow[self::CSV_ISSUE_STATUS])) { $issue->setStatus($activerow[self::CSV_ISSUE_STATUS]); } if (isset($activerow[self::CSV_ISSUE_POSTED_BY])) { $issue->setPostedBy(TBGContext::factory()->TBGUser($activerow[self::CSV_ISSUE_POSTED_BY])); } if (isset($activerow[self::CSV_ISSUE_OWNER]) && isset($activerow[self::CSV_ISSUE_OWNER_TYPE])) { switch ($activerow[self::CSV_ISSUE_OWNER_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new TBGUser($activerow[self::CSV_ISSUE_OWNER]); $issue->setOwner($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new TBGTeam($activerow[self::CSV_ISSUE_OWNER]); $issue->setOwner($team); break; } } if (isset($activerow[self::CSV_ISSUE_ASSIGNED]) && isset($activerow[self::CSV_ISSUE_ASSIGNED_TYPE])) { switch ($activerow[self::CSV_ISSUE_ASSIGNED_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new TBGUser($activerow[self::CSV_ISSUE_ASSIGNED]); $issue->setAssignee($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new TBGTeam($activerow[self::CSV_ISSUE_ASSIGNED]); $issue->setAssignee($team); break; } } if (isset($activerow[self::CSV_ISSUE_RESOLUTION])) { $issue->setResolution($activerow[self::CSV_ISSUE_RESOLUTION]); } if (isset($activerow[self::CSV_ISSUE_PRIORITY])) { $issue->setPriority($activerow[self::CSV_ISSUE_PRIORITY]); } if (isset($activerow[self::CSV_ISSUE_CATEGORY])) { $issue->setCategory($activerow[self::CSV_ISSUE_CATEGORY]); } if (isset($activerow[self::CSV_ISSUE_BLOCKING])) { $issue->setBlocking($activerow[self::CSV_ISSUE_BLOCKING]); } if (isset($activerow[self::CSV_ISSUE_SEVERITY])) { $issue->setSeverity($activerow[self::CSV_ISSUE_SEVERITY]); } if (isset($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) { $issue->setReproducability($activerow[self::CSV_ISSUE_REPRODUCIBILITY]); } if (isset($activerow[self::CSV_ISSUE_VOTES])) { $issue->setVotes($activerow[self::CSV_ISSUE_VOTES]); } if (isset($activerow[self::CSV_ISSUE_PERCENTAGE])) { $issue->setPercentCompleted($activerow[self::CSV_ISSUE_PERCENTAGE]); } if (isset($activerow[self::CSV_ISSUE_ISSUENO])) { $issue->setIssueNo((int) $activerow[self::CSV_ISSUE_ISSUENO]); } if (isset($activerow[self::CSV_ISSUE_MILESTONE])) { $issue->setMilestone($activerow[self::CSV_ISSUE_MILESTONE]); } if (isset($activerow[self::CSV_ISSUE_POSTED])) { $issue->setPosted((int) $activerow[self::CSV_ISSUE_POSTED]); } $issue->save(); } catch (Exception $e) { $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage())); } } break; } // Handle errors if (count($errors) != 0) { $errordiv = '<ul>'; foreach ($errors as $error) { $errordiv .= '<li>' . $error . '</li>'; } $errordiv .= '</ul>'; $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('errordetail' => $errordiv, 'error' => $this->getI18n()->__('Errors occured while importing, see the error list in the import screen for further details'))); } else { return $this->renderJSON(array('message' => $this->getI18n()->__('Successfully imported %num rows!', array('%num' => count($data))))); } } }
protected function _postIssue() { $fields_array = $this->selected_project->getReportableFieldsArray($this->issuetype_id); $issue = new TBGIssue(); $issue->setTitle($this->title); $issue->setIssuetype($this->issuetype_id); $issue->setProject($this->selected_project); if (isset($fields_array['description'])) { $issue->setDescription($this->selected_description); } if (isset($fields_array['description_syntax'])) { $issue->setDescriptionSyntax($this->selected_description_syntax); } if (isset($fields_array['reproduction_steps'])) { $issue->setReproductionSteps($this->selected_reproduction_steps); } if (isset($fields_array['reproduction_steps_syntax'])) { $issue->setReproductionStepsSyntax($this->selected_reproduction_steps_syntax); } if (isset($fields_array['category']) && $this->selected_category instanceof TBGDatatype) { $issue->setCategory($this->selected_category->getID()); } if (isset($fields_array['status']) && $this->selected_status instanceof TBGDatatype) { $issue->setStatus($this->selected_status->getID()); } if (isset($fields_array['reproducability']) && $this->selected_reproducability instanceof TBGDatatype) { $issue->setReproducability($this->selected_reproducability->getID()); } if (isset($fields_array['resolution']) && $this->selected_resolution instanceof TBGDatatype) { $issue->setResolution($this->selected_resolution->getID()); } if (isset($fields_array['severity']) && $this->selected_severity instanceof TBGDatatype) { $issue->setSeverity($this->selected_severity->getID()); } if (isset($fields_array['priority']) && $this->selected_priority instanceof TBGDatatype) { $issue->setPriority($this->selected_priority->getID()); } if (isset($fields_array['estimated_time'])) { $issue->setEstimatedTime($this->selected_estimated_time); } if (isset($fields_array['spent_time'])) { $issue->setSpentTime($this->selected_spent_time); } if (isset($fields_array['milestone']) || isset($this->selected_milestone)) { $issue->setMilestone($this->selected_milestone); } if (isset($fields_array['percent_complete'])) { $issue->setPercentCompleted($this->selected_percent_complete); } if (isset($fields_array['pain_bug_type'])) { $issue->setPainBugType($this->selected_pain_bug_type); } if (isset($fields_array['pain_likelihood'])) { $issue->setPainLikelihood($this->selected_pain_likelihood); } if (isset($fields_array['pain_effect'])) { $issue->setPainEffect($this->selected_pain_effect); } foreach (TBGCustomDatatype::getAll() as $customdatatype) { if (!isset($fields_array[$customdatatype->getKey()])) { continue; } if ($customdatatype->hasCustomOptions()) { if (isset($fields_array[$customdatatype->getKey()]) && $this->selected_customdatatype[$customdatatype->getKey()] instanceof TBGCustomDatatypeOption) { $selected_option = $this->selected_customdatatype[$customdatatype->getKey()]; $issue->setCustomField($customdatatype->getKey(), $selected_option->getID()); } } else { $issue->setCustomField($customdatatype->getKey(), $this->selected_customdatatype[$customdatatype->getKey()]); } } // FIXME: If we set the issue assignee during report issue, this needs to be set INSTEAD of this if ($this->selected_project->canAutoassign()) { if (isset($fields_array['component']) && $this->selected_component instanceof TBGComponent && $this->selected_component->hasLeader()) { $issue->setAssignee($this->selected_component->getLeader()); } elseif (isset($fields_array['edition']) && $this->selected_edition instanceof TBGEdition && $this->selected_edition->hasLeader()) { $issue->setAssignee($this->selected_edition->getLeader()); } elseif ($this->selected_project->hasLeader()) { $issue->setAssignee($this->selected_project->getLeader()); } } $issue->save(); if (isset($this->parent_issue)) { $issue->addParentIssue($this->parent_issue); } if (isset($fields_array['edition']) && $this->selected_edition instanceof TBGEdition) { $issue->addAffectedEdition($this->selected_edition); } if (isset($fields_array['build']) && $this->selected_build instanceof TBGBuild) { $issue->addAffectedBuild($this->selected_build); } if (isset($fields_array['component']) && $this->selected_component instanceof TBGComponent) { $issue->addAffectedComponent($this->selected_component); } return $issue; }