Example #1
0
 public function markNotificationsRead($type, $id)
 {
     if ($type == 'issue') {
         tables\Notifications::getTable()->markUserNotificationsReadByTypesAndId(array(Notification::TYPE_ISSUE_CREATED, Notification::TYPE_ISSUE_UPDATED), $id, $this->getID());
         $comment_ids = tables\Comments::getTable()->getCommentIDs($id, Comment::TYPE_ISSUE);
         if (count($comment_ids)) {
             tables\Notifications::getTable()->markUserNotificationsReadByTypesAndId(array(Notification::TYPE_ISSUE_COMMENTED, Notification::TYPE_COMMENT_MENTIONED), $comment_ids, $this->getID());
         }
     }
     if ($type == 'article') {
         tables\Notifications::getTable()->markUserNotificationsReadByTypesAndId(array(Notification::TYPE_ARTICLE_UPDATED), $id, $this->getID());
         $comment_ids = tables\Comments::getTable()->getCommentIDs($id, Comment::TYPE_ARTICLE);
         if (count($comment_ids)) {
             tables\Notifications::getTable()->markUserNotificationsReadByTypesAndId(array(Notification::TYPE_ARTICLE_COMMENTED, Notification::TYPE_COMMENT_MENTIONED), $comment_ids, $this->getID());
         }
     }
     $this->_notifications = null;
     $this->_unread_notifications_count = null;
     $this->_read_notifications_count = null;
 }
Example #2
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;
 }
Example #3
0
 /**
  * Returns the object which the notification is for
  *
  * @return \thebuggenie\core\entities\common\IdentifiableScoped
  */
 public function getTarget()
 {
     if ($this->_target === null) {
         if ($this->_module_name == 'core') {
             switch ($this->_notification_type) {
                 case self::TYPE_ARTICLE_COMMENTED:
                 case self::TYPE_ISSUE_COMMENTED:
                 case self::TYPE_COMMENT_MENTIONED:
                     $this->_target = tables\Comments::getTable()->selectById((int) $this->_target_id);
                     break;
                 case self::TYPE_ISSUE_UPDATED:
                 case self::TYPE_ISSUE_CREATED:
                 case self::TYPE_ISSUE_MENTIONED:
                     $this->_target = \thebuggenie\core\entities\Issue::getB2DBTable()->selectById((int) $this->_target_id);
                     break;
                 case self::TYPE_ARTICLE_CREATED:
                 case self::TYPE_ARTICLE_UPDATED:
                 case self::TYPE_ARTICLE_MENTIONED:
                     $this->_target = Articles::getTable()->selectById((int) $this->_target_id);
                     break;
             }
         } else {
             $event = new \thebuggenie\core\framework\Event('core', 'thebuggenie\\core\\entities\\Notification::getTarget', $this);
             $event->triggerUntilProcessed();
             $this->_target = $event->getReturnValue();
         }
     }
     return $this->_target;
 }
Example #4
0
 public function markNotificationsRead($type, $id)
 {
     $grouped_notifications_minutes = $this->getNotificationSetting(framework\Settings::SETTINGS_USER_NOTIFY_GROUPED_NOTIFICATIONS, false, 'core')->getValue();
     if ($type == 'issue') {
         tables\Notifications::getTable()->markUserNotificationsReadByTypesAndIdAndGroupableMinutes(array(Notification::TYPE_ISSUE_CREATED, Notification::TYPE_ISSUE_UPDATED), $id, $this->getID(), $grouped_notifications_minutes);
         $comment_ids = tables\Comments::getTable()->getCommentIDs($id, Comment::TYPE_ISSUE);
         if (count($comment_ids)) {
             tables\Notifications::getTable()->markUserNotificationsReadByTypesAndIdAndGroupableMinutes(array(Notification::TYPE_ISSUE_COMMENTED, Notification::TYPE_COMMENT_MENTIONED), $comment_ids, $this->getID(), $grouped_notifications_minutes);
         }
     }
     if ($type == 'article') {
         tables\Notifications::getTable()->markUserNotificationsReadByTypesAndIdAndGroupableMinutes(array(Notification::TYPE_ARTICLE_CREATED, Notification::TYPE_ARTICLE_UPDATED), $id, $this->getID(), $grouped_notifications_minutes);
         $comment_ids = tables\Comments::getTable()->getCommentIDs($id, Comment::TYPE_ARTICLE);
         if (count($comment_ids)) {
             tables\Notifications::getTable()->markUserNotificationsReadByTypesAndIdAndGroupableMinutes(array(Notification::TYPE_ARTICLE_COMMENTED, Notification::TYPE_COMMENT_MENTIONED), $comment_ids, $this->getID(), $grouped_notifications_minutes);
         }
     }
     $this->_notifications = null;
     $this->_unread_notifications_count = null;
     $this->_read_notifications_count = null;
 }
