public function do_execute() { $scope = \thebuggenie\core\entities\tables\Scopes::getTable()->getByHostname($this->getProvidedArgument('hostname')); if ($scope instanceof Scope) { $message = "Removing scope with ID " . $scope->getID() . " for hostname " . $this->getProvidedArgument('hostname'); $this->cliEcho($message . "\n\n"); $scope->delete(); $this->cliEcho("Done", 'white', 'bold'); } else { $message = "No scope found for hostname " . $this->getProvidedArgument('hostname'); $this->cliEcho($message . "\n\n", 'white', 'bold'); } $this->cliEcho("\n"); }
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 final function _processArguments() { $cc = 1; foreach ($this->_required_arguments as $key => $argument) { $cc++; if ($this->hasProvidedArgument($key)) { continue; } if ($this->hasProvidedArgument($cc)) { if (mb_substr(self::$_provided_arguments[$cc], 0, 2) == '--' && mb_substr(self::$_provided_arguments[$cc], 2, mb_strpos(self::$_provided_arguments[$cc], '=') - 1) != $key) { continue; } self::$_provided_arguments[$key] = self::$_provided_arguments[$cc]; if (!is_numeric($key)) { self::$_named_arguments[$key] = self::$_provided_arguments[$cc]; } continue; } } foreach (self::$_provided_arguments as $key => $value) { $this->{$key} = $value; } $diff = array_diff(array_keys($this->_required_arguments), array_keys(self::$_named_arguments)); if (count($diff)) { throw new \Exception('Please include all required arguments. Missing arguments: ' . join(', ', $diff)); } foreach ($this->_optional_arguments as $key => $argument) { $cc++; if ($this->hasProvidedArgument($key)) { continue; } if ($this->hasProvidedArgument($cc)) { if (mb_substr(self::$_provided_arguments[$cc], 0, 2) == '--' && mb_substr(self::$_provided_arguments[$cc], 2, mb_strpos(self::$_provided_arguments[$cc], '=') - 1) != $key) { continue; } self::$_provided_arguments[$key] = self::$_provided_arguments[$cc]; if (!is_numeric($key)) { self::$_named_arguments[$key] = self::$_provided_arguments[$cc]; } continue; } } if ($this->_scoped && array_key_exists('scope', self::$_named_arguments)) { $scope = \thebuggenie\core\entities\tables\Scopes::getTable()->selectById(self::$_named_arguments['scope']); $this->cliEcho("Using scope " . $scope->getID() . "\n"); \thebuggenie\core\framework\Context::setScope($scope); } }
public function getScopeDetailsByUser($user_id) { $crit = $this->getCriteria(); $crit->addWhere(self::USER_ID, $user_id); $scope_details = array(); if ($res = $this->doSelect($crit)) { while ($row = $res->getNextRow()) { $scope_details[$row->get(self::SCOPE)] = array('confirmed' => (bool) $row->get(self::CONFIRMED), 'group_id' => $row->get(self::GROUP_ID), 'internal_id' => $row->get(self::ID)); } } if (count($scope_details)) { $scopes = Scopes::getTable()->getByIds(array_keys($scope_details)); foreach ($scope_details as $id => $detail) { if (array_key_exists($id, $scopes)) { $scope_details[$id]['scope'] = $scopes[$id]; } else { $this->doDeleteById($detail['internal_id']); unset($scope_details[$id]); } } } return $scope_details; }
/** * Find and set the current scope * * @param Scope $scope Specify a scope to set for this request */ public static function setScope($scope = null) { Logging::log("Setting current scope"); if ($scope !== null) { Logging::log("Setting scope from function parameter"); self::$_scope = $scope; Settings::forceSettingsReload(); Logging::log("...done (Setting scope from function parameter)"); return true; } $row = null; try { $hostname = null; if (!self::isCLI() && !self::isInstallmode()) { Logging::log("Checking if scope can be set from hostname (" . $_SERVER['HTTP_HOST'] . ")"); $hostname = $_SERVER['HTTP_HOST']; } if (!self::isUpgrademode() && !self::isInstallmode()) { $scope = \thebuggenie\core\entities\tables\Scopes::getTable()->getByHostnameOrDefault($hostname); } if (!$scope instanceof Scope) { Logging::log("It couldn't", 'main', Logging::LEVEL_WARNING); if (!self::isInstallmode()) { throw new \Exception("The Bug Genie isn't set up to work with this server name."); } else { return; } } Logging::log("Setting scope {$scope->getID()} from hostname"); self::$_scope = $scope; Settings::forceSettingsReload(); Settings::loadSettings(); Logging::log("...done (Setting scope from hostname)"); return true; } catch (\Exception $e) { if (self::isCLI()) { Logging::log("Couldn't set up default scope.", 'main', Logging::LEVEL_FATAL); throw new \Exception("Could not load default scope. Error message was: " . $e->getMessage()); } elseif (!self::isInstallmode()) { Logging::log("Couldn't find a scope for hostname {$_SERVER['HTTP_HOST']}", 'main', Logging::LEVEL_FATAL); Logging::log($e->getMessage(), 'main', Logging::LEVEL_FATAL); throw new \Exception("Could not load scope. This is usually because the scopes table doesn't have a scope for this hostname"); } else { Logging::log("Couldn't find a scope for hostname {$_SERVER['HTTP_HOST']}, but we're in installmode so continuing anyway"); } } }
public function runScopes(framework\Request $request) { if ($request->isPost()) { $hostname = $request['hostname']; $hostname = str_replace(array('http://', 'https://'), array('', ''), $hostname); $scopename = $request['name']; if (!$hostname || tables\Scopes::getTable()->getByHostname($hostname) instanceof entities\Scope) { $this->scope_hostname_error = true; } elseif (!$scopename) { $this->scope_name_error = true; } else { $scope = new entities\Scope(); $scope->addHostname($hostname); $scope->setName($scopename); $scope->setEnabled(); $scope->save(); $this->forward(framework\Context::getRouting()->generate('configure_scopes')); } } $this->scope_deleted = framework\Context::getMessageAndClear('scope_deleted'); $this->scope_saved = framework\Context::getMessageAndClear('scope_saved'); $this->scopes = entities\Scope::getAll(); }
public function getStatusListForUpgrade() { $crit = $this->getCriteria(); $crit->addWhere(self::ITEMTYPE, \thebuggenie\core\entities\Datatype::STATUS); $crit->addJoin(Scopes::getTable(), Scopes::ID, self::SCOPE); $res = $this->doSelect($crit); $statuses = array(); while ($row = $res->getNextRow()) { if (!array_key_exists($row[self::SCOPE], $statuses)) { $statuses[$row[self::SCOPE]] = array('scopename' => $row[Scopes::NAME], 'statuses' => array()); } $statuses[$row[self::SCOPE]]['statuses'][$row[self::ID]] = $row[self::NAME]; } return $statuses; }
protected function _setup($b2db_name, $id_column) { parent::_setup($b2db_name, $id_column); parent::_addForeignKeyColumn(static::SCOPE, \thebuggenie\core\entities\tables\Scopes::getTable(), \thebuggenie\core\entities\tables\Scopes::ID); }
/** * Return all available scopes * * @return array|\thebuggenie\core\entities\Scope */ static function getAll() { if (self::$_scopes === null) { self::$_scopes = tables\Scopes::getTable()->selectAll(); } return self::$_scopes; }
public function do_execute() { $from_scope = Scopes::getTable()->selectById($this->getProvidedArgument('scope_id')); $verbose = (bool) $this->getProvidedArgument('verbose'); if (!$from_scope instanceof Scope) { throw new \Exception("Cannot read from scope " . $this->getProvidedArgument('scope_id')); } $this->cliEcho("Reading project list from scope {$from_scope->getID()} (" . join($from_scope->getHostnames(), ',') . ")\n"); $this->from_scope = $from_scope->getID(); $projects = $this->_getProjects(); if (!count($projects)) { throw new \Exception("There are no projects to move"); } $project_id = $this->getProvidedArgument('project_id'); if (!$project_id) { $this->cliEcho("\n"); $this->cliEcho("Please choose the project to move from the list below:\n"); foreach ($projects as $project_id => $project) { $this->cliEcho($project->getID() . ': ', 'white', 'bold'); $this->cliEcho('[' . $project->getKey() . '] ' . $project->getName() . "\n"); } $this->cliEcho("\n"); $this->cliEcho("Enter the ID of the project you want to move, or 'all' to move all projects: "); $project_id = (int) $this->getInput(); } if (strpos($project_id, ',') !== false) { $project_ids = explode(',', $project_id); } elseif ($project_id == 'all') { $project_ids = array_keys($projects); } else { $project_ids = [$project_id]; } foreach ($project_ids as $project_id) { if (!array_key_exists($project_id, $projects)) { var_dump($project_id); throw new \Exception("Please select a project id from the list"); } $project = $projects[$project_id]; $to_scope_id = $this->getProvidedArgument('to_scope_id'); if (!$to_scope_id) { $this->cliEcho("\n"); $this->cliEcho("Enter the hostname of the scope you want to move this project to, or press [Enter] for the default scope.\n"); $this->cliEcho("Hostname [default]: "); $hostname = $this->getInput(); $to_scope = $this->_getScope($hostname); } else { $to_scope = Scopes::getTable()->selectById($to_scope_id); } if (!$to_scope instanceof Scope) { throw new \Exception("Could not find target scope"); } $to_scope_id = $to_scope->getID(); if ($to_scope_id == $from_scope->getID()) { throw new \Exception("Cannot move the project to the same scope"); } $this->cliEcho("\n"); $this->cliEcho("Moving project ", 'green'); if ($verbose) { $this->cliEcho($project->getName() . " [{$project->getID()}]", 'white', 'bold'); } else { $this->cliEcho($project->getName(), 'white', 'bold'); } if ($from_scope->isDefault()) { $this->cliEcho(" from ", 'green'); $this->cliEcho("default scope", 'white', 'bold'); } else { $this->cliEcho(" from ", 'green'); if ($verbose) { $this->cliEcho(join($from_scope->getHostnames(), ',') . " [{$from_scope->getID()}]", 'white', 'bold'); } else { $this->cliEcho(join($from_scope->getHostnames(), ','), 'white', 'bold'); } } $this->cliEcho(" to ", 'green'); if ($verbose) { $this->cliEcho(join($to_scope->getHostnames(), ',') . " [{$to_scope->getID()}]", 'white', 'bold'); } else { $this->cliEcho(join($to_scope->getHostnames(), ','), 'white', 'bold'); } $this->cliEcho("\n"); $this->cliEcho("\n"); if ($this->getProvidedArgument('skip-confirmation', 'no') != 'yes') { $this->cliEcho("Please type [yes] to start moving the project: \n"); if (!$this->getInputConfirmation()) { $this->cliEcho("Cancelled", 'red', 'bold'); $this->cliEcho("\n"); $this->cliEcho("\n"); return; } } $this->moveProject($project_id, $to_scope_id); } }