public static function removeModule($module_id)
 {
     TBGModulesTable::getTable()->removeModuleByID($module_id);
 }
 public function runScope(TBGRequest $request)
 {
     $this->scope = new TBGScope($request->getParameter('id'));
     $modules = TBGModulesTable::getTable()->getModulesForScope($this->scope->getID());
     $this->modules = $modules;
     $this->scope_save_error = TBGContext::getMessageAndClear('scope_save_error');
     $this->scope_saved = TBGContext::getMessageAndClear('scope_saved');
     if ($request->isMethod(TBGRequest::POST)) {
         try {
             if ($request->getParameter('scope_action') == 'delete') {
                 if (!$this->scope->isDefault()) {
                     $this->scope->delete();
                     TBGContext::setMessage('scope_deleted', true);
                     $this->forward(make_url('configure_scopes'));
                 } else {
                     $this->scope_save_error = TBGContext::getI18n()->__('You cannot delete the default scope');
                 }
             } else {
                 if (!$request->getParameter('name')) {
                     throw new Exception(TBGContext::getI18n()->__('Please specify a scope name'));
                 }
                 $this->scope->setName($request->getParameter('name'));
                 $this->scope->setDescription($request->getParameter('description'));
                 $this->scope->setCustomWorkflowsEnabled((bool) $request->getParameter('custom_workflows_enabled'));
                 $this->scope->setMaxWorkflowsLimit((int) $request->getParameter('workflow_limit'));
                 $this->scope->setUploadsEnabled((bool) $request->getParameter('file_uploads_enabled'));
                 $this->scope->setMaxUploadLimit((int) $request->getParameter('upload_limit'));
                 $this->scope->setMaxProjects((int) $request->getParameter('project_limit'));
                 $this->scope->setMaxUsers((int) $request->getParameter('user_limit'));
                 $this->scope->setMaxTeams((int) $request->getParameter('team_limit'));
                 $this->scope->save();
                 $enabled_modules = $request->getParameter('module_enabled');
                 $prev_scope = TBGContext::getScope();
                 foreach ($enabled_modules as $module => $enabled) {
                     if (!TBGContext::getModule($module)->isCore() && !$enabled && array_key_exists($module, $modules)) {
                         $module = TBGModulesTable::getTable()->getModuleForScope($module, $this->scope->getID());
                         $module->uninstall($this->scope->getID());
                     } elseif (!TBGContext::getModule($module)->isCore() && $enabled && !array_key_exists($module, $modules)) {
                         TBGContext::setScope($this->scope);
                         TBGModule::installModule($module);
                         TBGContext::setScope($prev_scope);
                     }
                 }
                 TBGContext::setMessage('scope_saved', true);
                 $this->forward(make_url('configure_scope', array('id' => $this->scope->getID())));
             }
         } catch (Exception $e) {
             TBGContext::setMessage('scope_save_error', $e->getMessage());
         }
     }
 }
