public function addArticleHistory($article_name, $old_content, $new_content, $user_id, $reason = null) { if (!Core::isTransactionActive()) { $transaction = Core::startTransaction(); } $crit = $this->getCriteria(); $crit->addInsert(self::ARTICLE_NAME, $article_name); $crit->addInsert(self::AUTHOR, $user_id); $revision_number = $this->_getNextRevisionNumberForArticle($article_name); $crit->addInsert(self::REVISION, $revision_number); if (!($revision_number == 1 && $old_content == $new_content)) { $crit->addInsert(self::OLD_CONTENT, $old_content); } else { $crit->addInsert(self::OLD_CONTENT, ''); } $crit->addInsert(self::NEW_CONTENT, $new_content); if ($reason !== null) { $crit->addInsert(self::REASON, $reason); } $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID()); $crit->addInsert(self::DATE, NOW); $res = $this->doInsert($crit); if (isset($transaction)) { $transaction->commitAndEnd(); } return $revision_number; }
/** * Installs a module * * @param string $module_name the module key * @return boolean Whether the install succeeded or not */ public static function installModule($module_name, $scope = null) { $scope_id = $scope ? $scope->getID() : framework\Context::getScope()->getID(); if (!framework\Context::getScope() instanceof \thebuggenie\core\entities\Scope) { throw new \Exception('No scope??'); } framework\Logging::log('installing module ' . $module_name); $transaction = \b2db\Core::startTransaction(); try { $module = tables\Modules::getTable()->installModule($module_name, $scope_id); $module->install($scope_id); $transaction->commitAndEnd(); } catch (\Exception $e) { $transaction->rollback(); throw $e; } framework\Logging::log('done (installing module ' . $module_name . ')'); return $module; }
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 _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; }
/** * Configuration import page * * @param framework\Request $request */ public function runIndex(framework\Request $request) { if ($request->isPost()) { if ($request['import_sample_data']) { $transaction = \b2db\Core::startTransaction(); $users = array(); $user1 = new entities\User(); $user1->setUsername('john'); $user1->setPassword('john'); $user1->setBuddyname('John'); $user1->setRealname('John'); $user1->setActivated(); $user1->setEnabled(); $user1->save(); $users[] = $user1; $user2 = new entities\User(); $user2->setUsername('jane'); $user2->setPassword('jane'); $user2->setBuddyname('Jane'); $user2->setRealname('Jane'); $user2->setActivated(); $user2->setEnabled(); $user2->save(); $users[] = $user2; $user3 = new entities\User(); $user3->setUsername('jackdaniels'); $user3->setPassword('jackdaniels'); $user3->setBuddyname('Jack'); $user3->setRealname('Jack Daniels'); $user3->setActivated(); $user3->setEnabled(); $user3->save(); $users[] = $user3; $project1 = new entities\Project(); $project1->setName('Sample project 1'); $project1->setOwner($users[rand(0, 2)]); $project1->setLeader($users[rand(0, 2)]); $project1->setQaResponsible($users[rand(0, 2)]); $project1->setDescription('This is a sample project that is awesome. Try it out!'); $project1->setHomepage('http://www.google.com'); $project1->save(); $project2 = new entities\Project(); $project2->setName('Sample project 2'); $project2->setOwner($users[rand(0, 2)]); $project2->setLeader($users[rand(0, 2)]); $project2->setQaResponsible($users[rand(0, 2)]); $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!'); $project2->setHomepage('http://www.bing.com'); $project2->save(); foreach (array($project1, $project2) as $project) { for ($cc = 1; $cc <= 5; $cc++) { $milestone = new entities\Milestone(); $milestone->setName("Milestone {$cc}"); $milestone->setProject($project); $milestone->setType(entities\Milestone::TYPE_REGULAR); if ((bool) rand(0, 1)) { $milestone->setScheduledDate(NOW + 100000 * (20 * $cc)); } $milestone->save(); } } $p1_milestones = $project1->getMilestones(); $p2_milestones = $project2->getMilestones(); $issues = array(); $priorities = entities\Priority::getAll(); $categories = entities\Category::getAll(); $severities = entities\Severity::getAll(); $statuses = entities\Status::getAll(); $reproducabilities = entities\Reproducability::getAll(); $lorem_ipsum = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('LoremIpsum'); $lorem_words = explode(' ', $lorem_ipsum->getContent()); foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) { $issuetype = entities\Issuetype::getByKeyish($issuetype); for ($cc = 1; $cc <= 10; $cc++) { $issue1 = new entities\Issue(); $issue1->setProject($project1); $issue1->setPostedBy($users[rand(0, 2)]); $issue1->setPosted(NOW - 86400 * rand(1, 30)); $title_string = ''; $description_string = ''; $rand_length = rand(4, 15); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word); $title_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $title_string .= '.'; $ucnext = true; } $title_string .= ' '; } $rand_length = rand(40, 500); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word); $description_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $description_string .= '.'; $ucnext = true; $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' '; } else { $description_string .= ' '; } } $issue1->setTitle(ucfirst($title_string)); $issue1->setDescription($description_string); $issue1->setIssuetype($issuetype); $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]); $issue1->setPriority($priorities[array_rand($priorities)]); $issue1->setCategory($categories[array_rand($categories)]); $issue1->setSeverity($severities[array_rand($severities)]); $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]); $issue1->setPercentCompleted(rand(0, 100)); $issue1->save(); $issue1->setStatus($statuses[array_rand($statuses)]); if (rand(0, 1)) { $issue1->setAssignee($users[array_rand($users)]); } $issue1->save(); $issues[] = $issue1; $issue2 = new entities\Issue(); $issue2->setProject($project2); $issue2->setPostedBy($users[rand(0, 2)]); $issue2->setPosted(NOW - 86400 * rand(1, 30)); $title_string = ''; $description_string = ''; $rand_length = rand(4, 15); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word); $title_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $title_string .= '.'; $ucnext = true; } $title_string .= ' '; } $rand_length = rand(40, 500); $ucnext = true; for ($ll = 1; $ll <= $rand_length; $ll++) { $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]); $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word); $description_string .= $word; $ucnext = false; if ($ll == $rand_length || rand(1, 15) == 5) { $description_string .= '.'; $ucnext = true; $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' '; } else { $description_string .= ' '; } } $issue2->setTitle(ucfirst($title_string)); $issue2->setDescription($description_string); $issue2->setIssuetype($issuetype); $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]); $issue2->setPriority($priorities[array_rand($priorities)]); $issue2->setCategory($categories[array_rand($categories)]); $issue2->setSeverity($severities[array_rand($severities)]); $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]); $issue2->setPercentCompleted(rand(0, 100)); if (rand(0, 1)) { $issue1->setAssignee($users[array_rand($users)]); } $issue2->save(); $issue2->setStatus($statuses[array_rand($statuses)]); $issue2->save(); $issues[] = $issue2; } } $rand_issues_to_close = rand(8, 40); $resolutions = entities\Resolution::getAll(); for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) { $issue = array_slice($issues, array_rand($issues), 1); $issue = $issue[0]; $issue->setResolution($resolutions[array_rand($resolutions)]); $issue->close(); $issue->save(); } $this->imported_data = true; $roles = entities\Role::getAll(); foreach (array($project1, $project2) as $project) { foreach ($users as $user) { $project->addAssignee($user, $roles[array_rand($roles)]); } } $transaction->commitAndEnd(); } } $project1 = entities\Project::getByKey('sampleproject1'); $project2 = entities\Project::getByKey('sampleproject2'); $this->canimport = !$project1 instanceof entities\Project && !$project2 instanceof entities\Project; }