예제 #1
0
 public function runBulkUpdateIssues(TBGRequest $request)
 {
     $issue_ids = $request['issue_ids'];
     $options = array('issue_ids' => array_values($issue_ids));
     TBGContext::loadLibrary('common');
     $options['last_updated'] = tbg_formatTime(time(), 20);
     if (!empty($issue_ids)) {
         $options['bulk_action'] = $request['bulk_action'];
         switch ($request['bulk_action']) {
             case 'assign_milestone':
                 $milestone = null;
                 if ($request['milestone'] == 'new') {
                     $milestone = new TBGMilestone();
                     $milestone->setProject(TBGContext::getCurrentProject());
                     $milestone->setName($request['milestone_name']);
                     $milestone->save();
                     $options['milestone_url'] = TBGContext::getRouting()->generate('project_planning_milestone', array('project_key' => $milestone->getProject()->getKey(), 'milestone_id' => $milestone->getID()));
                 } elseif ($request['milestone']) {
                     $milestone = new TBGMilestone($request['milestone']);
                 }
                 $milestone_id = $milestone instanceof TBGMilestone ? $milestone->getID() : null;
                 foreach (array_keys($issue_ids) as $issue_id) {
                     if (is_numeric($issue_id)) {
                         $issue = new TBGIssue($issue_id);
                         $issue->setMilestone($milestone_id);
                         $issue->save();
                     }
                 }
                 $options['milestone_id'] = $milestone_id;
                 $options['milestone_name'] = $milestone_id ? $milestone->getName() : '-';
                 break;
             case 'set_status':
                 if (is_numeric($request['status'])) {
                     $status = new TBGStatus($request['status']);
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new TBGIssue($issue_id);
                             $issue->setStatus($status->getID());
                             $issue->save();
                         }
                     }
                     $options['status'] = array('color' => $status->getColor(), 'name' => $status->getName(), 'id' => $status->getID());
                 }
                 break;
             case 'set_severity':
                 if (is_numeric($request['severity'])) {
                     $severity = $request['severity'] ? new TBGSeverity($request['severity']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new TBGIssue($issue_id);
                             $severity_id = $severity instanceof TBGSeverity ? $severity->getID() : 0;
                             $issue->setSeverity($severity_id);
                             $issue->save();
                         }
                     }
                     $options['severity'] = array('name' => $severity instanceof TBGSeverity ? $severity->getName() : '-', 'id' => $severity instanceof TBGSeverity ? $severity->getID() : 0);
                 }
                 break;
             case 'set_resolution':
                 if (is_numeric($request['resolution'])) {
                     $resolution = $request['resolution'] ? new TBGResolution($request['resolution']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new TBGIssue($issue_id);
                             $resolution_id = $resolution instanceof TBGResolution ? $resolution->getID() : 0;
                             $issue->setResolution($resolution_id);
                             $issue->save();
                         }
                     }
                     $options['resolution'] = array('name' => $resolution instanceof TBGResolution ? $resolution->getName() : '-', 'id' => $resolution instanceof TBGResolution ? $resolution->getID() : 0);
                 }
                 break;
             case 'set_priority':
                 if (is_numeric($request['priority'])) {
                     $priority = $request['priority'] ? new TBGPriority($request['priority']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new TBGIssue($issue_id);
                             $priority_id = $priority instanceof TBGPriority ? $priority->getID() : 0;
                             $issue->setPriority($priority_id);
                             $issue->save();
                         }
                     }
                     $options['priority'] = array('name' => $priority instanceof TBGPriority ? $priority->getName() : '-', 'id' => $priority instanceof TBGPriority ? $priority->getID() : 0);
                 }
                 break;
             case 'set_category':
                 if (is_numeric($request['category'])) {
                     $category = $request['category'] ? new TBGCategory($request['category']) : null;
                     foreach (array_keys($issue_ids) as $issue_id) {
                         if (is_numeric($issue_id)) {
                             $issue = new TBGIssue($issue_id);
                             $category_id = $category instanceof TBGCategory ? $category->getID() : 0;
                             $issue->setCategory($category_id);
                             $issue->save();
                         }
                     }
                     $options['category'] = array('name' => $category instanceof TBGCategory ? $category->getName() : '-', 'id' => $category instanceof TBGCategory ? $category->getID() : 0);
                 }
                 break;
         }
     }
     return $this->renderJSON($options);
 }