Example #5
0
 /**
  * Class constructor
  *
  * @param \b2db\Row $row
  */
 public function _construct(\b2db\Row $row, $foreign_key = null)
 {
     $this->_initializeCustomfields();
     $this->_mergeChangedProperties();
     $this->_num_user_comments = tables\Comments::getTable()->getPreloadedIssueCommentCount($this->_id);
     $this->_num_files = tables\IssueFiles::getTable()->getPreloadedIssueFileCount($this->_id);
     //            if ($this->isDeleted())
     //            {
     //                throw new \Exception(framework\Context::geti18n()->__('This issue has been deleted'));
     //            }
 }
Example #6
0
 protected function _preSave($is_new)
 {
     parent::_preSave($is_new);
     if ($is_new) {
         if (!$this->_posted) {
             $this->_posted = NOW;
         }
         if (!$this->_comment_number) {
             $this->_comment_number = tables\Comments::getTable()->getNextCommentNumber($this->_target_id, $this->_target_type);
         }
     }
 }
Example #7
0
 protected function moveIssues($project_id, $to_scope_id)
 {
     $crit = Issues::getTable()->getCriteria();
     $crit->addWhere('issues.project_id', $project_id);
     $crit->addSelectionColumn('issues.id', 'id');
     $issue_ids = [];
     if ($res = Issues::getTable()->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $issue_ids[] = $row['id'];
         }
     }
     $this->cliEcho("------------------\n");
     $this->cliEcho('Moving ');
     $this->cliEcho(count($issue_ids), 'white', 'bold');
     $this->cliEcho(" issues\n");
     $this->cliEcho("------------------\n");
     if (!$issue_ids) {
         return;
     }
     $this->cliEcho("Moving comments... ");
     $comments_crit = Comments::getTable()->getCriteria();
     $comments_crit->addUpdate('comments.scope', $to_scope_id);
     $comments_crit->addWhere('comments.target_id', $issue_ids, Criteria::DB_IN);
     $comments_crit->addWhere('comments.target_type', Comment::TYPE_ISSUE);
     Comments::getTable()->doUpdate($comments_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving log items... ");
     $logs_crit = Log::getTable()->getCriteria();
     $logs_crit->addUpdate('log.scope', $to_scope_id);
     $logs_crit->addWhere('log.target', $issue_ids, Criteria::DB_IN);
     $logs_crit->addWhere('log.target_type', Log::TYPE_ISSUE);
     Log::getTable()->doUpdate($logs_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving attachments... ");
     $file_ids_crit = IssueFiles::getTable()->getCriteria();
     $file_ids_crit->addWhere('issuefiles.issue_id', $issue_ids, Criteria::DB_IN);
     $file_ids_crit->addSelectionColumn('issuefiles.file_id', 'file_id');
     $file_ids_crit->addSelectionColumn('issuefiles.id', 'id');
     $file_ids = [];
     $issue_file_ids = [];
     if ($res = IssueFiles::getTable()->doSelect($file_ids_crit)) {
         while ($row = $res->getNextRow()) {
             $file_ids[] = $row['file_id'];
             $issue_file_ids[] = $row['id'];
         }
     }
     if (count($file_ids)) {
         $file_crit = Files::getTable()->getCriteria();
         $file_crit->addUpdate('files.scope', $to_scope_id);
         $file_crit->addWhere('files.id', $file_ids, Criteria::DB_IN);
         Files::getTable()->doUpdate($file_crit);
         $issue_file_crit = IssueFiles::getTable()->getCriteria();
         $issue_file_crit->addUpdate('issuefiles.scope', $to_scope_id);
         $issue_file_crit->addWhere('issuefiles.id', $issue_file_ids, Criteria::DB_IN);
         IssueFiles::getTable()->doUpdate($issue_file_crit);
     }
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving calculations and estimations... ");
     $estimates_crit = IssueEstimates::getTable()->getCriteria();
     $estimates_crit->addUpdate('issue_estimates.scope', $to_scope_id);
     $estimates_crit->addWhere('issue_estimates.issue_id', $issue_ids, Criteria::DB_IN);
     IssueEstimates::getTable()->doUpdate($estimates_crit);
     $spent_crit = IssueSpentTimes::getTable()->getCriteria();
     $spent_crit->addUpdate('issue_spenttimes.scope', $to_scope_id);
     $spent_crit->addWhere('issue_spenttimes.issue_id', $issue_ids, Criteria::DB_IN);
     IssueSpentTimes::getTable()->doUpdate($spent_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving links, related and affected items");
     $tables = ['\\thebuggenie\\core\\entities\\tables\\IssueAffectsBuild' => 'issueaffectsbuild', '\\thebuggenie\\core\\entities\\tables\\IssueAffectsComponent' => 'issueaffectscomponent', '\\thebuggenie\\core\\entities\\tables\\IssueAffectsEdition' => 'issueaffectsedition'];
     foreach ($tables as $class_name => $table_name) {
         $crit = $class_name::getTable()->getCriteria();
         $crit->addUpdate($table_name . '.scope', $to_scope_id);
         $crit->addWhere($table_name . '.issue', $issue_ids, Criteria::DB_IN);
         $class_name::getTable()->doUpdate($crit);
     }
     $links_crit = Links::getTable()->getCriteria();
     $links_crit->addUpdate('links.scope', $to_scope_id);
     $links_crit->addWhere('links.target_id', $issue_ids, Criteria::DB_IN);
     $links_crit->addWhere('links.target_type', 'issue');
     Links::getTable()->doUpdate($links_crit);
     $related_crit = IssueRelations::getTable()->getCriteria();
     $related_crit->addUpdate('issuerelations.scope', $to_scope_id);
     $ctn = $related_crit->returnCriterion('issuerelations.child_id', $issue_ids, Criteria::DB_IN);
     $ctn->addOr('issuerelations.parent_id', $issue_ids, Criteria::DB_IN);
     $related_crit->addWhere($ctn);
     $votes_crit = Votes::getTable()->getCriteria();
     $votes_crit->addUpdate('votes.scope', $to_scope_id);
     $votes_crit->addWhere('votes.target', $issue_ids, Criteria::DB_IN);
     Votes::getTable()->doUpdate($votes_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Updating user issue bookmarks");
     $user_issues_crit = UserIssues::getTable()->getCriteria();
     $user_issues_crit->addUpdate('userissues.scope', $to_scope_id);
     $user_issues_crit->addWhere('userissues.issue', $issue_ids, Criteria::DB_IN);
     UserIssues::getTable()->doUpdate($user_issues_crit);
     $this->cliEcho(" done\n");
     $this->updateCustomFields($issue_ids, $to_scope_id);
     $crit = Issues::getTable()->getCriteria();
     $crit->addUpdate('issues.scope', $to_scope_id);
     $crit->addWhere('issues.id', $issue_ids, Criteria::DB_IN);
     Issues::getTable()->doUpdate($crit);
     $this->cliEcho("------------------\n");
     $this->cliEcho("Done moving issues\n");
     $this->cliEcho("------------------\n");
 }