public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::USER_ID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::ARTICLE_ID, TBGArticlesTable::getTable(), TBGArticlesTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::USER_ID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::ARTICLE_ID, TBGArticlesTable::getTable(), TBGArticlesTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::UID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
     parent::_addForeignKeyColumn(self::ARTICLE_ID, TBGArticlesTable::getTable(), TBGArticlesTable::ID);
     parent::_addForeignKeyColumn(self::FILE_ID, TBGFilesTable::getTable(), TBGFilesTable::ID);
     parent::_addInteger(self::ATTACHED_AT, 10);
 }
 public function getUserStarredArticles($user_id)
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::UID, $user_id);
     $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID());
     $crit->addJoin(TBGArticlesTable::getTable(), TBGArticlesTable::ID, self::ARTICLE);
     $crit->addWhere(TBGArticlesTable::DELETED, 0);
     $res = $this->doSelect($crit);
     return $res;
 }
 public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::TITLE, 255);
     parent::_addText(self::CONTENT, false);
     parent::_addText(self::LINK, false);
     parent::_addBoolean(self::IS_DELETED);
     parent::_addInteger(self::DATE, 10);
     parent::_addInteger(self::TARGET_BOARD, 10);
     parent::_addForeignKeyColumn(self::ARTICLE_ID, TBGArticlesTable::getTable(), TBGArticlesTable::ID);
     parent::_addForeignKeyColumn(self::AUTHOR, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function do_execute()
 {
     $this->cliEcho("Extracting articles ... \n", 'white', 'bold');
     $articles = TBGArticlesTable::getTable()->getAllArticles();
     $this->cliEcho("Articles found: ");
     $this->cliEcho(count($articles) . "\n", 'green', 'bold');
     foreach ($articles as $article_id => $article) {
         $filename = THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS . urlencode($article->getName());
         if (!file_exists($filename) || $this->getProvidedArgument('overwrite', 'no') == 'yes') {
             $this->cliEcho("Saving ");
             file_put_contents($filename, $article->getContent());
         } else {
             $this->cliEcho("Skipping ");
         }
         $this->cliEcho($article->getName() . "\n", 'white', 'bold');
     }
 }
Esempio n. 7
0
 /**
  * Pre-execute function
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->getResponse()->setPage('wiki');
     $i18n = TBGContext::getI18n();
     $this->article = null;
     $this->article_name = $request->getParameter('article_name');
     if ($request->hasParameter('article_name') && strpos($request->getParameter('article_name'), ':') !== false) {
         $namespace = substr($this->article_name, 0, strpos($this->article_name, ':'));
         $article_name = substr($this->article_name, strpos($this->article_name, ':') + 1);
         if ($namespace == 'Category') {
             $namespace = substr($article_name, 0, strpos($article_name, ':'));
             $article_name = substr($article_name, strpos($article_name, ':') + 1);
         }
         if ($namespace != '') {
             $key = strtolower($namespace);
             $row = TBGProjectsTable::getTable()->getByKey($key);
             if ($row instanceof B2DBRow) {
                 $project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row);
                 if ($project instanceof TBGProject) {
                     $this->forward403unless($project->hasAccess());
                 }
                 TBGContext::setCurrentProject($project);
             }
         }
     } else {
         try {
             if ($project_key = $request->getParameter('project_key')) {
                 $row = TBGProjectsTable::getTable()->getByKey($project_key);
                 $this->selected_project = TBGContext::factory()->TBGProject($row->get(TBGProjectsTable::ID), $row);
             } elseif ($project_id = (int) $request->getParameter('project_id')) {
                 $this->selected_project = TBGContext::factory()->TBGProject($project_id);
             }
             if ($this->selected_project instanceof TBGProject) {
                 $this->forward403unless($this->selected_project->hasAccess());
             }
             TBGContext::setCurrentProject($this->selected_project);
         } catch (Exception $e) {
         }
     }
     if ($row = TBGArticlesTable::getTable()->getArticleByName($this->article_name)) {
         $this->article = PublishFactory::article($row->get(TBGArticlesTable::ID), $row);
     }
 }
 public function componentReportIssue()
 {
     $introarticle = TBGArticlesTable::getTable()->getArticleByName(ucfirst(TBGContext::getCurrentProject()->getKey()) . ':ReportIssueIntro');
     $this->introarticle = $introarticle instanceof TBGWikiArticle ? $introarticle : TBGArticlesTable::getTable()->getArticleByName('ReportIssueIntro');
     $reporthelparticle = TBGArticlesTable::getTable()->getArticleByName(ucfirst(TBGContext::getCurrentProject()->getKey()) . ':ReportIssueHelp');
     $this->reporthelparticle = $reporthelparticle instanceof TBGWikiArticle ? $reporthelparticle : TBGArticlesTable::getTable()->getArticleByName('ReportIssueHelp');
     $this->uniqid = TBGContext::getRequest()->getParameter('uniqid', uniqid());
     $this->_setupReportIssueProperties();
     $dummyissue = new TBGIssue();
     $dummyissue->setProject(TBGContext::getCurrentProject());
     $this->canupload = TBGSettings::isUploadsEnabled() && $dummyissue->canAttachFiles();
 }
 public function componentSpecialWhatLinksHere()
 {
     $this->linked_article_name = TBGContext::getRequest()->getParameter('linked_article_name');
     $this->articles = TBGArticlesTable::getTable()->getAllByLinksToArticleName($this->linked_article_name);
 }
Esempio n. 10
0
 public function doSave($options = array(), $reason = null)
 {
     if (TBGArticlesTable::getTable()->doesNameConflictExist($this->_name, $this->_id, TBGContext::getScope()->getID())) {
         if (!array_key_exists('overwrite', $options) || !$options['overwrite']) {
             throw new Exception(TBGContext::getI18n()->__('Another article with this name already exists'));
         }
     }
     $user_id = TBGContext::getUser() instanceof TBGUser ? TBGContext::getUser()->getID() : 0;
     if (!isset($options['revert']) || !$options['revert']) {
         $revision = TBGArticleHistoryTable::getTable()->addArticleHistory($this->_name, $this->_old_content, $this->_content, $user_id, $reason);
     } else {
         $revision = null;
     }
     TBGArticleLinksTable::getTable()->deleteLinksByArticle($this->_name);
     TBGArticleCategoriesTable::getTable()->deleteCategoriesByArticle($this->_name);
     $this->save();
     $this->_old_content = $this->_content;
     if (mb_substr($this->getContent(), 0, 10) == "#REDIRECT ") {
         $content = explode("\n", $this->getContent());
         preg_match('/(\\[\\[([^\\]]*?)\\]\\])$/im', mb_substr(array_shift($content), 10), $matches);
         if (count($matches) == 3) {
             return;
         }
     }
     list($links, $categories) = $this->_retrieveLinksAndCategoriesFromContent($options);
     foreach ($links as $link => $occurrences) {
         TBGArticleLinksTable::getTable()->addArticleLink($this->_name, $link);
     }
     foreach ($categories as $category => $occurrences) {
         TBGArticleCategoriesTable::getTable()->addArticleCategory($this->_name, $category, $this->isCategory());
     }
     $this->_history = null;
     TBGEvent::createNew('core', 'TBGWikiArticle::doSave', $this, compact('reason', 'revision', 'user_id'))->trigger();
     return true;
 }
 public function getFrontpageArticle($type)
 {
     $article_name = $type == 'main' ? 'FrontpageArticle' : 'FrontpageLeftmenu';
     if ($row = TBGArticlesTable::getTable()->getArticleByName($article_name)) {
         return PublishFactory::article($row->get(TBGArticlesTable::ID), $row);
     }
     return null;
 }
Esempio n. 12
0
 /**
  * Adds an article to the list of articles "starred" by this user 
  *
  * @param integer $article_id ID of article to add
  * @return boolean
  */
 public function addStarredArticle($article_id)
 {
     $this->_populateStarredArticles();
     if ($this->isLoggedIn() && !$this->isGuest()) {
         if (array_key_exists($article_id, $this->_starredarticles)) {
             return true;
         }
         TBGUserArticlesTable::getTable()->addStarredArticle($this->getID(), $article_id);
         $article = TBGArticlesTable::getTable()->selectById($article_id);
         $this->_starredarticles[$article->getID()] = $article;
         ksort($this->_starredarticles);
         return true;
     }
     return false;
 }
 public function componentForgotPasswordPane()
 {
     $this->forgottenintro = TBGArticlesTable::getTable()->getArticleByName('ForgottenPasswordIntro');
 }
Esempio n. 14
0
 /**
  * Returns the object which the notification is for
  *
  * @return TBGIdentifiableScopedClass
  */
 public function getTarget()
 {
     if ($this->_target === null) {
         if ($this->_module_name == 'core') {
             switch ($this->_notification_type) {
                 case self::TYPE_ARTICLE_COMMENTED:
                 case self::TYPE_ARTICLE_MENTIONED:
                 case self::TYPE_ISSUE_COMMENTED:
                 case self::TYPE_ISSUE_MENTIONED:
                 case self::TYPE_COMMENT_MENTIONED:
                     $this->_target = TBGCommentsTable::getTable()->selectById((int) $this->_target_id);
                     break;
                 case self::TYPE_ISSUE_UPDATED:
                 case self::TYPE_ISSUE_CREATED:
                     $this->_target = TBGIssuesTable::getTable()->selectById((int) $this->_target_id);
                     break;
                 case self::TYPE_ARTICLE_UPDATED:
                     $this->_target = TBGArticlesTable::getTable()->selectById((int) $this->_target_id);
                     break;
             }
         } else {
             $event = new TBGEvent('core', 'TBGNotification::getTarget', $this);
             $event->triggerUntilProcessed();
             $this->_target = $event->getReturnValue();
         }
     }
     return $this->_target;
 }
Esempio n. 15
0
 public function getFrontpageArticle($type)
 {
     $article_name = $type == 'main' ? 'FrontpageArticle' : 'FrontpageLeftmenu';
     $article = TBGArticlesTable::getTable()->getArticleByName($article_name);
     return $article;
 }
Esempio n. 16
0
 /**
  * Configuration import page
  * 
  * @param TBGRequest $request
  */
 public function runImport(TBGRequest $request)
 {
     if ($request->isMethod(TBGRequest::POST)) {
         if ($request->getParameter('import_sample_data')) {
             $users = array();
             $user1 = new TBGUser();
             $user1->setUsername('john');
             $user1->setPassword('john');
             $user1->setBuddyname('John');
             $user1->setRealname('John');
             $user1->setActivated();
             $user1->setEnabled();
             $user1->save();
             $users[] = $user1;
             $user2 = new TBGUser();
             $user2->setUsername('jane');
             $user2->setPassword('jane');
             $user2->setBuddyname('Jane');
             $user2->setRealname('Jane');
             $user2->setActivated();
             $user2->setEnabled();
             $user2->save();
             $users[] = $user2;
             $user3 = new TBGUser();
             $user3->setUsername('jackdaniels');
             $user3->setPassword('jackdaniels');
             $user3->setBuddyname('Jack');
             $user3->setRealname('Jack Daniels');
             $user3->setActivated();
             $user3->setEnabled();
             $user3->save();
             $users[] = $user3;
             $project1 = new TBGProject();
             $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 TBGProject();
             $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 TBGMilestone();
                     $milestone->setName("Milestone {$cc}");
                     $milestone->setProject($project);
                     $milestone->setType(TBGMilestone::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 = TBGPriority::getAll();
             $categories = TBGCategory::getAll();
             $severities = TBGSeverity::getAll();
             $statuses = TBGStatus::getAll();
             $reproducabilities = TBGReproducability::getAll();
             $lorem_ipsum = TBGArticlesTable::getTable()->getArticleByName('LoremIpsum');
             $lorem_ipsum = PublishFactory::article($lorem_ipsum->get(TBGArticlesTable::ID), $lorem_ipsum);
             $lorem_words = explode(' ', $lorem_ipsum->getContent());
             foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) {
                 $issuetype = TBGIssuetype::getIssuetypeByKeyish($issuetype);
                 for ($cc = 1; $cc <= 10; $cc++) {
                     $issue1 = new TBGIssue();
                     $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) : 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) : 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 TBGIssue();
                     $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) : 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) : 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 = TBGResolution::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;
             $developer = TBGProjectAssigneesTable::getByType(TBGProjectAssigneesTable::TYPE_DEVELOPER);
             foreach (array($project1, $project2) as $project) {
                 foreach ($users as $user) {
                     $project->addAssignee($user, $developer->getID());
                 }
             }
         }
     }
     $project1 = TBGProject::getByKey('sampleproject1');
     $project2 = TBGProject::getByKey('sampleproject2');
     $this->canimport = !$project1 instanceof TBGProject && !$project2 instanceof TBGProject;
 }
