Esempio n. 1
0
 /**
  * @param array $source
  * @return array
  */
 protected function fetchSource(array $source)
 {
     $fetcher = new Fetcher();
     $fetcher->setClient(new Client());
     $fetcher->setTimeout($this->app->config('fetcher.timeout'));
     $content = $fetcher->get($source['uri']);
     if (!empty($content)) {
         $defaultWorkerClass = $this->app->config('worker.default');
         /**
          * @var $worker \Nogo\Feedbox\Feed\Worker
          */
         $worker = new $defaultWorkerClass();
         $worker->setSanitizer($this->sanitizer);
         $worker->setContent($content);
         try {
             $items = $worker->execute();
         } catch (\Exception $e) {
             $items = null;
         }
         if ($items != null) {
             foreach ($items as $item) {
                 if (isset($item['uid'])) {
                     $dbItem = $this->itemRepository->findBy('uid', $item['uid']);
                     if (!empty($dbItem)) {
                         if ($item['content'] !== $dbItem['content'] || $item['title'] !== $dbItem['title']) {
                             $item['id'] = $dbItem['id'];
                             $item['starred'] = $dbItem['starred'];
                             $item['created_at'] = $dbItem['created_at'];
                         } else {
                             continue;
                         }
                     }
                 }
                 $item['source_id'] = $source['id'];
                 $this->itemRepository->persist($item);
             }
         }
         $source['last_update'] = date('Y-m-d H:i:s');
         if (empty($source['period'])) {
             $source['period'] = $worker->getUpdateInterval();
         }
         $source['errors'] = $worker->getErrors();
     } else {
         $source['errors'] = $fetcher->getError();
     }
     $source['unread'] = $this->itemRepository->countSourceUnread([$source['id']]);
     $this->sourceRepository->persist($source);
     // update tag unread counter
     if (!empty($source['tag_id'])) {
         $tag = $this->tagRepository->find($source['tag_id']);
         if ($tag) {
             $tag['unread'] = $this->sourceRepository->countTagUnread([$tag['id']]);
             $this->tagRepository->persist($tag);
         }
     }
     // clean up double uids in this source
     $uids = $this->itemRepository->findDoubleUid($source['id']);
     foreach ($uids as $uid) {
         $items = $this->itemRepository->findAllBy('uid', $uid);
         for ($i = 1; $i < count($items); $i++) {
             $this->itemRepository->remove($items[$i]['id']);
         }
     }
     return $source;
 }
Esempio n. 2
0
                 break;
             default:
                 $format = false;
                 $period = 0;
         }
         if ($format && $interval->format($format) <= $period) {
             continue;
         }
     }
 }
 // set uri
 if ($config['debug']) {
     echo sprintf("Read source [%s]: ", $source['name']);
 }
 $items = null;
 $content = $fetcher->get($source['uri']);
 if (!empty($content)) {
     /**
      * @var $worker \Nogo\Feedbox\Feed\Worker
      */
     $worker = new $defaultWorkerClass();
     $worker->setSanitizer($sanitizer);
     $worker->setContent($content);
     try {
         $items = $worker->execute();
     } catch (\Exception $e) {
         $items = null;
         $error = true;
     }
     if (!$error && $items != null) {
         foreach ($items as $item) {