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']) { TBGArticleHistoryTable::getTable()->addArticleHistory($this->_name, $this->_old_content, $this->_content, $user_id, $reason); } $this->save(); $this->_old_content = $this->_content; TBGArticleLinksTable::getTable()->deleteLinksByArticle($this->_name); TBGArticleCategoriesTable::getTable()->deleteCategoriesByArticle($this->_name); if (substr($this->getContent(), 0, 10) == "#REDIRECT ") { $content = explode("\n", $this->getContent()); preg_match('/(\\[\\[([^\\]]*?)\\]\\])$/im', 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; return true; }
public function getUnlinkedArticles(TBGProject $project = null) { $names = TBGArticleLinksTable::getTable()->getUniqueLinkedArticleNames(); $crit = $this->getCriteria(); if ($project instanceof TBGProject) { $crit->addWhere(self::NAME, ucfirst($project->getKey()) . ":%", Criteria::DB_LIKE); } else { foreach (TBGProjectsTable::getTable()->getAllIncludingDeleted() as $project) { if (trim($project->getKey()) == '') { continue; } $crit->addWhere(self::NAME, "Category:" . ucfirst($project->getKey()) . "%", Criteria::DB_NOT_LIKE); $crit->addWhere(self::NAME, ucfirst($project->getKey()) . ":%", Criteria::DB_NOT_LIKE); } } $crit->addWhere(self::NAME, $names, Criteria::DB_NOT_IN); $crit->addWhere(self::CONTENT, '#REDIRECT%', Criteria::DB_NOT_LIKE); $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID()); return $this->select($crit); }