Esempio n. 17
0
 public function getTarget()
 {
     if ($this->_target === null) {
         switch ($this->getTargetType()) {
             case self::TYPE_ISSUE:
                 $this->_target = TBGIssuesTable::getTable()->selectById($this->_target_id);
                 break;
             case self::TYPE_ARTICLE:
                 $this->_target = TBGArticlesTable::getTable()->selectById($this->_target_id);
                 break;
             default:
                 $event = TBGEvent::createNew('core', 'TBGComment::getTarget', $this);
                 $event->trigger();
                 $this->_target = $event->getReturnValue();
         }
     }
     return $this->_target;
 }
Esempio n. 18
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);
         }
     }
 }
Esempio n. 19
0
 protected function _parse_insert_template($matches)
 {
     switch ($matches[1]) {
         case 'CURRENTMONTH':
             return date('m');
         case 'CURRENTMONTHNAMEGEN':
         case 'CURRENTMONTHNAME':
             return date('F');
         case 'CURRENTDAY':
             return date('d');
         case 'CURRENTDAYNAME':
             return date('l');
         case 'CURRENTYEAR':
             return date('Y');
         case 'CURRENTTIME':
             return date('H:i');
         case 'NUMBEROFARTICLES':
             return 0;
         case 'PAGENAME':
             return TBGContext::getResponse()->getPage();
         case 'NAMESPACE':
             return 'None';
         case 'TOC':
             return isset($this->options['included']) ? '' : '{{TOC}}';
         case 'SITENAME':
         case 'SITETAGLINE':
             return TBGSettings::getTBGname();
         default:
             $details = explode('|', $matches[1]);
             $template_name = array_shift($details);
             if (substr($template_name, 0, 1) == ':') {
                 $template_name = substr($template_name, 1);
             }
             $template_name = TBGWikiArticle::doesArticleExist($template_name) ? $template_name : 'Template:' . $template_name;
             $template_article = TBGArticlesTable::getTable()->getArticleByName($template_name);
             $parameters = array();
             if (count($details)) {
                 foreach ($details as $parameter) {
                     $param = explode('=', $parameter);
                     if (count($param) == 2) {
                         $parameters[$param[0]] = $param[1];
                     } else {
                         $parameters[] = $parameter;
                     }
                 }
             }
             if ($template_article instanceof TBGWikiArticle) {
                 return tbg_parse_text($template_article->getContent(), false, null, array('included' => true, 'parameters' => $parameters));
             } else {
                 return $matches[0];
             }
     }
 }