예제 #2
0
 public function runDoImportCSV(TBGRequest $request)
 {
     try {
         if ($request->getParameter('csv_data') == '') {
             throw new Exception(TBGContext::getI18n()->__('No data supplied to import'));
         }
         // Split data into individual lines
         $data = str_replace("\r\n", "\n", $request->getParameter('csv_data'));
         $data = explode("\n", $data);
         if (count($data) <= 1) {
             throw new Exception(TBGContext::getI18n()->__('Insufficient data to import'));
         }
         $headerrow = $data[0];
         $headerrow = html_entity_decode($headerrow, ENT_QUOTES);
         $headerrow = explode(',', $headerrow);
         $headerrow2 = array();
         for ($i = 0; $i != count($headerrow); $i++) {
             $headerrow2[$i] = trim($headerrow[$i], '" ');
         }
         $errors = array();
         // inspect for correct rows
         switch ($request->getParameter('type')) {
             case 'clients':
                 $namecol = null;
                 $emailcol = null;
                 $telephonecol = null;
                 $faxcol = null;
                 $websitecol = null;
                 for ($i = 0; $i != count($headerrow2); $i++) {
                     if ($headerrow2[$i] == 'name') {
                         $namecol = $i;
                     } elseif ($headerrow2[$i] == 'email') {
                         $emailcol = $i;
                     } elseif ($headerrow2[$i] == 'telephone') {
                         $telephonecol = $i;
                     } elseif ($headerrow2[$i] == 'fax') {
                         $faxcol = $i;
                     } elseif ($headerrow2[$i] == 'website') {
                         $websitecol = $i;
                     }
                 }
                 $rowlength = count($headerrow2);
                 if ($namecol === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'name'));
                 }
                 break;
             case 'projects':
                 $namecol = null;
                 $prefix = null;
                 $scrum = null;
                 $owner = null;
                 $owner_type = null;
                 $lead = null;
                 $lead_type = null;
                 $qa = null;
                 $qa_type = null;
                 $descr = null;
                 $doc_url = null;
                 $freelance = null;
                 $en_builds = null;
                 $en_comps = null;
                 $en_editions = null;
                 $workflow_id = null;
                 $client = null;
                 $show_summary = null;
                 $summary_type = null;
                 $issuetype_scheme = null;
                 $allow_reporting = null;
                 $autoassign = null;
                 for ($i = 0; $i != count($headerrow2); $i++) {
                     if ($headerrow2[$i] == 'name') {
                         $namecol = $i;
                     } elseif ($headerrow2[$i] == 'prefix') {
                         $prefix = $i;
                     } elseif ($headerrow2[$i] == 'scrum') {
                         $scrum = $i;
                     } elseif ($headerrow2[$i] == 'owner') {
                         $owner = $i;
                     } elseif ($headerrow2[$i] == 'owner_type') {
                         $owner_type = $i;
                     } elseif ($headerrow2[$i] == 'lead') {
                         $lead = $i;
                     } elseif ($headerrow2[$i] == 'lead_type') {
                         $lead_type = $i;
                     } elseif ($headerrow2[$i] == 'qa') {
                         $qa = $i;
                     } elseif ($headerrow2[$i] == 'qa_type') {
                         $qa_type = $i;
                     } elseif ($headerrow2[$i] == 'descr') {
                         $descr = $i;
                     } elseif ($headerrow2[$i] == 'doc_url') {
                         $doc_url = $i;
                     } elseif ($headerrow2[$i] == 'freelance') {
                         $freelance = $i;
                     } elseif ($headerrow2[$i] == 'en_builds') {
                         $en_builds = $i;
                     } elseif ($headerrow2[$i] == 'en_comps') {
                         $en_comps = $i;
                     } elseif ($headerrow2[$i] == 'en_editions') {
                         $en_editions = $i;
                     } elseif ($headerrow2[$i] == 'workflow_id') {
                         $workflow_id = $i;
                     } elseif ($headerrow2[$i] == 'client') {
                         $client = $i;
                     } elseif ($headerrow2[$i] == 'show_summary') {
                         $show_summary = $i;
                     } elseif ($headerrow2[$i] == 'summary_type') {
                         $summary_type = $i;
                     } elseif ($headerrow2[$i] == 'issuetype_scheme') {
                         $issuetype_scheme = $i;
                     } elseif ($headerrow2[$i] == 'allow_reporting') {
                         $allow_reporting = $i;
                     } elseif ($headerrow2[$i] == 'autoassign') {
                         $autoassign = $i;
                     }
                 }
                 $rowlength = count($headerrow2);
                 if ($namecol === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'name'));
                 }
                 break;
             case 'issues':
                 $title = null;
                 $project = null;
                 $descr = null;
                 $repro = null;
                 $state = null;
                 $status = null;
                 $posted_by = null;
                 $owner = null;
                 $owner_type = null;
                 $assigned = null;
                 $assigned_type = null;
                 $resolution = null;
                 $issue_type = null;
                 $priority = null;
                 $category = null;
                 $severity = null;
                 $reproducability = null;
                 $votes = null;
                 $percentage = null;
                 $blocking = null;
                 $milestone = null;
                 for ($i = 0; $i != count($headerrow2); $i++) {
                     if ($headerrow2[$i] == 'title') {
                         $title = $i;
                     } elseif ($headerrow2[$i] == 'project') {
                         $project = $i;
                     } elseif ($headerrow2[$i] == 'assigned') {
                         $assigned = $i;
                     } elseif ($headerrow2[$i] == 'repro') {
                         $repro = $i;
                     } elseif ($headerrow2[$i] == 'state') {
                         $state = $i;
                     } elseif ($headerrow2[$i] == 'status') {
                         $status = $i;
                     } elseif ($headerrow2[$i] == 'posted_by') {
                         $posted_by = $i;
                     } elseif ($headerrow2[$i] == 'owner') {
                         $owner = $i;
                     } elseif ($headerrow2[$i] == 'owner_type') {
                         $owner_type = $i;
                     } elseif ($headerrow2[$i] == 'assigned') {
                         $assigned = $i;
                     } elseif ($headerrow2[$i] == 'assigned_type') {
                         $assigned_type = $i;
                     } elseif ($headerrow2[$i] == 'resolution') {
                         $resolution = $i;
                     } elseif ($headerrow2[$i] == 'issue_type') {
                         $issue_type = $i;
                     } elseif ($headerrow2[$i] == 'priority') {
                         $priority = $i;
                     } elseif ($headerrow2[$i] == 'category') {
                         $category = $i;
                     } elseif ($headerrow2[$i] == 'severity') {
                         $severity = $i;
                     } elseif ($headerrow2[$i] == 'reproducability') {
                         $reproducability = $i;
                     } elseif ($headerrow2[$i] == 'votes') {
                         $votes = $i;
                     } elseif ($headerrow2[$i] == 'percentage') {
                         $percentage = $i;
                     } elseif ($headerrow2[$i] == 'blocking') {
                         $blocking = $i;
                     } elseif ($headerrow2[$i] == 'type') {
                         $issue_type = $i;
                     } elseif ($headerrow2[$i] == 'milestone') {
                         $milestone = $i;
                     }
                 }
                 $rowlength = count($headerrow2);
                 if ($title === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'title'));
                 }
                 if ($project === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'project'));
                 }
                 if ($issue_type === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'issue_type'));
                 }
                 break;
             default:
                 throw new Exception('Sorry, this type is unimplemented');
                 break;
         }
         // Check if rows are long enough
         for ($i = 1; $i != count($data); $i++) {
             $activerow = $data[$i];
             $activerow = html_entity_decode($activerow, ENT_QUOTES);
             $activerow = explode(',', $activerow);
             if (count($activerow) != $rowlength) {
                 $errors[] = TBGContext::getI18n()->__('Row %row% does not have the same number of elements as the header row', array('%row%' => $i + 1));
             }
         }
         reset($data);
         // Check if fields are empty
         for ($i = 1; $i != count($data); $i++) {
             $activerow = $data[$i];
             $activerow = html_entity_decode($activerow, ENT_QUOTES);
             $activerow = explode(',', $activerow);
             for ($j = 0; $j != count($activerow); $j++) {
                 if ($activerow[$j] == '' || $activerow[$j] == '""') {
                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col% has no value', array('%col%' => $j + 1, '%row%' => $i + 1));
                 }
             }
         }
         if (count($errors) == 0) {
             // Check if fields are valid
             switch ($request->getParameter('type')) {
                 case 'projects':
                     for ($i = 1; $i != count($data); $i++) {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         // Check if project exists
                         $key = trim($activerow[$namecol], '" ');
                         $key = str_replace(' ', '', $key);
                         $key = strtolower($key);
                         $tmp = TBGProject::getByKey($key);
                         if ($tmp !== null) {
                             $errors[] = TBGContext::getI18n()->__('Row %row%: A project with this name already exists', array('%row%' => $i + 1));
                         }
                         // First off are booleans
                         $boolitems = array($scrum, $allow_reporting, $autoassign, $freelance, $en_builds, $en_comps, $en_editions, $show_summary);
                         foreach ($boolitems as $boolitem) {
                             if ($boolitem !== null && trim($activerow[$boolitem], '"') != 0 && trim($activerow[$boolitem], '"') != 1) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1/0)', array('%col%' => $boolitem + 1, '%row%' => $i + 1));
                             }
                         }
                         // Now identifiables
                         $identifiableitems = array(array($qa, $qa_type), array($lead, $lead_type), array($owner, $owner_type));
                         foreach ($identifiableitems as $identifiableitem) {
                             if (($identifiableitem[0] === null || $identifiableitem[1] === null) && !($identifiableitem[0] === null && $identifiableitem[1] === null)) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row%: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row%' => $i + 1));
                                 continue;
                             }
                             if ($identifiableitem[1] !== null && trim($activerow[$identifiableitem[1]], '"') != 1 && trim($activerow[$identifiableitem[1]], '"') != 2) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1 for a user or 2 for a team)', array('%col%' => $identifiableitem[1] + 1, '%row%' => $i + 1));
                             }
                             if ($identifiableitem[0] !== null && !is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                             } elseif ($identifiableitem[0] !== null && is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 // check if they exist
                                 switch (trim($activerow[$identifiableitem[1]], '"')) {
                                     case 1:
                                         try {
                                             TBGContext::factory()->TBGUser(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: user does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                     case 2:
                                         try {
                                             TBGContext::factory()->TBGTeam(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: team does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                 }
                             }
                         }
                         // Now check client exists
                         if ($client !== null) {
                             if (!is_numeric(trim($activerow[$client], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $client + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGClient(trim($activerow[$client], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: client does not exist', array('%col%' => $client + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Now check if workflow exists
                         if ($workflow_id !== null) {
                             if (!is_numeric(trim($activerow[$workflow_id], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $workflow_id + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGWorkflowScheme(trim($activerow[$workflow_id], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: workflow scheme does not exist', array('%col%' => $workflow_id + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Now check if issuetype scheme
                         if ($issuetype_scheme !== null) {
                             if (!is_numeric(trim($activerow[$issuetype_scheme], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $issuetype_scheme + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGIssuetypeScheme(trim($activerow[$issuetype_scheme], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: issuetype scheme does not exist', array('%col%' => $issuetype_scheme + 1, '%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 ($summary_type !== null) {
                             if (trim($activerow[$summary_type], '"') != 'issuetypes' && trim($activerow[$summary_type], '"') != 'milestones') {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be \'issuetypes\' or \'milestones\')', array('%col%' => $summary_type + 1, '%row%' => $i + 1));
                             }
                         }
                     }
                     break;
                 case 'issues':
                     for ($i = 1; $i != count($data); $i++) {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         // Check if project exists
                         try {
                             $prjtmp = TBGContext::factory()->TBGProject($activerow[$project]);
                         } catch (Exception $e) {
                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: Project does not exist', array('%col%' => $project + 1, '%row%' => $i + 1));
                             break;
                         }
                         // First off are booleans
                         $boolitems = array($state, $blocking);
                         foreach ($boolitems as $boolitem) {
                             if ($boolitem !== null && trim($activerow[$boolitem], '"') != 0 && trim($activerow[$boolitem], '"') != 1) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1/0)', array('%col%' => $boolitem + 1, '%row%' => $i + 1));
                             }
                         }
                         // Now numerics
                         $numericitems = array($votes, $percentage);
                         foreach ($numericitems as $numericitem) {
                             if ($numericitem !== null && !is_numeric(trim($activerow[$numericitem], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $numericitem + 1, '%row%' => $i + 1));
                             }
                         }
                         // Percentage must be 0-100
                         if ($numericitem !== null && (trim($activerow[$percentage], '"') < 0 || trim($activerow[$percentage], '"') > 100)) {
                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: Percentage must be from 0 to 100 inclusive', array('%col%' => $percentage + 1, '%row%' => $i + 1));
                         }
                         // Now identifiables
                         $identifiableitems = array(array($owner, $owner_type), array($assigned, $assigned_type));
                         foreach ($identifiableitems as $identifiableitem) {
                             if (($identifiableitem[0] === null || $identifiableitem[1] === null) && !($identifiableitem[0] === null && $identifiableitem[1] === null)) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row%: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row%' => $i + 1));
                                 continue;
                             }
                             if ($identifiableitem[1] !== null && trim($activerow[$identifiableitem[1]], '"') != 1 && trim($activerow[$identifiableitem[1]], '"') != 2) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1 for a user or 2 for a team)', array('%col%' => $identifiableitem[1] + 1, '%row%' => $i + 1));
                             }
                             if ($identifiableitem[0] !== null && !is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                             } elseif ($identifiableitem[0] !== null && is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 // check if they exist
                                 switch (trim($activerow[$identifiableitem[1]], '"')) {
                                     case 1:
                                         try {
                                             TBGContext::factory()->TBGUser(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: user does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                     case 2:
                                         try {
                                             TBGContext::factory()->TBGTeam(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: team does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                 }
                             }
                         }
                         // Now check user exists for postedby
                         if ($posted_by !== null) {
                             if (!is_numeric(trim($activerow[$posted_by], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $posted_by + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGUser(trim($activerow[$posted_by], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: user does not exist', array('%col%' => $posted_by + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Now check milestone exists and is valid
                         if ($milestone !== null) {
                             if (!is_numeric(trim($activerow[$milestone], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $milestone + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     $milestonetmp = TBGContext::factory()->TBGMilestone(trim($activerow[$milestone], '" '));
                                     if ($milestonetmp->getProject()->getID() != $activerow[$project]) {
                                         $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: milestone does not apply to the specified project', array('%col%' => $milestone + 1, '%row%' => $i + 1));
                                     }
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: milestone does not exist', array('%col%' => $milestone + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // status
                         if ($status !== null) {
                             if (!is_numeric(trim($activerow[$status], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $status + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGStatus(trim($activerow[$status], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: status does not exist', array('%col%' => $status + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // resolution
                         if ($resolution !== null) {
                             if (!is_numeric(trim($activerow[$resolution], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $resolution + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGResolution(trim($activerow[$resolution], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: resolution does not exist', array('%col%' => $resolution + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // priority
                         if ($priority !== null) {
                             if (!is_numeric(trim($activerow[$priority], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $priority + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGPriority(trim($activerow[$priority], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: priority does not exist', array('%col%' => $priority + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // category
                         if ($category !== null) {
                             if (!is_numeric(trim($activerow[$category], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $category + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGCategory(trim($activerow[$category], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: category does not exist', array('%col%' => $category + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // severity
                         if ($severity !== null) {
                             if (!is_numeric(trim($activerow[$severity], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $severity + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGSeverity(trim($activerow[$severity], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: severity does not exist', array('%col%' => $severity + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // reproducability
                         if ($reproducability !== null) {
                             if (!is_numeric(trim($activerow[$reproducability], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $reproducability + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGReproducability(trim($activerow[$reproducability], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: reproducability does not exist', array('%col%' => $reproducability + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // type
                         if ($issue_type !== null) {
                             if (!is_numeric(trim($activerow[$issue_type], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $issue_type + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     $typetmp = TBGContext::factory()->TBGIssuetype(trim($activerow[$issue_type], '" '));
                                     if (!$prjtmp->getIssuetypeScheme()->isSchemeAssociatedWithIssuetype($typetmp)) {
                                         $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: this project does not support issues of this type (%type%)', array('%type%' => $typetmp->getName(), '%col%' => $issue_type + 1, '%row%' => $i + 1));
                                     }
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: issue type does not exist', array('%col%' => $issue_type + 1, '%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('failed' => true, 'errordetail' => $errordiv, 'error' => TBGContext::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('failed' => true, 'errordetail' => $e->getMessage(), 'error' => $e->getMessage()));
     }
     if ($request->getParameter('csv_dry_run')) {
         return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('Dry-run successful, you can now uncheck the dry-run box and import your data.')));
     } else {
         switch ($request->getParameter('type')) {
             case 'clients':
                 for ($i = 1; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         $client = new TBGClient();
                         $client->setName(trim($activerow[$namecol], '" '));
                         if ($emailcol !== null) {
                             $client->setEmail(trim($activerow[$emailcol], '" '));
                         }
                         if ($websitecol !== null) {
                             $client->setWebsite(trim($activerow[$websitecol], '" '));
                         }
                         if ($faxcol !== null) {
                             $client->setFax(trim($activerow[$faxcol], '" '));
                         }
                         if ($telephonecol !== null) {
                             $client->setTelephone(trim($activerow[$telephonecol], '" '));
                         }
                         $client->save();
                     } catch (Exception $e) {
                         $errors[] = TBGContext::getI18n()->__('Row %row% failed: %err%', array('%row%' => $i + 1, '%err%' => $e->getMessage()));
                     }
                 }
                 break;
             case 'projects':
                 for ($i = 1; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         $project = new TBGProject();
                         $project->setName(trim($activerow[$namecol], '" '));
                         if ($prefix !== null) {
                             $project->setPrefix(trim($activerow[$prefix], '" '));
                             $project->setUsePrefix(true);
                         }
                         if ($scrum !== null) {
                             if (trim($activerow[$websitecol], '"') == '1') {
                                 $project->setUseScrum(true);
                             }
                         }
                         if ($owner !== null && $owner_type !== null) {
                             switch (trim($activerow[$owner_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$owner], '" '));
                                     $project->setOwner($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$owner], '" '));
                                     $project->setOwner($team);
                                     break;
                             }
                         }
                         if ($lead !== null && $lead_type !== null) {
                             switch (trim($activerow[$lead_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$lead], '" '));
                                     $project->setLeader($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$lead], '" '));
                                     $project->setLeader($team);
                                     break;
                             }
                         }
                         if ($qa !== null && $qa_type !== null) {
                             switch (trim($activerow[$qa_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$qa], '" '));
                                     $project->setQaResponsible($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$qa], '" '));
                                     $project->setQaResponsible($team);
                                     break;
                             }
                         }
                         if ($descr !== null) {
                             $project->setDescription(trim($activerow[$descr], '" '));
                         }
                         if ($doc_url !== null) {
                             $project->setDocumentationUrl(trim($activerow[$doc_url], '" '));
                         }
                         if ($freelance !== null) {
                             if (trim($activerow[$freelance], '"') == '1') {
                                 $project->setChangeIssuesWithoutWorkingOnThem(true);
                             }
                         }
                         if ($en_builds !== null) {
                             if (trim($activerow[$en_builds], '"') == '1') {
                                 $project->setBuildsEnabled(true);
                             }
                         }
                         if ($en_comps !== null) {
                             if (trim($activerow[$en_comps], '"') == '1') {
                                 $project->setComponentsEnabled(true);
                             }
                         }
                         if ($en_editions !== null) {
                             if (trim($activerow[$en_editions], '"') == '1') {
                                 $project->setEditionsEnabled(true);
                             }
                         }
                         if ($workflow_id !== null) {
                             $workflow = TBGContext::factory()->TBGWorkflowScheme(trim($activerow[$workflow_id], '" '));
                             $project->setWorkflowScheme($workflow);
                         }
                         if ($client !== null) {
                             $client_object = TBGContext::factory()->TBGWorkflowScheme(trim($activerow[$client], '" '));
                             $project->setClient($client_object);
                         }
                         if ($show_summary !== null) {
                             if (trim($activerow[$show_summary], '"') == '1') {
                                 $project->setFrontpageSummaryVisibility(true);
                             }
                         }
                         if ($summary_type !== null) {
                             $project->setFrontpageSummaryType(trim($activerow[$summary_type], '" '));
                         }
                         if ($issuetype_scheme !== null) {
                             $project->setIssuetypeScheme(TBGContext::factory()->TBGIssuetypeScheme(trim($activerow[$issuetype_scheme], '"')));
                         }
                         if ($allow_reporting !== null) {
                             $project->setLocked(trim($activerow[$allow_reporting], '" '));
                         }
                         if ($autoassign !== null) {
                             $project->setAutoassign(trim($activerow[$autoassign], '" '));
                         }
                         $project->save();
                     } catch (Exception $e) {
                         $errors[] = TBGContext::getI18n()->__('Row %row% failed: %err%', array('%row%' => $i + 1, '%err%' => $e->getMessage()));
                     }
                 }
                 break;
             case 'issues':
                 for ($i = 1; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         $issue = new TBGIssue();
                         $issue->setTitle(trim($activerow[$title], '" '));
                         $issue->setProject(trim($activerow[$project], '" '));
                         $issue->setIssuetype(trim($activerow[$issue_type], '" '));
                         if ($issue_type !== null) {
                             $issue->setIssuetype(trim($activerow[$issue_type], '" '));
                         }
                         if ($descr !== null) {
                             $issue->setDescription(trim($activerow[$descr], '" '));
                         }
                         if ($repro !== null) {
                             $issue->setReproduction(trim($activerow[$repro], '" '));
                         }
                         if ($state !== null) {
                             $issue->setState(trim($activerow[$state], '" '));
                         }
                         if ($status !== null) {
                             $issue->setStatus(trim($activerow[$status], '" '));
                         }
                         if ($posted_by !== null) {
                             $issue->setPostedBy(TBGContext::factory()->TBGUser(trim($activerow[$posted_by], '"')));
                         }
                         if ($owner !== null && $owner_type !== null) {
                             switch (trim($activerow[$owner_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$owner], '" '));
                                     $issue->setOwner($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$owner], '" '));
                                     $issue->setOwner($team);
                                     break;
                             }
                         }
                         if ($assigned !== null && $assigned_type !== null) {
                             switch (trim($activerow[$assigned_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$assigned], '" '));
                                     $issue->setAssignee($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$assigned], '" '));
                                     $issue->setAssignee($team);
                                     break;
                             }
                         }
                         if ($resolution !== null) {
                             $issue->setResolution(trim($activerow[$resolution], '" '));
                         }
                         if ($priority !== null) {
                             $issue->setPriority(trim($activerow[$priority], '" '));
                         }
                         if ($category !== null) {
                             $issue->setCategory(trim($activerow[$category], '" '));
                         }
                         if ($blocking !== null) {
                             $issue->setBlocking(trim($activerow[$blocking], '" '));
                         }
                         if ($severity !== null) {
                             $issue->setSeverity(trim($activerow[$severity], '" '));
                         }
                         if ($reproducability !== null) {
                             $issue->setReproducability(trim($activerow[$reproducability], '" '));
                         }
                         if ($votes !== null) {
                             $issue->setVotes(trim($activerow[$votes], '" '));
                         }
                         if ($percentage !== null) {
                             $issue->setPercentage(trim($activerow[$percentage], '" '));
                         }
                         if ($milestone !== null) {
                             $issue->setMilestone(trim($activerow[$milestone], '" '));
                         }
                         $issue->save();
                     } catch (Exception $e) {
                         $errors[] = TBGContext::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('failed' => true, 'errordetail' => $errordiv, 'error' => TBGContext::getI18n()->__('Errors occured while importing, see the error list in the import screen for further details')));
         } else {
             return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('Successfully imported %num% rows!', array('%num%' => count($data) - 1))));
         }
     }
 }
예제 #3
0
 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'])))));
 }
예제 #4
0
 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)))));
         }
     }
 }
예제 #5
0
 /**
  * Add a task to a scrum user story
  *
  * @param TBGRequest $request
  */
 public function runScrumAddTask(TBGRequest $request)
 {
     $this->forward403unless($this->_checkProjectPageAccess('project_scrum'));
     $issue = TBGContext::factory()->TBGIssue($request->getParameter('story_id'));
     try {
         if ($issue instanceof TBGIssue) {
             $this->forward403unless($issue->canAddRelatedIssues());
             $task = new TBGIssue();
             $task->setTitle($request->getParameter('task_name'));
             $task->setIssuetype(TBGIssuetype::getTask()->getID());
             $task->setProject($issue->getProjectID());
             $task->setMilestone($issue->getMilestone() instanceof TBGMilestone ? $issue->getMilestone()->getID() : null);
             $task->save();
             $comment = $issue->addChildIssue($task);
             $mode = $request->getParameter('mode', 'scrum');
             if ($mode == 'scrum') {
                 return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('project/scrumstorytask', array('task' => $task)), 'count' => count($issue->getChildIssues())));
             } elseif ($mode == 'sprint') {
                 return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('project/scrumsprintdetailstask', array('task' => $task, 'can_estimate' => $issue->canEditEstimatedTime())), 'count' => count($issue->getChildIssues())));
             } else {
                 return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('main/relatedissue', array('theIssue' => $issue, 'related_issue' => $task)), 'comment' => $comment instanceof TBGComment ? $this->getTemplateHTML('main/comment', array('comment' => $comment, 'theIssue' => $issue)) : false, 'message' => TBGContext::getI18n()->__('The task was added')));
             }
         }
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Invalid user story')));
     } catch (Exception $e) {
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__("An error occured while trying to create a new task: %exception_message%", array('%exception_message%' => $e->getMessage()))));
     }
 }
예제 #6
0
 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;
 }
예제 #7
0
 public function processIncomingEmailAccount(TBGIncomingEmailAccount $account, $limit = 25)
 {
     $count = 0;
     if ($emails = $account->getUnprocessedEmails()) {
         try {
             $current_user = TBGContext::getUser();
             foreach ($emails as $email) {
                 $user = $this->getOrCreateUserFromEmailString($email->from);
                 if ($user instanceof TBGUser) {
                     if (TBGContext::getUser()->getID() != $user->getID()) {
                         TBGContext::switchUserContext($user);
                     }
                     $message = $account->getMessage($email);
                     $data = $message->getBodyPlain() ? $message->getBodyPlain() : strip_tags($message->getBodyHTML());
                     if ($data) {
                         if (mb_detect_encoding($data, 'UTF-8', true) === false) {
                             $data = utf8_encode($data);
                         }
                         $new_data = '';
                         foreach (explode("\n", $data) as $line) {
                             $line = trim($line);
                             if ($line) {
                                 $line = preg_replace('/^(_{2,}|-{2,})$/', "<hr>", $line);
                                 $new_data .= $line . "\n";
                             } else {
                                 $new_data .= "\n";
                             }
                         }
                         $data = nl2br($new_data, false);
                     }
                     // Parse the subject, and obtain the issues.
                     $parsed_commit = TBGIssue::getIssuesFromTextByRegex(mb_decode_mimeheader($email->subject));
                     $issues = $parsed_commit["issues"];
                     // If any issues were found, add new comment to each issue.
                     if ($issues) {
                         foreach ($issues as $issue) {
                             $text = preg_replace('#(^\\w.+:\\n)?(^>.*(\\n|$))+#mi', "", $data);
                             $text = trim($text);
                             if (!$this->processIncomingEmailCommand($text, $issue, $user) && $user->canPostComments()) {
                                 $comment = new TBGComment();
                                 $comment->setContent($text);
                                 $comment->setPostedBy($user);
                                 $comment->setTargetID($issue->getID());
                                 $comment->setTargetType(TBGComment::TYPE_ISSUE);
                                 $comment->save();
                             }
                         }
                     } else {
                         if ($user->canReportIssues($account->getProject())) {
                             $issue = new TBGIssue();
                             $issue->setProject($account->getProject());
                             $issue->setTitle(mb_decode_mimeheader($email->subject));
                             $issue->setDescription($data);
                             $issue->setPostedBy($user);
                             $issue->setIssuetype($account->getIssuetype());
                             $issue->save();
                             // Append the new issue to the list of affected issues. This
                             // is necessary in order to process the attachments properly.
                             $issues[] = $issue;
                         }
                     }
                     // If there was at least a single affected issue, and mail
                     // contains attachments, add those attachments to related issues.
                     if ($issues && $message->hasAttachments()) {
                         foreach ($message->getAttachments() as $attachment_no => $attachment) {
                             echo 'saving attachment ' . $attachment_no;
                             $name = $attachment['filename'];
                             $new_filename = TBGContext::getUser()->getID() . '_' . NOW . '_' . basename($name);
                             if (TBGSettings::getUploadStorage() == 'files') {
                                 $files_dir = TBGSettings::getUploadsLocalpath();
                                 $filename = $files_dir . $new_filename;
                             } else {
                                 $filename = $name;
                             }
                             TBGLogging::log('Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no);
                             echo 'Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no;
                             $content_type = $attachment['type'] . '/' . $attachment['subtype'];
                             $file = new TBGFile();
                             $file->setRealFilename($new_filename);
                             $file->setOriginalFilename(basename($name));
                             $file->setContentType($content_type);
                             $file->setDescription($name);
                             $file->setUploadedBy(TBGContext::getUser());
                             if (TBGSettings::getUploadStorage() == 'database') {
                                 $file->setContent($attachment['data']);
                             } else {
                                 TBGLogging::log('Saving file ' . $new_filename . ' with content from attachment ' . $attachment_no);
                                 file_put_contents($new_filename, $attachment['data']);
                             }
                             $file->save();
                             // Attach file to each related issue.
                             foreach ($issues as $issue) {
                                 $issue->attachFile($file);
                             }
                         }
                     }
                     $count++;
                 }
             }
         } catch (Exception $e) {
         }
         if (TBGContext::getUser()->getID() != $current_user->getID()) {
             TBGContext::switchUserContext($current_user);
         }
     }
     $account->setTimeLastFetched(time());
     $account->setNumberOfEmailsLastFetched($count);
     $account->save();
     return $count;
 }