Ejemplo n.º 1
0
 public function addIdentity($identity, $user_id)
 {
     $user = \thebuggenie\core\entities\User::getB2DBTable()->selectById($user_id);
     $crit = $this->getCriteria();
     $crit->addInsert(self::IDENTITY, $identity);
     $crit->addInsert(self::IDENTITY_HASH, User::hashPassword($identity, $user->getSalt()));
     $crit->addInsert(self::UID, $user_id);
     $type = 'openid';
     foreach (self::getProviders() as $provider => $string) {
         if (stripos($identity, $string) !== false) {
             $type = $provider;
             break;
         }
     }
     $crit->addInsert(self::TYPE, $type);
     $this->doInsert($crit);
 }
Ejemplo n.º 2
0
 protected static function initializeUser()
 {
     Logging::log('Loading user');
     try {
         Logging::log('is this logout?');
         if (self::getRequest()->getParameter('logout')) {
             Logging::log('yes');
             self::logout();
         } else {
             Logging::log('no');
             Logging::log('sets up user object');
             $event = Event::createNew('core', 'pre_login');
             $event->trigger();
             if ($event->isProcessed()) {
                 self::loadUser($event->getReturnValue());
             } elseif (!self::isCLI()) {
                 self::loadUser();
             } else {
                 self::$_user = new User();
             }
             Event::createNew('core', 'post_login', self::getUser())->trigger();
             Logging::log('loaded');
             Logging::log('caching permissions');
             self::cacheAllPermissions();
             Logging::log('done (caching permissions)');
         }
     } catch (exceptions\ElevatedLoginException $e) {
         Logging::log("Could not reauthenticate elevated permissions: " . $e->getMessage(), 'main', Logging::LEVEL_INFO);
         self::setMessage('elevated_login_message_err', $e->getMessage());
         self::$_redirect_login = '******';
     } catch (\Exception $e) {
         Logging::log("Something happened while setting up user: " . $e->getMessage(), 'main', Logging::LEVEL_WARNING);
         $is_anonymous_route = self::isCLI() || self::getRouting()->isCurrentRouteAnonymousRoute();
         if (!$is_anonymous_route) {
             self::setMessage('login_message_err', $e->getMessage());
             self::$_redirect_login = '******';
         } else {
             self::$_user = User::getB2DBTable()->selectById(Settings::getDefaultUserID());
         }
     }
     Logging::log('...done');
 }