Esempio n. 20
0
 /**
  * Toggle favourite article (starring)
  *  
  * @param TBGRequest $request
  */
 public function runToggleFavouriteArticle(TBGRequest $request)
 {
     if ($article_id = $request['article_id']) {
         try {
             $article = TBGArticlesTable::getTable()->selectById($article_id);
             $user = TBGUsersTable::getTable()->selectById($request['user_id']);
         } catch (Exception $e) {
             return $this->renderText('fail');
         }
     } else {
         return $this->renderText('no article');
     }
     if ($user->isArticleStarred($article_id)) {
         $retval = !$user->removeStarredArticle($article_id);
     } else {
         $retval = $user->addStarredArticle($article_id);
         if ($user->getID() != $this->getUser()->getID()) {
             TBGEvent::createNew('core', 'article_subscribe_user', $article, compact('user'))->trigger();
         }
     }
     return $this->renderText(json_encode(array('starred' => $retval, 'subscriber' => $this->getTemplateHTML('publish/articlesubscriber', array('user' => $user, 'article' => $article)))));
 }
 public function hideFromNews()
 {
     $crit = new B2DBCriteria();
     $crit->addUpdate(TBGArticlesTable::IS_NEWS, 0);
     $res = TBGArticlesTable::getTable()->doUpdateById($crit, $this->_id);
     $this->is_news = false;
 }
