Ejemplo n.º 1
0
 /**
  * POST /feed/item/queue/:id
  *
  * @param $id
  */
 public function enqueueItem($id)
 {
     $item = new Item();
     if (!$item->read($id)) {
         $this->app->render(404, ['response' => $id]);
         return;
     }
     if ((new ItemQueue())->enqueue($id)) {
         $this->app->render(201, ['response' => $id]);
     } else {
         $this->app->render(500);
     }
 }
Ejemplo n.º 2
0
 public function calculateUpdateInterval()
 {
     $min = new Config();
     $min->readKey('update-interval-min');
     $max = new Config();
     $max->readKey('update-interval-max');
     $item = new Item();
     foreach ((new Feed())->all() as $feed) {
         $itemCount = $item->count('id_feed = ?', [$feed->id]);
         $sth = $item->getPdo()->prepare('SELECT date FROM item WHERE id_feed = ? ORDER BY date DESC LIMIT ' . intval($itemCount / 3));
         $sth->execute([$feed->id]);
         $lastDate = time();
         $diffs = [];
         foreach ($sth->fetchAll(\PDO::FETCH_COLUMN) as $date) {
             if ($lastDate - $date > 0) {
                 $diffs[] = $lastDate - $date;
             }
             $lastDate = $date;
         }
         if (empty($diffs)) {
             continue;
         }
         rsort($diffs);
         $medMin = floor($diffs[intval(round(count($diffs) / 2)) - 1]);
         if ($medMin < $min->value) {
             $medMin = $min->value;
         } else {
             if ($medMin > $max->value) {
                 $medMin = $max->value;
             }
         }
         $feed->interval = $medMin;
         $feed->save();
     }
     return true;
 }