Ejemplo n.º 3
0
         <?php 
 if (!isset($include_issue_title) || $include_issue_title) {
     ?>
             <?php 
     echo link_tag(make_url('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())), $issue_title, array('class' => $log_action['change_type'] == \thebuggenie\core\entities\tables\Log::LOG_ISSUE_CLOSE ? 'issue_closed' : 'issue_open', 'style' => 'margin-top: 7px;'));
     ?>
         <?php 
 }
 ?>
         <?php 
 if ((!isset($include_issue_title) || $include_issue_title) && (isset($include_user) && $include_user == true)) {
     ?>
             <br>
             <span class="user">
                 <?php 
     if (($user = \thebuggenie\core\entities\User::getB2DBTable()->selectById($log_action['user_id'])) instanceof \thebuggenie\core\entities\User) {
         ?>
                     <?php 
         if ($log_action['change_type'] != \thebuggenie\core\entities\tables\Log::LOG_COMMENT) {
             ?>
                         <?php 
             echo $user->getNameWithUsername() . ':';
             ?>
                     <?php 
         } else {
             ?>
                         <?php 
             echo __('%user said', array('%user' => $user->getNameWithUsername())) . ':';
             ?>
                     <?php 
         }
 public function perform(\thebuggenie\core\entities\Issue $issue, $request = null)
 {
     switch ($this->_action_type) {
         case self::ACTION_ASSIGN_ISSUE_SELF:
             $issue->setAssignee(framework\Context::getUser());
             break;
         case self::ACTION_SET_STATUS:
             if ($this->getTargetValue()) {
                 $issue->setStatus(Status::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setStatus($request['status_id']);
             }
             break;
         case self::ACTION_CLEAR_MILESTONE:
             $issue->setMilestone(null);
             break;
         case self::ACTION_SET_MILESTONE:
             if ($this->getTargetValue()) {
                 $issue->setMilestone(Milestone::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setMilestone($request['milestone_id']);
             }
             break;
         case self::ACTION_CLEAR_PRIORITY:
             $issue->setPriority(null);
             break;
         case self::ACTION_SET_PRIORITY:
             if ($this->getTargetValue()) {
                 $issue->setPriority(Priority::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setPriority($request['priority_id']);
             }
             break;
         case self::ACTION_CLEAR_PERCENT:
             $issue->setPercentCompleted(0);
             break;
         case self::ACTION_SET_PERCENT:
             if ($this->getTargetValue()) {
                 $issue->setPercentCompleted((int) $this->getTargetValue());
             } else {
                 $issue->setPercentCompleted((int) $request['percent_complete_id']);
             }
             break;
         case self::ACTION_CLEAR_DUPLICATE:
             $issue->setDuplicateOf(null);
             break;
         case self::ACTION_SET_DUPLICATE:
             $issue->setDuplicateOf($request['duplicate_issue_id']);
             break;
         case self::ACTION_CLEAR_RESOLUTION:
             $issue->setResolution(null);
             break;
         case self::ACTION_SET_RESOLUTION:
             if ($this->getTargetValue()) {
                 $issue->setResolution(Resolution::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setResolution($request['resolution_id']);
             }
             break;
         case self::ACTION_CLEAR_REPRODUCABILITY:
             $issue->setReproducability(null);
             break;
         case self::ACTION_SET_REPRODUCABILITY:
             if ($this->getTargetValue()) {
                 $issue->setReproducability(Reproducability::getB2DBTable()->selectById((int) $this->getTargetValue()));
             } else {
                 $issue->setReproducability($request['reproducability_id']);
             }
             break;
         case self::ACTION_CLEAR_ASSIGNEE:
             $issue->clearAssignee();
             break;
         case self::ACTION_ASSIGN_ISSUE:
             if ($this->getTargetValue()) {
                 $target_details = explode('_', $this->_target_value);
                 if ($target_details[0] == 'user') {
                     $assignee = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $target_details[1]);
                 } else {
                     $assignee = Team::getB2DBTable()->selectById((int) $target_details[1]);
                 }
                 $issue->setAssignee($assignee);
             } else {
                 $assignee = null;
                 switch ($request['assignee_type']) {
                     case 'user':
                         $assignee = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $request['assignee_id']);
                         break;
                     case 'team':
                         $assignee = Team::getB2DBTable()->selectById((int) $request['assignee_id']);
                         break;
                 }
                 if ((bool) $request->getParameter('assignee_teamup', false) && $assignee instanceof \thebuggenie\core\entities\User && $assignee->getID() != framework\Context::getUser()->getID()) {
                     $team = new \thebuggenie\core\entities\Team();
                     $team->setName($assignee->getBuddyname() . ' & ' . framework\Context::getUser()->getBuddyname());
                     $team->setOndemand(true);
                     $team->save();
                     $team->addMember($assignee);
                     $team->addMember(framework\Context::getUser());
                     $assignee = $team;
                 }
                 $issue->setAssignee($assignee);
             }
             break;
         case self::ACTION_USER_START_WORKING:
             $issue->clearUserWorkingOnIssue();
             if ($issue->getAssignee() instanceof \thebuggenie\core\entities\Team && $issue->getAssignee()->isOndemand()) {
                 $members = $issue->getAssignee()->getMembers();
                 $issue->startWorkingOnIssue(array_shift($members));
             } elseif ($issue->getAssignee() instanceof \thebuggenie\core\entities\User) {
                 $issue->startWorkingOnIssue($issue->getAssignee());
             }
             break;
         case self::ACTION_USER_STOP_WORKING:
             if ($request->getParameter('did', 'nothing') == 'nothing') {
                 $issue->clearUserWorkingOnIssue();
             } elseif ($request->getParameter('did', 'nothing') == 'this') {
                 $times = array();
                 if ($request['timespent_manual']) {
                     $times = Issue::convertFancyStringToTime($request['timespent_manual']);
                 } elseif ($request['timespent_specified_type']) {
                     $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0);
                     $times[$request['timespent_specified_type']] = $request['timespent_specified_value'];
                 }
                 if (array_sum($times) > 0) {
                     $times['hours'] *= 100;
                     $spenttime = new \thebuggenie\core\entities\IssueSpentTime();
                     $spenttime->setIssue($issue);
                     $spenttime->setUser(framework\Context::getUser());
                     $spenttime->setSpentPoints($times['points']);
                     $spenttime->setSpentHours($times['hours']);
                     $spenttime->setSpentDays($times['days']);
                     $spenttime->setSpentWeeks($times['weeks']);
                     $spenttime->setSpentMonths($times['months']);
                     $spenttime->setActivityType($request['timespent_activitytype']);
                     $spenttime->setComment($request['timespent_comment']);
                     $spenttime->save();
                 }
                 $issue->clearUserWorkingOnIssue();
             } else {
                 $issue->stopWorkingOnIssue();
             }
             break;
         default:
             if (strpos($this->_action_type, self::CUSTOMFIELD_CLEAR_PREFIX) === 0) {
                 $customkey = substr($this->_action_type, strlen(self::CUSTOMFIELD_CLEAR_PREFIX));
                 $issue->setCustomField($customkey, null);
             } elseif (strpos($this->_action_type, self::CUSTOMFIELD_SET_PREFIX) === 0) {
                 $customkey = substr($this->_action_type, strlen(self::CUSTOMFIELD_SET_PREFIX));
                 if ($this->getTargetValue()) {
                     $issue->setCustomField($customkey, $this->getTargetValue());
                 } else {
                     $issue->setCustomField($customkey, $request[$customkey . '_id']);
                 }
             } else {
                 $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionAction::perform', $issue, array('request' => $request));
                 $event->triggerUntilProcessed();
             }
     }
 }
Ejemplo n.º 5
0
         $previous_value = $item->getPreviousValue() ? \thebuggenie\core\entities\Issue::getPainTypesOrLabel('pain_likelihood', $item->getPreviousValue()) : __('Not determined');
         $new_value = $item->getCurrentValue() ? \thebuggenie\core\entities\Issue::getPainTypesOrLabel('pain_likelihood', $item->getCurrentValue()) : __('Not determined');
         echo __("Likelihood on issue changed: %previous_value => %new_value", array('%previous_value' => '<strong>' . $previous_value . '</strong>', '%new_value' => '<strong>' . $new_value . '</strong>'));
     }
     break;
 case \thebuggenie\core\entities\tables\Log::LOG_ISSUE_PAIN_CALCULATED:
     echo image_tag('icon_percent.png');
     if ($item->hasChangeDetails()) {
         echo __("Calculated pain on issue changed: %value", array('%value' => '<strong>' . $item->getText() . '</strong>'));
     }
     break;
 case \thebuggenie\core\entities\tables\Log::LOG_ISSUE_USERS:
     echo image_tag('icon_user.png');
     if ($item->hasChangeDetails()) {
         $previous_value = $item->getPreviousValue() ? ($old_item = \thebuggenie\core\entities\User::getB2DBTable()->selectById($item->getPreviousValue())) ? __($old_item->getNameWithUsername()) : __('Unknown') : __('Not determined');
         $new_value = $item->getCurrentValue() ? ($new_item = \thebuggenie\core\entities\User::getB2DBTable()->selectById($item->getCurrentValue())) ? __($new_item->getNameWithUsername()) : __('Unknown') : __('Not determined');
         echo __("User working on issue changed: %previous_value => %new_value", array('%previous_value' => '<strong>' . $previous_value . '</strong>', '%new_value' => '<strong>' . $new_value . '</strong>'));
     }
     break;
 case \thebuggenie\core\entities\tables\Log::LOG_ISSUE_ASSIGNED:
     echo image_tag('icon_user.png');
     echo __("Assignee changed to %new_value", array('%new_value' => '<strong>' . $item->getText() . '</strong>'));
     break;
 case \thebuggenie\core\entities\tables\Log::LOG_ISSUE_TIME_SPENT:
     echo image_tag('icon_time.png');
     echo __("Time spent changed: %value", array('%value' => '<strong>' . $item->getText() . '</strong>'));
     break;
 case \thebuggenie\core\entities\tables\Log::LOG_ISSUE_PERCENT:
     echo image_tag('icon_percent.png');
     if ($item->hasChangeDetails()) {
         echo __("Percent complete changed: %previous_value => %new_value", array('%previous_value' => '<strong>' . (int) $item->getPreviousValue() . '</strong>', '%new_value' => '<strong>' . (int) $item->getCurrentValue() . '</strong>'));
Ejemplo n.º 6
0
 public function runDoImportCSV(framework\Request $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 = entities\Project::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 {
                                             entities\User::getB2DBTable()->selectByID($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 {
                                             entities\Team::getB2DBTable()->selectById($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 {
                                     entities\Client::getB2DBTable()->selectById($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 {
                                     entities\WorkflowScheme::getB2DBTable()->selectById($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 {
                                     entities\IssuetypeScheme::getB2DBTable()->selectById($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 = entities\Project::getB2DBTable()->selectByID($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 {
                                             entities\User::getB2DBTable()->selectByID($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 {
                                             entities\Team::getB2DBTable()->selectById($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 {
                                     entities\User::getB2DBTable()->selectByID($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 = entities\Milestone::getB2DBTable()->selectById($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 {
                                     entities\Status::getB2DBTable()->selectById($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 {
                                     entities\Resolution::getB2DBTable()->selectById($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 {
                                     entities\Priority::getB2DBTable()->selectById($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 {
                                     entities\Category::getB2DBTable()->selectById($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 {
                                     entities\Severity::getB2DBTable()->selectById($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 {
                                     entities\Reproducability::getB2DBTable()->selectById($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 = entities\Issuetype::getB2DBTable()->selectById($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 entities\Client();
                         $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 entities\Project();
                         $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 entities\User($activerow[self::CSV_PROJECT_OWNER]);
                                     $project->setOwner($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new entities\Team($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 entities\User($activerow[self::CSV_PROJECT_LEAD]);
                                     $project->setLeader($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new entities\Team($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 entities\User($activerow[self::CSV_PROJECT_QA]);
                                     $project->setQaResponsible($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new entities\Team($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(entities\Client::getB2DBTable()->selectById($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(entities\IssuetypeScheme::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME]));
                         }
                         if (isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) {
                         }
                         $project->setWorkflowScheme(entities\WorkflowScheme::getB2DBTable()->selectById($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 entities\Issue();
                         $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(entities\User::getB2DBTable()->selectByID($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 entities\User($activerow[self::CSV_ISSUE_OWNER]);
                                     $issue->setOwner($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new entities\Team($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 entities\User($activerow[self::CSV_ISSUE_ASSIGNED]);
                                     $issue->setAssignee($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new entities\Team($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)))));
         }
     }
 }
Ejemplo n.º 7
0
 public function listen_Article_doSave(framework\Event $event)
 {
     $article = $event->getSubject();
     $change_reason = $event->getParameter('reason');
     $revision = $event->getParameter('revision');
     $subject = 'Wiki article updated: %article_name';
     $user = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $event->getParameter('user_id'));
     $parameters = compact('article', 'change_reason', 'user', 'revision');
     $to_users = $this->_getArticleRelatedUsers($article, $user);
     if (!empty($to_users)) {
         $this->_markArticleSent($article, $to_users);
         $messages = $this->getTranslatedMessages('articleupdate', $parameters, $to_users, $subject, array('%article_name' => html_entity_decode($article->getTitle(), ENT_COMPAT, framework\Context::getI18n()->getCharset())));
         foreach ($messages as $message) {
             if ($project = $article->getProject()) {
                 $this->_addProjectEmailAddress($message, $project);
             }
             $this->sendMail($message);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Sets up the internal friends array
  */
 protected function _setupFriends()
 {
     if ($this->_friends === null) {
         $userids = tables\Buddies::getTable()->getFriendsByUserID($this->getID());
         $friends = array();
         foreach ($userids as $friend) {
             try {
                 $friend = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $friend);
                 $friends[$friend->getID()] = $friend;
             } catch (\Exception $e) {
                 $this->removeFriend($friend);
             }
         }
         $this->_friends = $friends;
     }
 }
Ejemplo n.º 9
0
 protected function _processChanges()
 {
     $related_issues_to_save = array();
     $changed_properties = $this->_getChangedProperties();
     if (count($changed_properties)) {
         $is_saved_estimated = false;
         $is_saved_spent = false;
         $is_saved_assignee = false;
         $is_saved_owner = false;
         foreach ($changed_properties as $property => $value) {
             $compare_value = is_object($this->{$property}) ? $this->{$property}->getID() : $this->{$property};
             $original_value = $value['original_value'];
             if ($original_value != $compare_value) {
                 switch ($property) {
                     case '_title':
                         $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_TITLE, framework\Context::getI18n()->__("Title updated"), $original_value, $compare_value);
                         break;
                     case '_shortname':
                         $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_SHORTNAME, framework\Context::getI18n()->__("Issue label updated"), $original_value, $compare_value);
                         break;
                     case '_description':
                         $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_DESCRIPTION, framework\Context::getI18n()->__("Description updated"), $original_value, $compare_value);
                         break;
                     case '_reproduction_steps':
                         $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_REPRODUCTIONSTEPS, framework\Context::getI18n()->__("Reproduction steps updated"), $original_value, $compare_value);
                         break;
                     case '_category':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Category::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Not determined');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getCategory() instanceof Datatype ? $this->getCategory()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_CATEGORY, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_pain_bug_type':
                         if ($original_value != 0) {
                             $old_name = ($old_item = self::getPainTypesOrLabel('pain_bug_type', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = ($new_item = self::getPainTypesOrLabel('pain_bug_type', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_BUG_TYPE, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_pain_effect':
                         if ($original_value != 0) {
                             $old_name = ($old_item = self::getPainTypesOrLabel('pain_effect', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = ($new_item = self::getPainTypesOrLabel('pain_effect', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_EFFECT, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_pain_likelihood':
                         if ($original_value != 0) {
                             $old_name = ($old_item = self::getPainTypesOrLabel('pain_likelihood', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = ($new_item = self::getPainTypesOrLabel('pain_likelihood', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_LIKELIHOOD, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_user_pain':
                         $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_CALCULATED, $original_value . ' &rArr; ' . $value['current_value']);
                         break;
                     case '_status':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Status::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getStatus() instanceof Datatype ? $this->getStatus()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_STATUS, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_reproducability':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Reproducability::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getReproducability() instanceof Datatype ? $this->getReproducability()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_REPRODUCABILITY, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_priority':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Priority::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getPriority() instanceof Datatype ? $this->getPriority()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_PRIORITY, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_assignee_team':
                     case '_assignee_user':
                         if (!$is_saved_assignee) {
                             $new_name = $this->getAssignee() instanceof \thebuggenie\core\entities\common\Identifiable ? $this->getAssignee()->getName() : framework\Context::getI18n()->__('Not assigned');
                             if ($this->getAssignee() instanceof \thebuggenie\core\entities\User) {
                                 $this->startWorkingOnIssue($this->getAssignee());
                             }
                             $this->addLogEntry(tables\Log::LOG_ISSUE_ASSIGNED, $new_name);
                             $is_saved_assignee = true;
                         }
                         break;
                     case '_posted_by':
                         $old_identifiable = $original_value ? \thebuggenie\core\entities\User::getB2DBTable()->selectById($original_value) : framework\Context::getI18n()->__('Unknown');
                         $old_name = $old_identifiable instanceof \thebuggenie\core\entities\User ? $old_identifiable->getName() : framework\Context::getI18n()->__('Unknown');
                         $new_name = $this->getPostedBy()->getName();
                         $this->addLogEntry(tables\Log::LOG_ISSUE_POSTED, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_being_worked_on_by_user':
                         if ($original_value != 0) {
                             $old_identifiable = \thebuggenie\core\entities\User::getB2DBTable()->selectById($original_value);
                             $old_name = $old_identifiable instanceof \thebuggenie\core\entities\User ? $old_identifiable->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not being worked on');
                         }
                         $new_name = $this->getUserWorkingOnIssue() instanceof \thebuggenie\core\entities\User ? $this->getUserWorkingOnIssue()->getName() : framework\Context::getI18n()->__('Not being worked on');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_USERS, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_owner_team':
                     case '_owner_user':
                         if (!$is_saved_owner) {
                             $new_name = $this->getOwner() instanceof \thebuggenie\core\entities\common\Identifiable ? $this->getOwner()->getName() : framework\Context::getI18n()->__('Not owned by anyone');
                             $this->addLogEntry(tables\Log::LOG_ISSUE_OWNED, $new_name);
                             $is_saved_owner = true;
                         }
                         break;
                     case '_percent_complete':
                         $this->addLogEntry(tables\Log::LOG_ISSUE_PERCENT, $original_value . '% &rArr; ' . $this->getPercentCompleted() . '', $original_value, $compare_value);
                         break;
                     case '_resolution':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Resolution::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getResolution() instanceof Datatype ? $this->getResolution()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_RESOLUTION, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_severity':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Severity::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getSeverity() instanceof Datatype ? $this->getSeverity()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_SEVERITY, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_milestone':
                         if ($original_value != 0) {
                             $old_name = ($old_item = \thebuggenie\core\entities\Milestone::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Not determined');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Not determined');
                         }
                         $new_name = $this->getMilestone() instanceof \thebuggenie\core\entities\Milestone ? $this->getMilestone()->getName() : framework\Context::getI18n()->__('Not determined');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_MILESTONE, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         $this->_milestone_order = 0;
                         break;
                     case '_issuetype':
                         if ($original_value != 0) {
                             $old_name = ($old_item = Issuetype::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                         } else {
                             $old_name = framework\Context::getI18n()->__('Unknown');
                         }
                         $new_name = $this->getIssuetype() instanceof \thebuggenie\core\entities\Issuetype ? $this->getIssuetype()->getName() : framework\Context::getI18n()->__('Unknown');
                         $this->addLogEntry(tables\Log::LOG_ISSUE_ISSUETYPE, $old_name . ' &rArr; ' . $new_name, $original_value, $compare_value);
                         break;
                     case '_estimated_months':
                     case '_estimated_weeks':
                     case '_estimated_days':
                     case '_estimated_hours':
                     case '_estimated_points':
                         if (!$is_saved_estimated) {
                             $old_time = array('months' => $this->getChangedPropertyOriginal('_estimated_months'), 'weeks' => $this->getChangedPropertyOriginal('_estimated_weeks'), 'days' => $this->getChangedPropertyOriginal('_estimated_days'), 'hours' => $this->getChangedPropertyOriginal('_estimated_hours'), 'points' => $this->getChangedPropertyOriginal('_estimated_points'));
                             $old_formatted_time = array_sum($old_time) > 0 ? Issue::getFormattedTime($old_time) : framework\Context::getI18n()->__('Not estimated');
                             $new_formatted_time = $this->hasEstimatedTime() ? Issue::getFormattedTime($this->getEstimatedTime()) : framework\Context::getI18n()->__('Not estimated');
                             $this->addLogEntry(tables\Log::LOG_ISSUE_TIME_ESTIMATED, $old_formatted_time . ' &rArr; ' . $new_formatted_time, serialize($old_time), serialize($this->getEstimatedTime()));
                             $is_saved_estimated = true;
                         }
                         break;
                     case '_spent_months':
                     case '_spent_weeks':
                     case '_spent_days':
                     case '_spent_hours':
                     case '_spent_points':
                         if (!$is_saved_spent) {
                             $old_time = array('months' => $this->getChangedPropertyOriginal('_spent_months'), 'weeks' => $this->getChangedPropertyOriginal('_spent_weeks'), 'days' => $this->getChangedPropertyOriginal('_spent_days'), 'hours' => round($this->getChangedPropertyOriginal('_spent_hours') / 100, 2), 'points' => $this->getChangedPropertyOriginal('_spent_points'));
                             $old_formatted_time = array_sum($old_time) > 0 ? Issue::getFormattedTime($old_time) : framework\Context::getI18n()->__('No time spent');
                             $new_formatted_time = $this->hasSpentTime() ? Issue::getFormattedTime($this->getSpentTime()) : framework\Context::getI18n()->__('No time spent');
                             $this->addLogEntry(tables\Log::LOG_ISSUE_TIME_SPENT, $old_formatted_time . ' &rArr; ' . $new_formatted_time, serialize($old_time), serialize($this->getSpentTime()));
                             $is_saved_spent = true;
                         }
                         break;
                     case '_state':
                         if ($this->isClosed()) {
                             $this->addLogEntry(tables\Log::LOG_ISSUE_CLOSE);
                             if ($this->getMilestone() instanceof \thebuggenie\core\entities\Milestone) {
                                 if ($this->getMilestone()->isSprint()) {
                                     if (!$this->getIssueType()->isTask()) {
                                         $this->setSpentPoints($this->getEstimatedPoints());
                                     } else {
                                         if ($this->getSpentHours() < $this->getEstimatedHours()) {
                                             $this->setSpentHours($this->getEstimatedHours());
                                         }
                                         foreach ($this->getParentIssues() as $parent_issue) {
                                             if ($parent_issue->checkTaskStates()) {
                                                 $related_issues_to_save[$parent_issue->getID()] = true;
                                             }
                                         }
                                     }
                                 }
                                 $this->getMilestone()->updateStatus();
                                 $this->getMilestone()->save();
                             }
                         } else {
                             $this->addLogEntry(tables\Log::LOG_ISSUE_REOPEN);
                         }
                         break;
                     case '_blocking':
                         if ($this->isBlocking()) {
                             $this->addLogEntry(tables\Log::LOG_ISSUE_BLOCKED);
                         } else {
                             $this->addLogEntry(tables\Log::LOG_ISSUE_UNBLOCKED);
                         }
                         break;
                     default:
                         if (mb_substr($property, 0, 12) == '_customfield') {
                             $key = mb_substr($property, 12);
                             $customdatatype = CustomDatatype::getByKey($key);
                             switch ($customdatatype->getType()) {
                                 case CustomDatatype::INPUT_TEXT:
                                     $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : framework\Context::getI18n()->__('Unknown');
                                     $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value);
                                     break;
                                 case CustomDatatype::INPUT_TEXTAREA_SMALL:
                                 case CustomDatatype::INPUT_TEXTAREA_MAIN:
                                     $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : framework\Context::getI18n()->__('Unknown');
                                     $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value);
                                     break;
                                 case CustomDatatype::EDITIONS_CHOICE:
                                 case CustomDatatype::COMPONENTS_CHOICE:
                                 case CustomDatatype::RELEASES_CHOICE:
                                 case CustomDatatype::MILESTONE_CHOICE:
                                 case CustomDatatype::STATUS_CHOICE:
                                 case CustomDatatype::TEAM_CHOICE:
                                 case CustomDatatype::USER_CHOICE:
                                 case CustomDatatype::CLIENT_CHOICE:
                                     $old_object = null;
                                     $new_object = null;
                                     try {
                                         switch ($customdatatype->getType()) {
                                             case CustomDatatype::EDITIONS_CHOICE:
                                                 $old_object = Edition::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::COMPONENTS_CHOICE:
                                                 $old_object = Component::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::RELEASES_CHOICE:
                                                 $old_object = Build::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::MILESTONE_CHOICE:
                                                 $old_object = Milestone::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::STATUS_CHOICE:
                                                 $old_object = Status::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::TEAM_CHOICE:
                                                 $old_object = Team::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::USER_CHOICE:
                                                 $old_object = User::getB2DBTable()->selectById($original_value);
                                                 break;
                                             case CustomDatatype::CLIENT_CHOICE:
                                                 $old_object = Client::getB2DBTable()->selectById($original_value);
                                                 break;
                                         }
                                     } catch (\Exception $e) {
                                     }
                                     try {
                                         switch ($customdatatype->getType()) {
                                             case CustomDatatype::EDITIONS_CHOICE:
                                             case CustomDatatype::COMPONENTS_CHOICE:
                                             case CustomDatatype::RELEASES_CHOICE:
                                             case CustomDatatype::MILESTONE_CHOICE:
                                             case CustomDatatype::STATUS_CHOICE:
                                             case CustomDatatype::TEAM_CHOICE:
                                             case CustomDatatype::USER_CHOICE:
                                             case CustomDatatype::CLIENT_CHOICE:
                                                 $new_object = $this->getCustomField($key);
                                                 break;
                                         }
                                     } catch (\Exception $e) {
                                     }
                                     $old_value = is_object($old_object) ? $old_object->getName() : framework\Context::getI18n()->__('Unknown');
                                     $new_value = is_object($new_object) ? $new_object->getName() : framework\Context::getI18n()->__('Unknown');
                                     $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' &rArr; ' . $new_value, $original_value, $compare_value);
                                     break;
                                 default:
                                     $old_item = null;
                                     try {
                                         $old_item = $original_value ? new CustomDatatypeOption($original_value) : null;
                                     } catch (\Exception $e) {
                                     }
                                     $old_value = $old_item instanceof \thebuggenie\core\entities\CustomDatatypeOption ? $old_item->getName() : framework\Context::getI18n()->__('Unknown');
                                     $new_value = $this->getCustomField($key) instanceof \thebuggenie\core\entities\CustomDatatypeOption ? $this->getCustomField($key)->getName() : framework\Context::getI18n()->__('Unknown');
                                     $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' &rArr; ' . $new_value, $original_value, $compare_value);
                                     break;
                             }
                         }
                         break;
                 }
             }
         }
         if ($is_saved_estimated) {
             tables\IssueEstimates::getTable()->saveEstimate($this->getID(), $this->_estimated_months, $this->_estimated_weeks, $this->_estimated_days, $this->_estimated_hours, $this->_estimated_points);
         }
     }
     return $related_issues_to_save;
 }
Ejemplo n.º 10
0
 public function runAddClientMember(framework\Request $request)
 {
     try {
         $user_id = (int) $request['user_id'];
         $client = tables\Clients::getTable()->selectById((int) $request['client_id']);
         $user = entities\User::getB2DBTable()->selectByID($user_id);
         $client->addMember($user);
         return $this->renderJSON(array('clientlistitem' => $this->getComponentHTML('configuration/clientuserlistitem', compact('client', 'user_id', 'user')), 'update_clients' => array('ids' => array($client->getID()), 'membercounts' => array($client->getID() => $client->getNumberOfMembers()))));
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }
Ejemplo n.º 11
0
 /**
  * Returns the user who posted the comment
  *
  * @return \thebuggenie\core\entities\User
  */
 public function getPostedBy()
 {
     try {
         return $this->_posted_by instanceof \thebuggenie\core\entities\User ? $this->_posted_by : \thebuggenie\core\entities\User::getB2DBTable()->selectById($this->_posted_by);
     } catch (\Exception $e) {
         return null;
     }
 }
Ejemplo n.º 12
0
 public function runGetACLFormEntry(framework\Request $request)
 {
     switch ($request['identifiable_type']) {
         case 'user':
             $target = entities\User::getB2DBTable()->selectById((int) $request['identifiable_value']);
             break;
         case 'team':
             $target = entities\Team::getB2DBTable()->selectById((int) $request['identifiable_value']);
             break;
     }
     if (!$target instanceof entities\common\Identifiable) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $this->getI18n()->__('Could not show permissions list')));
     }
     return $this->renderJSON(array('content' => $this->getComponentHTML('main/issueaclformentry', array('target' => $target))));
 }
Ejemplo n.º 13
0
 public function getByPermissionTargetIDAndModule($permission, $target_id, $module = 'core')
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::PERMISSION_TYPE, $permission);
     $crit->addWhere(self::TARGET_ID, $target_id);
     $crit->addWhere(self::MODULE, $module);
     $permissions = array();
     if ($res = $this->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $target = null;
             if ($uid = $row->get(self::UID)) {
                 $target = \thebuggenie\core\entities\User::getB2DBTable()->selectById($uid);
             }
             if ($tid = $row->get(self::TID)) {
                 $target = \thebuggenie\core\entities\Team::getB2DBTable()->selectById($tid);
             }
             if ($gid = $row->get(self::GID)) {
                 $target = \thebuggenie\core\entities\Group::getB2DBTable()->selectById($gid);
             }
             if ($target instanceof \thebuggenie\core\entities\common\Identifiable) {
                 $permissions[] = array('target' => $target, 'allowed' => (bool) $row->get(self::ALLOWED), 'user_id' => $row->get(self::UID), 'team_id' => $row->get(self::TID), 'group_id' => $row->get(self::GID));
             }
         }
     }
     return $permissions;
 }
Ejemplo n.º 14
0
 public function findInConfig($details, $limit = 50, $allow_keywords = true)
 {
     $crit = $this->getCriteria();
     switch ($details) {
         case 'unactivated':
             if ($allow_keywords) {
                 $crit->addWhere(self::ACTIVATED, false);
                 $limit = 500;
                 break;
             }
         case 'newusers':
             if ($allow_keywords) {
                 $crit->addWhere(self::JOINED, NOW - 1814400, Criteria::DB_GREATER_THAN_EQUAL);
                 $limit = 500;
                 break;
             }
         case '0-9':
             if ($allow_keywords) {
                 $ctn = $crit->returnCriterion(self::UNAME, array('0%', '1%', '2%', '3%', '4%', '5%', '6%', '7%', '8%', '9%'), Criteria::DB_IN);
                 $ctn->addOr(self::BUDDYNAME, array('0%', '1%', '2%', '3%', '4%', '5%', '6%', '7%', '8%', '9%'), Criteria::DB_IN);
                 $ctn->addOr(self::REALNAME, array('0%', '1%', '2%', '3%', '4%', '5%', '6%', '7%', '8%', '9%'), Criteria::DB_IN);
                 $crit->addWhere($ctn);
                 $limit = 500;
                 break;
             }
         case 'all':
             if ($allow_keywords) {
                 $limit = 500;
                 break;
             }
         default:
             if (mb_strlen($details) == 1) {
                 $limit = 500;
             }
             $details = mb_strlen($details) == 1 ? mb_strtolower("{$details}%") : mb_strtolower("%{$details}%");
             $ctn = $crit->returnCriterion(self::UNAME, $details, Criteria::DB_LIKE);
             $ctn->addOr(self::BUDDYNAME, $details, Criteria::DB_LIKE);
             $ctn->addOr(self::REALNAME, $details, Criteria::DB_LIKE);
             $ctn->addOr(self::EMAIL, $details, Criteria::DB_LIKE);
             $crit->addWhere($ctn);
             break;
     }
     $crit->addJoin(UserScopes::getTable(), UserScopes::USER_ID, self::ID, array(), Criteria::DB_INNER_JOIN);
     $crit->addWhere(UserScopes::SCOPE, framework\Context::getScope()->getID());
     $crit->addWhere(self::DELETED, false);
     $users = array();
     $res = null;
     if ($details != '' && ($res = $this->doSelect($crit))) {
         while (($row = $res->getNextRow()) && count($users) < $limit) {
             $user_id = (int) $row->get(self::ID);
             $details = UserScopes::getTable()->getUserDetailsByScope($user_id, framework\Context::getScope()->getID());
             if (!$details) {
                 continue;
             }
             $users[$user_id] = \thebuggenie\core\entities\User::getB2DBTable()->selectById($user_id);
             $users[$user_id]->setScopeConfirmed($details['confirmed']);
         }
     }
     return $users;
 }
Ejemplo n.º 15
0
 /**
  * Configure project leaders
  *
  * @param framework\Request $request The request object
  */
 public function runSetItemLead(framework\Request $request)
 {
     try {
         switch ($request['item_type']) {
             case 'project':
                 $item = entities\Project::getB2DBTable()->selectById($request['project_id']);
                 break;
             case 'edition':
                 $item = entities\Edition::getB2DBTable()->selectById($request['edition_id']);
                 break;
             case 'component':
                 $item = entities\Component::getB2DBTable()->selectById($request['component_id']);
                 break;
         }
     } catch (\Exception $e) {
     }
     $this->forward403unless(isset($item) && $item instanceof entities\common\Identifiable);
     if ($request->hasParameter('value')) {
         $this->forward403unless($request['item_type'] == 'project' && $this->getUser()->canEditProjectDetails($this->selected_project) || $request['item_type'] != 'project' && $this->getUser()->canManageProjectReleases($this->selected_project));
         if ($request->hasParameter('identifiable_type')) {
             if (in_array($request['identifiable_type'], array('team', 'user')) && $request['value']) {
                 switch ($request['identifiable_type']) {
                     case 'user':
                         $identified = entities\User::getB2DBTable()->selectById($request['value']);
                         break;
                     case 'team':
                         $identified = entities\Team::getB2DBTable()->selectById($request['value']);
                         break;
                 }
                 if ($identified instanceof entities\common\Identifiable) {
                     if ($request['field'] == 'owned_by') {
                         $item->setOwner($identified);
                     } elseif ($request['field'] == 'qa_by') {
                         $item->setQaResponsible($identified);
                     } elseif ($request['field'] == 'lead_by') {
                         $item->setLeader($identified);
                     }
                     $item->save();
                 }
             } else {
                 if ($request['field'] == 'owned_by') {
                     $item->clearOwner();
                 } elseif ($request['field'] == 'qa_by') {
                     $item->clearQaResponsible();
                 } elseif ($request['field'] == 'lead_by') {
                     $item->clearLeader();
                 }
                 $item->save();
             }
         }
         if ($request['field'] == 'owned_by') {
             return $this->renderJSON(array('field' => $item->hasOwner() ? array('id' => $item->getOwner()->getID(), 'name' => $item->getOwner() instanceof entities\User ? $this->getComponentHTML('main/userdropdown', array('user' => $item->getOwner())) : $this->getComponentHTML('main/teamdropdown', array('team' => $item->getOwner()))) : array('id' => 0)));
         } elseif ($request['field'] == 'lead_by') {
             return $this->renderJSON(array('field' => $item->hasLeader() ? array('id' => $item->getLeader()->getID(), 'name' => $item->getLeader() instanceof entities\User ? $this->getComponentHTML('main/userdropdown', array('user' => $item->getLeader())) : $this->getComponentHTML('main/teamdropdown', array('team' => $item->getLeader()))) : array('id' => 0)));
         } elseif ($request['field'] == 'qa_by') {
             return $this->renderJSON(array('field' => $item->hasQaResponsible() ? array('id' => $item->getQaResponsible()->getID(), 'name' => $item->getQaResponsible() instanceof entities\User ? $this->getComponentHTML('main/userdropdown', array('user' => $item->getQaResponsible())) : $this->getComponentHTML('main/teamdropdown', array('team' => $item->getQaResponsible()))) : array('id' => 0)));
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Toggle favourite article (starring)
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runToggleFavouriteArticle(framework\Request $request)
 {
     if ($article_id = $request['article_id']) {
         try {
             $article = Articles::getTable()->selectById($article_id);
             $user = \thebuggenie\core\entities\User::getB2DBTable()->selectById($request['user_id']);
         } catch (\Exception $e) {
             return $this->renderText('fail');
         }
     } else {
         return $this->renderText('no article');
     }
     if ($user->isArticleStarred($article_id)) {
         $retval = !$user->removeStarredArticle($article_id);
     } else {
         $retval = $user->addStarredArticle($article_id);
         if ($user->getID() != $this->getUser()->getID()) {
             framework\Event::createNew('core', 'article_subscribe_user', $article, compact('user'))->trigger();
         }
     }
     return $this->renderText(json_encode(array('starred' => $retval, 'subscriber' => $this->getComponentHTML('publish/articlesubscriber', array('user' => $user, 'article' => $article)))));
 }
Ejemplo n.º 17
0
 public function getMembers()
 {
     if ($this->_members === null) {
         $this->_members = array();
         foreach (tables\TeamMembers::getTable()->getUIDsForTeamID($this->getID()) as $uid) {
             $this->_members[$uid] = \thebuggenie\core\entities\User::getB2DBTable()->selectById($uid);
         }
     }
     return $this->_members;
 }
Ejemplo n.º 18
0
 /**
  * Return the default user
  *
  * @return \thebuggenie\core\entities\User
  */
 public static function getDefaultUser()
 {
     try {
         return \thebuggenie\core\entities\User::getB2DBTable()->selectByID((int) self::get(self::SETTING_DEFAULT_USER_ID));
     } catch (\Exception $e) {
         return null;
     }
 }
                 <?php 
     echo __('Set resolution to %resolution', array('%resolution' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\Resolution::getB2DBTable()->selectById((int) $action->getTargetValue())->getName() : __('Resolution provided by user')) . '</span>'));
     ?>
             <?php 
 } elseif ($action->getActionType() == \thebuggenie\core\entities\WorkflowTransitionAction::ACTION_SET_REPRODUCABILITY) {
     ?>
                 <?php 
     echo __('Set reproducability to %reproducability', array('%reproducability' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? \thebuggenie\core\entities\Reproducability::getB2DBTable()->selectById((int) $action->getTargetValue())->getName() : __('Reproducability provided by user')) . '</span>'));
     ?>
             <?php 
 } elseif ($action->getActionType() == \thebuggenie\core\entities\WorkflowTransitionAction::ACTION_ASSIGN_ISSUE) {
     ?>
                 <?php 
     if ($action->hasTargetValue()) {
         $target_details = explode('_', $action->getTargetValue());
         echo __('Assign issue to %assignee', array('%assignee' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($target_details[0] == 'user' ? \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $target_details[1])->getNameWithUsername() : \thebuggenie\core\entities\Team::getB2DBTable()->selectById((int) $target_details[1])->getName()) . '</span>'));
     } else {
         echo __('Assign issue to %assignee', array('%assignee' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . __('User or team specified during transition') . '</span>'));
     }
     ?>
             <?php 
 } elseif ($action->isCustomSetAction()) {
     ?>
                 <?php 
     $tbg_response->addJavascript('calendarview.js');
     switch (\thebuggenie\core\entities\CustomDatatype::getByKey($action->getCustomActionType())->getType()) {
         case \thebuggenie\core\entities\CustomDatatype::INPUT_TEXTAREA_MAIN:
         case \thebuggenie\core\entities\CustomDatatype::INPUT_TEXTAREA_SMALL:
         case \thebuggenie\core\entities\CustomDatatype::INPUT_TEXT:
         case \thebuggenie\core\entities\CustomDatatype::CALCULATED_FIELD:
             echo __('Set issue field %key to %value', array('%key' => $action->getCustomActionType(), '%value' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ?: __('Value provided by user')) . '</span>'));
Ejemplo n.º 20
0
 protected function _upgradeFrom3dot2(framework\Request $request)
 {
     set_time_limit(0);
     \thebuggenie\core\entities\tables\Milestones::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGMilestone::getB2DBTable());
     \thebuggenie\core\entities\tables\Projects::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGProjectsTable::getTable());
     \thebuggenie\core\entities\tables\Log::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGLogTable::getTable());
     \thebuggenie\core\entities\tables\Users::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGUsersTable::getTable());
     \thebuggenie\core\entities\tables\Issues::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGIssuesTable::getTable());
     \thebuggenie\core\entities\tables\Workflows::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGWorkflowsTable::getTable());
     \thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGIssueSpentTimesTable::getTable());
     \thebuggenie\core\entities\tables\Comments::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGCommentsTable::getTable());
     \thebuggenie\core\entities\tables\SavedSearches::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGSavedSearchesTable::getTable());
     \thebuggenie\core\entities\tables\Settings::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGSettingsTable::getTable());
     \thebuggenie\core\entities\tables\Notifications::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGNotificationsTable::getTable());
     \thebuggenie\core\entities\tables\Permissions::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGPermissionsTable::getTable());
     \thebuggenie\core\entities\Dashboard::getB2DBTable()->create();
     \thebuggenie\core\entities\DashboardView::getB2DBTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGDashboardViewsTable::getTable());
     \thebuggenie\core\entities\ApplicationPassword::getB2DBTable()->create();
     \thebuggenie\core\entities\NotificationSetting::getB2DBTable()->create();
     $transaction = \b2db\Core::startTransaction();
     // Upgrade user passwords
     switch ($request['upgrade_passwords']) {
         case 'manual':
             $password = $request['manual_password'];
             foreach (\thebuggenie\core\entities\tables\Users::getTable()->selectAll() as $user) {
                 $user->setPassword($password);
                 $user->save();
             }
             break;
         case 'auto':
             $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email';
             foreach (\thebuggenie\core\entities\tables\Users::getTable()->selectAll() as $user) {
                 if ($field == 'username' && trim($user->getUsername())) {
                     $user->setPassword(trim($user->getUsername()));
                     $user->save();
                 } elseif ($field == 'email' && trim($user->getEmail())) {
                     $user->setPassword(trim($user->getEmail()));
                     $user->save();
                 }
             }
             break;
     }
     $adminuser = \thebuggenie\core\entities\User::getB2DBTable()->selectById(1);
     $adminuser->setPassword($request['admin_password']);
     $adminuser->save();
     // Add new settings
     framework\Settings::saveSetting(framework\Settings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1);
     foreach ($request->getParameter('status') as $scope_id => $status_id) {
         $scope = \thebuggenie\core\entities\tables\Scopes::getTable()->selectById((int) $scope_id);
         if ($scope instanceof \thebuggenie\core\entities\Scope) {
             $epic = new \thebuggenie\core\entities\Issuetype();
             $epic->setName('Epic');
             $epic->setIcon('epic');
             $epic->setDescription('Issue type suited for entering epics');
             $epic->setScope($scope_id);
             $epic->save();
             framework\Settings::saveSetting('issuetype_epic', $epic->getID(), 'core', $scope_id);
             foreach (\thebuggenie\core\entities\tables\Workflows::getTable()->getAll((int) $scope_id) as $workflow) {
                 $transition = new \thebuggenie\core\entities\WorkflowTransition();
                 $steps = $workflow->getSteps();
                 $step = array_shift($steps);
                 $step->setLinkedStatusID((int) $status_id);
                 $step->save();
                 $transition->setOutgoingStep($step);
                 $transition->setName('Issue created');
                 $transition->setWorkflow($workflow);
                 $transition->setScope($scope);
                 $transition->setDescription('This is the initial transition for issues using this workflow');
                 $transition->save();
                 $workflow->setInitialTransition($transition);
                 $workflow->save();
             }
             \thebuggenie\core\entities\ActivityType::loadFixtures($scope);
         }
     }
     $transaction->commitAndEnd();
     framework\Context::finishUpgrading();
     foreach (framework\Context::getModules() as $module) {
         $module->upgrade();
     }
     $this->upgrade_complete = true;
 }
Ejemplo n.º 21
0
                    ?>
TBG.Main.Helpers.Backdrop.show('<?php 
                    echo make_url('get_partial_for_backdrop', array('key' => 'permissions', 'permission_key' => $permission_key, 'mode' => $mode, 'target_id' => $current_target_id, 'target_module' => $module, 'access_level' => $access_level));
                    ?>
');" style="float: right;"><?php 
                    echo image_tag('cfg_icon_permissions.png');
                    ?>
</a>
                    <?php 
                }
                ?>
                <?php 
            } elseif (isset($user_id) && $user_id) {
                ?>
                    <?php 
                $user = \thebuggenie\core\entities\User::getB2DBTable()->selectById($user_id);
                ?>
                    <div style="float: right;"><?php 
                include_component('configuration/permissionsinfoitem', array('key' => $permission_key, 'target_id' => $current_target_id, 'type' => 'user', 'mode' => $mode, 'item_id' => $user->getID(), 'item_name' => urlencode($user->getName()), 'module' => $module, 'access_level' => $access_level));
                ?>
</div>
                <?php 
            } elseif (isset($team_id) && $team_id) {
                ?>
                    <?php 
                $team = \thebuggenie\core\entities\Team::getB2DBTable()->selectById($team_id);
                ?>
                    <div style="float: right;"><?php 
                include_component('configuration/permissionsinfoitem', array('key' => $permission_key, 'target_id' => $current_target_id, 'type' => 'team', 'mode' => $mode, 'item_id' => $team->getID(), 'item_name' => urlencode($team->getName()), 'module' => $module, 'access_level' => $access_level));
                ?>
</div>