public function do_execute()
 {
     if (TBGContext::isInstallmode()) {
         $this->cliEcho("The Bug Genie is not installed\n", 'red');
     } else {
         $this->cliEcho("Finding times to fix\n", 'white', 'bold');
         $issuetimes = TBGIssueSpentTimesTable::getTable()->getAllSpentTimesForFixing();
         $error_issues = array();
         foreach ($issuetimes as $issue_id => $times) {
             if (count($times) > 1) {
                 $this->cliEcho("Fixing times spent for issue ID {$issue_id}, " . count($times) . " entries\n");
                 $prev_times = array('hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0, 'points' => 0);
                 foreach ($times as $k => $row) {
                     if ($row[TBGIssueSpentTimesTable::SPENT_DAYS] < $prev_times['days'] || $row[TBGIssueSpentTimesTable::SPENT_HOURS] < $prev_times['hours'] || $row[TBGIssueSpentTimesTable::SPENT_WEEKS] < $prev_times['weeks'] || $row[TBGIssueSpentTimesTable::SPENT_MONTHS] < $prev_times['months'] || $row[TBGIssueSpentTimesTable::SPENT_POINTS] < $prev_times['points']) {
                         $error_issues[] = $issue_id;
                     } else {
                         TBGIssueSpentTimesTable::getTable()->fixRow($row, $prev_times);
                         $prev_times['points'] += $row[TBGIssueSpentTimesTable::SPENT_POINTS];
                         $prev_times['hours'] += $row[TBGIssueSpentTimesTable::SPENT_HOURS];
                         $prev_times['days'] += $row[TBGIssueSpentTimesTable::SPENT_DAYS];
                         $prev_times['weeks'] += $row[TBGIssueSpentTimesTable::SPENT_WEEKS];
                         $prev_times['months'] += $row[TBGIssueSpentTimesTable::SPENT_MONTHS];
                     }
                 }
             }
         }
         foreach (TBGIssueSpentTimesTable::getTable()->getAllSpentTimesForFixing() as $issue_id => $times) {
             foreach ($times as $row) {
                 TBGIssueSpentTimesTable::getTable()->fixHours($row);
             }
             TBGIssuesTable::getTable()->fixHours($issue_id);
         }
         if (count($error_issues) > 0) {
             $this->cliEcho("\n");
             $this->cliEcho("All spent times have been attempted fixed, but there were some issues that could not be fixed automatically!\n");
             $this->cliEcho("This happens if there has been adjustments in time spent, lowering the value for spent points, hours, days, weeks or months.\n\n");
             $this->cliEcho("You should fix the issues manually (issue ids corresponding to issue_ids in the timesspent table): ");
             $this->cliEcho(join(', ', $error_issues) . "\n\n");
             $this->cliEcho("Spent times fixed!\n\n", 'green');
         } else {
             $this->cliEcho("All spent times fixed successfully!\n\n", 'green');
         }
         $this->cliEcho("IMPORTANT: Don't run this task again!\n", 'white', 'bold');
     }
 }
 public function fixHours($issue_id)
 {
     $times = TBGIssueSpentTimesTable::getTable()->getSpentTimeSumsByIssueId($issue_id);
     $crit = $this->getCriteria();
     $crit->addUpdate(self::SPENT_HOURS, $times['hours']);
     $this->doUpdate($crit);
 }
 protected function _populateBurndownData()
 {
     if ($this->_burndowndata === null) {
         $this->_burndowndata = array();
         $issues = array();
         foreach ($this->getIssues() as $issue) {
             $issues[] = (int) $issue->getID();
             foreach ($issue->getChildIssues() as $child_issue) {
                 $issues[] = (int) $child_issue->getID();
             }
         }
         $estimations = TBGIssueEstimates::getTable()->getEstimatesByDateAndIssueIDs($this->getStartingDate(), $this->getScheduledDate(), $issues);
         $spent_times = TBGIssueSpentTimesTable::getTable()->getSpentTimesByDateAndIssueIDs($this->getStartingDate(), $this->getScheduledDate(), $issues);
         $burndown = array();
         foreach ($estimations['hours'] as $key => $val) {
             $burndown['hours'][$key] = array_key_exists($key, $spent_times['hours']) ? $val - $spent_times['hours'][$key] : $val;
         }
         foreach ($estimations['points'] as $key => $val) {
             $burndown['points'][$key] = array_key_exists($key, $spent_times['points']) ? $val - $spent_times['points'][$key] : $val;
         }
         foreach ($spent_times['hours'] as $key => $val) {
             $spent_times['hours'][$key] = round($spent_times['hours'][$key] / 100, 2);
         }
         $this->_burndowndata = array('estimations' => $estimations, 'spent_times' => $spent_times, 'burndown' => $burndown);
     }
 }
Exemple #4
0
 public function runIssueEditTimeSpent(TBGRequest $request)
 {
     $entry_id = $request['entry_id'];
     $spenttime = $entry_id ? TBGIssueSpentTimesTable::getTable()->selectById($entry_id) : new TBGIssueSpentTime();
     if ($issue_id = $request['issue_id']) {
         try {
             $issue = TBGContext::factory()->TBGIssue($issue_id);
         } catch (Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderText('fail');
         }
     } else {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderText('no issue');
     }
     if (!$spenttime->getID()) {
         if ($request['timespent_manual']) {
             $times = TBGIssue::convertFancyStringToTime($request['timespent_manual']);
         } else {
             $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0);
             $times[$request['timespent_specified_type']] = $request['timespent_specified_value'];
         }
         $spenttime->setIssue($issue);
         $spenttime->setUser($this->getUser());
     } else {
         $times = array('points' => $request['points'], 'hours' => $request['hours'], 'days' => $request['days'], 'weeks' => $request['weeks'], 'months' => $request['months']);
         $edited_at = $request['edited_at'];
         $spenttime->setEditedAt(mktime(0, 0, 1, $edited_at['month'], $edited_at['day'], $edited_at['year']));
     }
     $times['hours'] *= 100;
     $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();
     $spenttime->getIssue()->save();
     $timesum = array_sum($spenttime->getIssue()->getSpentTime());
     return $this->renderJSON(array('edited' => 'ok', 'issue_id' => $issue_id, 'timesum' => $timesum, 'spenttime' => TBGIssue::getFormattedTime($spenttime->getIssue()->getSpentTime()), 'timeentries' => $this->getComponentHTML('main/issuespenttimes', array('issue' => $spenttime->getIssue()))));
 }
 public function componentIssueSpenttime()
 {
     $this->entry = TBGIssueSpentTimesTable::getTable()->selectById($this->entry_id);
 }