Esempio n. 22
0
 public function runAddComment(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     $comment_applies_type = $request['comment_applies_type'];
     try {
         if (!$this->getUser()->canPostComments()) {
             throw new Exception($i18n->__('You are not allowed to do this'));
         }
         if (!trim($request['comment_body'])) {
             throw new Exception($i18n->__('The comment must have some content'));
         }
         $comment = new TBGComment();
         $comment->setTitle('');
         $comment->setContent($request->getParameter('comment_body', null, false));
         $comment->setPostedBy($this->getUser()->getID());
         $comment->setTargetID($request['comment_applies_id']);
         $comment->setTargetType($request['comment_applies_type']);
         $comment->setReplyToComment($request['reply_to_comment_id']);
         $comment->setModuleName($request['comment_module']);
         $comment->setIsPublic((bool) $request['comment_visibility']);
         $comment->setSyntax($request['comment_body_syntax']);
         $comment->save();
         if ($comment_applies_type == TBGComment::TYPE_ISSUE) {
             $issue = TBGIssuesTable::getTable()->selectById((int) $request['comment_applies_id']);
             if (!$request->isAjaxCall() || $request['comment_save_changes']) {
                 $issue->setSaveComment($comment);
                 $issue->save();
             } else {
                 TBGEvent::createNew('core', 'TBGComment::createNew', $comment, compact('issue'))->trigger();
             }
         } elseif ($comment_applies_type == TBGComment::TYPE_ARTICLE) {
             $article = TBGArticlesTable::getTable()->selectById((int) $request['comment_applies_id']);
             TBGEvent::createNew('core', 'TBGComment::createNew', $comment, compact('article'))->trigger();
         }
         switch ($comment_applies_type) {
             case TBGComment::TYPE_ISSUE:
                 $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment, 'issue' => TBGContext::factory()->TBGIssue($request['comment_applies_id'])));
                 break;
             case TBGComment::TYPE_ARTICLE:
                 $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment));
                 break;
             default:
                 $comment_html = 'OH NO!';
         }
     } catch (Exception $e) {
         if ($request->isAjaxCall()) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $e->getMessage()));
         } else {
             TBGContext::setMessage('comment_error', $e->getMessage());
             TBGContext::setMessage('comment_error_body', $request['comment_body']);
             TBGContext::setMessage('comment_error_title', $request['comment_title']);
             TBGContext::setMessage('comment_error_visibility', $request['comment_visibility']);
         }
     }
     if ($request->isAjaxCall()) {
         return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request['forward_url'], 'commentcount' => TBGComment::countComments($request['comment_applies_id'], $request['comment_applies_type'])));
     }
     if (isset($comment) && $comment instanceof TBGComment) {
         $this->forward($request['forward_url'] . "#comment_{$request['comment_applies_type']}_{$request['comment_applies_id']}_{$comment->getID()}");
     } else {
         $this->forward($request['forward_url']);
     }
 }