Example #1
0
 public static function processMessage($msg)
 {
     $params = json_decode($msg->body);
     print_r($params);
     try {
         if ($pn = PendingNews::findOne(['id' => $params->pn_id])) {
             $detector = new SimilarDetectComponent($pn);
             $detector->detect();
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
 }
 public static function processMessage($msg)
 {
     //            print_r($msg);
     try {
         $params = json_decode($msg->body);
         print_r($params);
         $pqItem = ParserQueue::findOne(["id" => $params->pq_id]);
         $pnItem = PendingNews::findOne(["id" => $params->pn_id]);
         if ($pqItem && $pnItem) {
             $newsParser = new NewsParserComponent($pqItem, $pnItem);
             $newsParser->run();
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         if ($e->getCode() != 505) {
             $mq = new RabbitMQComponent();
             $mq->postMessage("parse", "parse_rss", $msg->body);
         }
     }
     $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
     //            die();
 }
 /**
  * Finds the PendingNews model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return PendingNews the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PendingNews::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 protected function detectCategories($news_id, $pn_id)
 {
     $pn = PendingNews::findOne($pn_id);
     $content = mb_strtolower($pn->search_content, 'utf-8');
     if ($pn->additonal_data) {
         $data = json_decode($pn->additonal_data);
         if (isset($data->category_id)) {
             if (!($nhc = NewsHasCategory::findOne(['category_id' => $data->category_id, 'news_id' => $news_id]))) {
                 $nhc = new NewsHasCategory();
                 $nhc->news_id = $news_id;
                 $nhc->category_id = $data->category_id;
                 $nhc->save();
                 return true;
             }
         }
         if ($data->category) {
             $content = mb_strtolower($data->category, 'utf-8');
         }
     }
     $categoryWords = CategoryWords::find()->all();
     foreach ($categoryWords as $cw) {
         if (mb_strpos($content, mb_strtolower($cw->word, 'utf-8'), 0, 'utf-8') !== false) {
             if (!($nhc = NewsHasCategory::findOne(['category_id' => $cw->category_id, 'news_id' => $news_id]))) {
                 $nhc = new NewsHasCategory();
                 $nhc->news_id = $news_id;
                 $nhc->category_id = $cw->category_id;
                 $nhc->save();
             }
         }
     }
 }
Example #5
0
 public function getShort($length = 150)
 {
     $npn = Npn::find()->where(['news_id' => $this->id])->orderBy(['pending_news_id' => SORT_DESC])->limit(1)->one();
     if ($pn = PendingNews::findOne($npn->pending_news_id)) {
         return html_entity_decode(mb_substr($pn->search_content, 0, $length, 'utf-8'));
     }
 }