Ejemplo n.º 1
0
 public function runUserdata(TBGRequest $request)
 {
     if ($this->getUser()->isGuest()) {
         return $this->renderJSON(array());
     } else {
         $data = array();
         if ($request->isPost()) {
             switch ($request['say']) {
                 case 'notificationstatus':
                     $notification = TBGNotificationsTable::getTable()->selectById($request['notification_id']);
                     if ($notification instanceof TBGNotification) {
                         $notification->setIsRead(!$notification->isRead());
                         $notification->save();
                         $data['notification_id'] = $notification->getID();
                         $data['is_read'] = (int) $notification->isRead();
                     }
                     break;
                 case 'notificationsread':
                     $this->getUser()->markAllNotificationsRead();
                     $data['all'] = 'read';
                     break;
             }
         } else {
             switch ($request['say']) {
                 case 'get_mentionables':
                     switch ($request['target_type']) {
                         case 'issue':
                             $target = TBGIssuesTable::getTable()->selectById($request['target_id']);
                             break;
                         case 'article':
                             $target = TBGArticlesTable::getTable()->selectById($request['target_id']);
                             break;
                         case 'project':
                             $target = TBGProjectsTable::getTable()->selectById($request['target_id']);
                             break;
                     }
                     $mentionables = array();
                     if (isset($target) && $target instanceof TBGMentionableProvider) {
                         foreach ($target->getMentionableUsers() as $user) {
                             if ($user->isOpenIdLocked()) {
                                 continue;
                             }
                             $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL());
                         }
                     }
                     foreach ($this->getUser()->getFriends() as $user) {
                         if ($user->isOpenIdLocked()) {
                             continue;
                         }
                         $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL());
                     }
                     foreach ($this->getUser()->getTeams() as $team) {
                         foreach ($team->getMembers() as $user) {
                             if ($user->isOpenIdLocked()) {
                                 continue;
                             }
                             $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL());
                         }
                     }
                     foreach ($this->getUser()->getClients() as $client) {
                         foreach ($client->getMembers() as $user) {
                             if ($user->isOpenIdLocked()) {
                                 continue;
                             }
                             $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL());
                         }
                     }
                     $data['mentionables'] = array_values($mentionables);
                     break;
                 default:
                     $data['unread_notifications'] = $this->getUser()->getNumberOfUnreadNotifications();
             }
         }
         return $this->renderJSON($data);
     }
 }
Ejemplo n.º 2
0
 public function markNotificationsRead($type, $id)
 {
     if ($type == 'issue') {
         TBGNotificationsTable::getTable()->markUserNotificationsReadByTypesAndId(array(TBGNotification::TYPE_ISSUE_CREATED, TBGNotification::TYPE_ISSUE_UPDATED), $id, $this->getID());
         $comment_ids = TBGCommentsTable::getTable()->getCommentIDs($id, TBGComment::TYPE_ISSUE);
         if (count($comment_ids)) {
             TBGNotificationsTable::getTable()->markUserNotificationsReadByTypesAndId(array(TBGNotification::TYPE_ISSUE_COMMENTED, TBGNotification::TYPE_COMMENT_MENTIONED), $comment_ids, $this->getID());
         }
     }
     if ($type == 'article') {
         TBGNotificationsTable::getTable()->markUserNotificationsReadByTypesAndId(array(TBGNotification::TYPE_ARTICLE_UPDATED), $id, $this->getID());
         $comment_ids = TBGCommentsTable::getTable()->getCommentIDs($id, TBGComment::TYPE_ARTICLE);
         if (count($comment_ids)) {
             TBGNotificationsTable::getTable()->markUserNotificationsReadByTypesAndId(array(TBGNotification::TYPE_ARTICLE_COMMENTED, TBGNotification::TYPE_COMMENT_MENTIONED), $comment_ids, $this->getID());
         }
     }
     $this->_notifications = null;
     $this->_unread_notifications_count = null;
     $this->_read_notifications_count = null;
 }
Ejemplo n.º 3
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;
 }