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; }
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; }
protected function _upgradeFrom4dot1dot7(framework\Request $request) { set_time_limit(0); \thebuggenie\core\entities\tables\Notifications::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_417\Notification::getB2DBTable()); $this->upgrade_complete = true; $this->current_version = '4.1.8'; }
/** * @param Notification $notification */ public function markNotificationGroupedNotificationsRead(\thebuggenie\core\entities\Notification $notification) { if ($notification->getNotificationType() != \thebuggenie\core\entities\Notification::TYPE_ISSUE_UPDATED) { return; } tables\Notifications::getTable()->markUserNotificationsReadByTypesAndIdAndGroupableMinutes(array(\thebuggenie\core\entities\Notification::TYPE_ISSUE_UPDATED), $notification->getTargetID(), $this->getID(), $this->getNotificationSetting(framework\Settings::SETTINGS_USER_NOTIFY_GROUPED_NOTIFICATIONS, false, 'core')->getValue(), (int) $notification->isRead(), false); }
protected function _populateNotifications($first_notification_id = null, $last_notification_id = null) { $filter_first_notification = !is_null($first_notification_id) && is_numeric($first_notification_id); if ($filter_first_notification) { $this->_notifications = null; $this->_filter_first_notification = true; } else { if (!$filter_first_notification && $this->_filter_first_notification) { $this->_notifications = null; $this->_filter_first_notification = false; } } if (!is_array($this->_notifications)) { $this->_notifications = Notifications::getTable()->getByUserIDAndGroupableMinutes($this->getID(), $this->getNotificationSetting(framework\Settings::SETTINGS_USER_NOTIFY_GROUPED_NOTIFICATIONS, false, 'core')->getValue()); $notifications = array('unread' => array(), 'read' => array(), 'all' => array()); $db_notifcations = $this->_notifications; foreach ($db_notifcations as $notification) { if ($filter_first_notification && $notification->getID() <= $first_notification_id) { break; } if (!$filter_first_notification && !is_null($last_notification_id) && $notification->getID() >= $last_notification_id) { continue; } if ($notification->getTriggeredByUser()->getID() == $this->getID()) { continue; } array_push($notifications['all'], $notification); if ($notification->isRead()) { array_push($notifications['read'], $notification); } else { array_push($notifications['unread'], $notification); } } $notifications = array_reverse($notifications); $this->_notifications = $notifications; $this->_unread_notifications_count = count($notifications['unread']); $this->_read_notifications_count = count($notifications['read']); } }
public function runUserdata(framework\Request $request) { if ($this->getUser()->isGuest()) { return $this->renderJSON(array()); } else { $data = array(); if ($request->isPost()) { switch ($request['say']) { case 'install-module': try { entities\Module::downloadModule($request['module_key']); $module = entities\Module::installModule($request['module_key']); $data['installed'] = true; $data['module_key'] = $request['module_key']; $data['module'] = $this->getComponentHTML('configuration/modulebox', array('module' => $module)); } catch (framework\exceptions\ModuleDownloadException $e) { $this->getResponse()->setHttpStatus(400); switch ($e->getCode()) { case framework\exceptions\ModuleDownloadException::JSON_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to retrieve the module data'))); break; case framework\exceptions\ModuleDownloadException::FILE_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('The module could not be downloaded'))); break; } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to install the module'))); } break; case 'install-theme': try { entities\Module::downloadTheme($request['theme_key']); $data['installed'] = true; $data['theme_key'] = $request['theme_key']; $themes = framework\Context::getThemes(); $data['theme'] = $this->getComponentHTML('configuration/theme', array('theme' => $themes[$request['theme_key']])); } catch (framework\exceptions\ModuleDownloadException $e) { $this->getResponse()->setHttpStatus(400); switch ($e->getCode()) { case framework\exceptions\ModuleDownloadException::JSON_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to retrieve the module data'))); break; case framework\exceptions\ModuleDownloadException::FILE_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('The module could not be downloaded'))); break; } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to install the module'))); } break; case 'notificationstatus': $notification = tables\Notifications::getTable()->selectById($request['notification_id']); $data['notification_id'] = $request['notification_id']; $data['is_read'] = 1; if ($notification instanceof entities\Notification) { $notification->setIsRead(!$notification->isRead()); $notification->save(); $data['is_read'] = (int) $notification->isRead(); $this->getUser()->markNotificationGroupedNotificationsRead($notification); } break; case 'notificationsread': $this->getUser()->markAllNotificationsRead(); $data['all'] = 'read'; break; } } else { switch ($request['say']) { case 'get_module_updates': $addons_param = array(); foreach ($request['addons'] as $addon) { $addons_param[] = 'addons[]=' . $addon; } try { $client = new \Net_Http_Client(); $client->get('http://www.thebuggenie.com/addons.json?' . join('&', $addons_param)); $addons_json = json_decode($client->getBody(), true); } catch (\Exception $e) { } return $this->renderJSON($addons_json); break; case 'getsearchcounts': $counts_json = array(); foreach ($request['search_ids'] as $search_id) { if (is_numeric($search_id)) { $search = tables\SavedSearches::getTable()->selectById($search_id); } else { $predefined_id = str_replace('predefined_', '', $search_id); $search = \thebuggenie\core\entities\SavedSearch::getPredefinedSearchObject($predefined_id); } if ($search instanceof entities\SavedSearch) { $counts_json[$search_id] = $search->getTotalNumberOfIssues(); } } return $this->renderJSON($counts_json); break; case 'get_theme_updates': $addons_param = array(); foreach ($request['addons'] as $addon) { $addons_param[] = 'themes[]=' . $addon; } try { $client = new \Net_Http_Client(); $client->get('http://www.thebuggenie.com/themes.json?' . join('&', $addons_param)); $addons_json = json_decode($client->getBody(), true); } catch (\Exception $e) { } return $this->renderJSON($addons_json); break; case 'verify_module_update_file': $filename = THEBUGGENIE_CACHE_PATH . $request['module_key'] . '.zip'; $exists = file_exists($filename) && dirname($filename) . DS == THEBUGGENIE_CACHE_PATH; return $this->renderJSON(array('verified' => (int) $exists)); break; case 'get_modules': return $this->renderComponent('configuration/onlinemodules'); break; case 'get_themes': return $this->renderComponent('configuration/onlinethemes'); break; case 'get_mentionables': switch ($request['target_type']) { case 'issue': $target = entities\Issue::getB2DBTable()->selectById($request['target_id']); break; case 'article': $target = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->selectById($request['target_id']); break; case 'project': $target = tables\Projects::getTable()->selectById($request['target_id']); break; } $mentionables = array(); if (isset($target) && $target instanceof \thebuggenie\core\helpers\MentionableProvider) { 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_count'] = $this->getUser()->getNumberOfUnreadNotifications(); $data['unread_notifications'] = array(); foreach ($this->getUser()->getUnreadNotifications() as $unread_notification) { $data['unread_notifications'][] = $unread_notification->getID(); } $data['poll_interval'] = framework\Settings::getNotificationPollInterval(); } } return $this->renderJSON($data); } }
protected function _populateNotifications($first_notification_id = null, $last_notification_id = null) { $filter_first_notification = !is_null($first_notification_id) && is_numeric($first_notification_id); if ($filter_first_notification) { $this->_notifications = null; $this->_filter_first_notification = true; } else { if (!$filter_first_notification && $this->_filter_first_notification) { $this->_notifications = null; $this->_filter_first_notification = false; } } if (!is_array($this->_notifications)) { $this->_notifications = Notifications::getTable()->getByUserID($this->getID()); $notifications = array('unread' => array(), 'read' => array(), 'all' => array()); $db_notifcations = array_reverse($this->_notifications); foreach ($db_notifcations as $notification) { if ($filter_first_notification && $notification->getID() <= $first_notification_id) { break; } if (!$filter_first_notification && !is_null($last_notification_id) && $notification->getID() >= $last_notification_id) { continue; } if ($notification->getTriggeredByUser()->getID() == $this->getID()) { continue; } array_push($notifications['all'], $notification); if ($notification->isRead()) { array_push($notifications['read'], $notification); } else { array_push($notifications['unread'], $notification); } } $notifications = array_reverse($notifications); $this->_notifications = $notifications; $this->_unread_notifications_count = count($notifications['unread']); $this->_read_notifications_count = count($notifications['read']); } }