示例#3
0
 private function _fixTimestamps()
 {
     // Unlimited execution time
     set_time_limit(0);
     foreach (TBGScope::getAll() as $scope) {
         TBGContext::setScope($scope);
         // The first job is to work out the offsets that need applying
         $offsets = array('system', 'users');
         $offsets['users'] = array();
         $offsets['system'] = (int) TBGSettings::getGMToffset() * 3600;
         $settingstable = TBGSettingsTable::getTable();
         $crit = $settingstable->getCriteria();
         $crit->addWhere(TBGSettingsTable::NAME, 'timezone');
         $crit->addWhere(TBGSettingsTable::MODULE, 'core');
         $crit->addWhere(TBGSettingsTable::UID, 0, \b2db\Criteria::DB_NOT_EQUALS);
         $crit->addWhere(TBGSettingsTable::VALUE, 0, \b2db\Criteria::DB_NOT_EQUALS);
         $crit->addWhere(TBGSettingsTable::VALUE, 'sys', \b2db\Criteria::DB_NOT_EQUALS);
         $crit->addWhere(TBGSettingsTable::SCOPE, $scope->getID());
         $res = $settingstable->doSelect($crit);
         if ($res instanceof \b2db\Resultset) {
             while ($user = $res->getNextRow()) {
                 $offsets['users']['uid_' . $user->get(TBGSettingsTable::UID)] = (int) $user->get(TBGSettingsTable::VALUE) * 3600;
             }
         }
         // Now go through every thing which requires updating
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes' . DS . 'B2DB');
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes');
         // ARTICLE HISTORY
         $this->_fixUserDependentTimezone($offsets, TBGArticleHistoryTable::getTable(), TBGArticleHistoryTable::AUTHOR, TBGArticleHistoryTable::DATE, $scope);
         // ARTICLES
         $this->_fixUserDependentTimezone($offsets, TBGArticlesTable::getTable(), TBGArticlesTable::AUTHOR, TBGArticlesTable::DATE, $scope);
         // BUILDS
         $this->_fixNonUserDependentTimezone($offsets, TBGBuildsTable::getTable(), TBGBuildsTable::RELEASE_DATE, $scope, TBGBuildsTable::RELEASED);
         // COMMENTS
         $this->_fixUserDependentTimezone($offsets, TBGCommentsTable::getTable(), array('a' => TBGCommentsTable::POSTED_BY, 'b' => TBGCommentsTable::UPDATED_BY), array('a' => TBGCommentsTable::POSTED, 'b' => TBGCommentsTable::UPDATED), $scope);
         // EDITIONS
         $this->_fixNonUserDependentTimezone($offsets, TBGEditionsTable::getTable(), TBGEditionsTable::RELEASE_DATE, $scope, TBGEditionsTable::RELEASED);
         // ISSUES
         // This is a bit more complex so do this manually - we have to poke around with the issue log
         $table = TBGIssuesTable::getTable();
         $crit = $table->getCriteria();
         $crit->addWhere(TBGIssuesTable::SCOPE, $scope->getID());
         $crit->addWhere(TBGIssuesTable::DELETED, false);
         $res = $table->doSelect($crit);
         if ($res) {
             while ($row = $res->getNextRow()) {
                 $crit = TBGLogTable::getTable()->getCriteria();
                 $crit->addSelectionColumn(TBGLogTable::UID);
                 $crit->addWhere(TBGLogTable::CHANGE_TYPE, TBGLogTable::LOG_ISSUE_ASSIGNED);
                 $crit->addWhere(TBGLogTable::TARGET, $row->get(TBGIssuesTable::ID));
                 $crit->addWhere(TBGLogTable::TARGET_TYPE, TBGLogTable::TYPE_ISSUE);
                 $crit->addOrderBy(TBGLogTable::TIME, b2db\Criteria::SORT_DESC);
                 $crit->addOrderBy(TBGLogTable::ID, b2db\Criteria::SORT_DESC);
                 if ($row2 = TBGLogTable::getTable()->doSelectOne($crit)) {
                     $assigned_by = $row2->get(TBGLogTable::UID);
                 }
                 $crit = TBGLogTable::getTable()->getCriteria();
                 $crit->addSelectionColumn(TBGLogTable::UID);
                 $crit->addWhere(TBGLogTable::TARGET, $row->get(TBGIssuesTable::ID));
                 $crit->addWhere(TBGLogTable::TARGET_TYPE, TBGLogTable::TYPE_ISSUE);
                 $crit->addOrderBy(TBGLogTable::TIME, b2db\Criteria::SORT_DESC);
                 $crit->addOrderBy(TBGLogTable::ID, b2db\Criteria::SORT_DESC);
                 if ($row2 = TBGLogTable::getTable()->doSelectOne($crit)) {
                     $updated_by = $row2->get(TBGLogTable::UID);
                 }
                 unset($crit);
                 unset($row2);
                 if (array_key_exists('uid_' . $row->get(TBGIssuesTable::POSTED_BY), $offsets['users'])) {
                     $offset = $offsets['users']['uid_' . $row->get(TBGIssuesTable::POSTED_BY)];
                 } else {
                     $offset = $offsets['system'];
                 }
                 if (isset($updated_by) && array_key_exists('uid_' . $updated_by, $offsets['users'])) {
                     $offset2 = $offsets['users']['uid_' . $updated_by];
                 } elseif (isset($updated_by)) {
                     $offset2 = $offsets['system'];
                 }
                 if (isset($assigned_by) && array_key_exists('uid_' . $assigned_by, $offsets['users'])) {
                     $offset3 = $offsets['users']['uid_' . $assigned_by];
                 } elseif (isset($assigned_by)) {
                     $offset3 = $offsets['system'];
                 }
                 $crit2 = $table->getCriteria();
                 $crit2->addUpdate(TBGIssuesTable::POSTED, (int) $row->get(TBGIssuesTable::POSTED) + $offset);
                 if (isset($offset2)) {
                     $crit2->addUpdate(TBGIssuesTable::LAST_UPDATED, (int) $row->get(TBGIssuesTable::LAST_UPDATED) + $offset2);
                     unset($offset2);
                 }
                 if (isset($offset3)) {
                     $crit2->addUpdate(TBGIssuesTable::BEING_WORKED_ON_BY_USER_SINCE, (int) $row->get(TBGIssuesTable::BEING_WORKED_ON_BY_USER_SINCE) + $offset3);
                     unset($offset3);
                 }
                 $crit2->addWhere(TBGIssuesTable::ID, $row->get(TBGIssuesTable::ID));
                 $table->doUpdate($crit2);
             }
         }
         // LOG
         $this->_fixUserDependentTimezone($offsets, TBGLogTable::getTable(), TBGLogTable::UID, TBGLogTable::TIME, $scope);
         // MILESTONES
         // The conditions are a bit different here so do it manually
         $table = TBGMilestonesTable::getTable();
         $crit = $table->getCriteria();
         $crit->addWhere(TBGMilestonesTable::SCOPE, $scope->getID());
         $res = $table->doSelect($crit);
         if ($res) {
             while ($row = $res->getNextRow()) {
                 $offset = $offsets['system'];
                 $crit2 = $table->getCriteria();
                 $added = 0;
                 if ($row->get(TBGMilestonesTable::REACHED) > 0) {
                     $crit2->addUpdate(TBGMilestonesTable::REACHED, (int) $row->get(TBGMilestonesTable::REACHED) + $offset);
                     $added = 1;
                 }
                 if ($row->get(TBGMilestonesTable::SCHEDULED) > 0) {
                     $crit2->addUpdate(TBGMilestonesTable::SCHEDULED, (int) $row->get(TBGMilestonesTable::SCHEDULED) + $offset);
                     $added = 1;
                 }
                 if ($row->get(TBGMilestonesTable::STARTING) > 0) {
                     $crit2->addUpdate(TBGMilestonesTable::STARTING, (int) $row->get(TBGMilestonesTable::STARTING) + $offset);
                     $added = 1;
                 }
                 // Only do something if at least one call to addUpdate is done
                 if ($added == 1) {
                     $crit2->addWhere(TBGMilestonesTable::ID, $row->get(TBGMilestonesTable::ID));
                     $table->doUpdate($crit2);
                 }
             }
         }
         // PROJECTS
         $this->_fixNonUserDependentTimezone($offsets, TBGProjectsTable::getTable(), TBGProjectsTable::RELEASE_DATE, $scope, TBGProjectsTable::RELEASED);
         // VCS INTEGRATION
         // check if module is loaded
         $modules = TBGModulesTable::getTable()->getModulesForScope($scope->getID());
         if ($modules['vcs_integration'] == true) {
             TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'vcs_integration' . DS . 'classes' . DS . 'B2DB');
             TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'vcs_integration' . DS . 'classes');
             $this->_fixUserDependentTimezone($offsets, TBGVCSIntegrationTable::getTable(), TBGVCSIntegrationTable::AUTHOR, TBGVCSIntegrationTable::DATE, $scope);
         }
     }
 }