示例#1
0
 /**
  * @throws CouldNotUpdateArticleContent
  */
 public function updateContent()
 {
     try {
         $content = $this->articleFetcher->fetchContent($this->getArticleUrl()->getUrl());
         $title = $this->articleFetcher->fetchTitle($this->getArticleUrl()->getUrl());
     } catch (CouldNotRetrieveContentException $exception) {
         throw new CouldNotUpdateArticleContent($exception->getMessage(), $exception->getCode());
     }
     $articleContent = new ArticleContent($title, $content, new \DateTime());
     try {
         $lastContent = $this->articleRepository->getLastContentOfArticle($this->getArticleId());
         if ($lastContent->getTitle() !== $articleContent->getTitle() || $lastContent->getHtml() !== $articleContent->getHtml()) {
             $this->articleRepository->addContent($this->getArticleId(), $articleContent);
         }
     } catch (NoContent $e) {
         $this->articleRepository->addContent($this->getArticleId(), $articleContent);
     }
 }
示例#2
0
 /**
  * Add content to an article into the database
  *
  * @param ArticleId      $articleId
  * @param ArticleContent $articleContent
  *
  * @return bool
  */
 public function addContent(ArticleId $articleId, ArticleContent $articleContent)
 {
     return $this->db->insert('article_content', array('title' => $articleContent->getTitle(), 'content' => $articleContent->getHtml(), 'article_id' => $articleId->getId(), 'date' => $articleContent->getDate()->format('U')));
 }