Beispiel #1
0
 /**
  * Store jobs in the database
  * @since Version 3.9
  * @return \Railpage\News\Scraper
  * @param boolean $logging Enable verbose logging of this feature
  */
 public function store($logging = false)
 {
     /**
      * Get Sphinx so we can lookup similar articles to prevent duplicates
      */
     $Sphinx = $this->getSphinx();
     foreach ($this->articles as $article) {
         /**
          * Look through our approved news articles for a possible duplication
          */
         $query = $Sphinx->select("*")->from("idx_news_article")->orderBy("story_time_unix", "DESC")->where("story_time_unix", ">=", $article['date']->sub(new DateInterval("P7D"))->getTimestamp())->match("story_title", $article['title']);
         $matches = $query->execute();
         /**
          * Look through our rejected titles to see if we've already rejected this
          */
         $query = $Sphinx->select("*")->from("idx_news_articles_rejected")->match("title", $article['title']);
         $rejected = $query->execute();
         /**
          * If no matches are found we'll add in the article
          */
         if (!count($matches) && !count($rejected)) {
             $Article = new Article();
             $Article->title = $article['title'];
             $Article->blurb = $article['blurb'];
             $Article->source = $article['source'];
             $Article->body = $article['body'];
             $Article->setTopic($article['topic'])->setAuthor(new User(User::SYSTEM_USER_ID))->commit(true);
             if ($logging) {
                 printf("Added news article \"%s\" (ID %d) in topic %s\n", $Article->title, $Article->id, $Article->Topic->name);
             }
         }
     }
     return $this;
 }