Example #1
0
 public function doSave($options = array(), $reason = null)
 {
     if (tables\Articles::getTable()->doesNameConflictExist($this->_name, $this->_id, framework\Context::getScope()->getID())) {
         if (!array_key_exists('overwrite', $options) || !$options['overwrite']) {
             throw new \Exception(framework\Context::getI18n()->__('Another article with this name already exists'));
         }
     }
     $user_id = framework\Context::getUser() instanceof User ? framework\Context::getUser()->getID() : 0;
     if (!isset($options['revert']) || !$options['revert']) {
         $revision = tables\ArticleHistory::getTable()->addArticleHistory($this->_name, $this->_old_content, $this->_content, $user_id, $reason);
     } else {
         $revision = null;
     }
     tables\ArticleLinks::getTable()->deleteLinksByArticle($this->_name);
     ArticleCategories::getTable()->deleteCategoriesByArticle($this->_name);
     if ($this->getArticleType() == self::TYPE_MANUAL && isset($options['article_prev_name']) && $this->_name != $options['article_prev_name']) {
         $manual_articles = Articles::getTable()->getManualSidebarArticles(framework\Context::getCurrentProject(), $options['article_prev_name']);
         foreach ($manual_articles as $manual_article) {
             $manual_article->setName(str_replace($options['article_prev_name'], $this->_name, $manual_article->getName()));
             $manual_article->doSave();
         }
     }
     $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) {
         tables\ArticleLinks::getTable()->addArticleLink($this->_name, $link);
     }
     foreach ($categories as $category => $occurrences) {
         ArticleCategories::getTable()->addArticleCategory($this->_name, $category, $this->isCategory());
     }
     $this->_history = null;
     \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\modules\\publish\\entities\\Article::doSave', $this, compact('reason', 'revision', 'user_id'))->trigger();
     return true;
 }
Example #2
0
 public function getUnlinkedArticles(\thebuggenie\core\entities\Project $project = null)
 {
     $names = ArticleLinks::getTable()->getUniqueLinkedArticleNames();
     $crit = $this->getCriteria();
     if ($project instanceof \thebuggenie\core\entities\Project) {
         $crit->addWhere(self::NAME, ucfirst($project->getKey()) . ":%", Criteria::DB_LIKE);
     } else {
         foreach (\thebuggenie\core\entities\tables\Projects::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, framework\Context::getScope()->getID());
     return $this->select($crit);
 }