Exemple #6
0
 protected function _upgradeFrom3dot2(TBGRequest $request)
 {
     set_time_limit(0);
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.2');
     foreach (array('publish', 'mailing') as $module) {
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes');
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes' . DS . 'B2DB');
     }
     TBGMilestonesTable::getTable()->upgrade(TBGMilestonesTable3dot2::getTable());
     TBGArticlesTable::getTable()->upgrade(TBGArticlesTable3dot2::getTable());
     TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot2::getTable());
     TBGLogTable::getTable()->upgrade(TBGLogTable3dot2::getTable());
     TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot2::getTable());
     TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot2::getTable());
     TBGWorkflowsTable::getTable()->upgrade(TBGWorkflowsTable3dot2::getTable());
     TBGIncomingEmailAccountTable::getTable()->upgrade(TBGIncomingEmailAccountTable3dot2::getTable());
     TBGIssueSpentTimesTable::getTable()->upgrade(TBGIssueSpentTimesTable3dot2::getTable());
     TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot2::getTable());
     TBGSavedSearchesTable::getTable()->upgrade(TBGSavedSearchesTable3dot2::getTable());
     TBGSettingsTable::getTable()->upgrade(TBGSettingsTable3dot2::getTable());
     TBGNotificationsTable::getTable()->upgrade(TBGNotificationsTable3dot2::getTable());
     TBGPermissionsTable::getTable()->upgrade(TBGPermissionsTable3dot2::getTable());
     TBGUserArticlesTable::getTable()->create();
     TBGApplicationPasswordsTable::getTable()->create();
     TBGUserNotificationSettingsTable::getTable()->create();
     $transaction = \b2db\Core::startTransaction();
     // Upgrade user passwords
     switch ($request['upgrade_passwords']) {
         case 'manual':
             $password = $request['manul_password'];
             foreach (TBGUsersTable::getTable()->selectAll() as $user) {
                 $user->setPassword($password);
                 $user->save();
             }
             break;
         case 'auto':
             $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email';
             foreach (TBGUsersTable::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 = TBGUsersTable::getTable()->selectById(1);
     $adminuser->setPassword($request['admin_password']);
     $adminuser->save();
     // Add new settings
     TBGSettings::saveSetting(TBGSettings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1);
     foreach ($request->getParameter('status') as $scope_id => $status_id) {
         $scope = TBGScopesTable::getTable()->selectById((int) $scope_id);
         if ($scope instanceof TBGScope) {
             foreach (TBGWorkflowsTable::getTable()->getAll((int) $scope_id) as $workflow) {
                 $transition = new TBGWorkflowTransition();
                 $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();
             }
             TBGActivityType::loadFixtures($scope);
         }
     }
     $transaction->commitAndEnd();
     TBGContext::finishUpgrading();
     TBGContext::getModule('mailing')->upgradeFrom3dot2();
     $this->upgrade_complete = true;
 }
 protected function _recalculateIssueTimes()
 {
     $times = TBGIssueSpentTimesTable::getTable()->getSpentTimeSumsByIssueId($this->getIssueID());
     $this->getIssue()->setSpentPoints($times['points']);
     $this->getIssue()->setSpentHours($times['hours']);
     $this->getIssue()->setSpentDays($times['days']);
     $this->getIssue()->setSpentWeeks($times['weeks']);
     $this->getIssue()->setSpentMonths($times['months']);
 }