Example #1
0
 public function delete($key)
 {
     $config = new Config();
     if ($config->readKey($key)) {
         $id = $config->id;
         $this->app->render($config->delete() ? 200 : 500, ['response' => $id]);
     } else {
         $this->app->render(404);
     }
 }
Example #2
0
 /**
  * Upgrades the DB from Version 2 to 3.
  */
 protected function upgradeDb()
 {
     $this->printLine('Upgrading the DB…');
     $pdo = (new Icon())->getPdo();
     $sql = 'CREATE TABLE IF NOT EXISTS icon (
               id INTEGER PRIMARY KEY,
               inserted INTEGER NOT NULL,
               id_feed INTEGER UNIQUE,
               id_bookmark INTEGER UNIQUE,
               data BLOB NOT NULL,
               FOREIGN KEY (id_feed) REFERENCES feed(id) ON DELETE CASCADE
               FOREIGN KEY (id_bookmark) REFERENCES bookmark(id) ON DELETE CASCADE
             );
             CREATE INDEX IF NOT EXISTS fk_icon_id_feed ON icon (id_feed);
             CREATE INDEX IF NOT EXISTS fk_icon_id_bookmark ON icon (id_bookmark);';
     $pdo->exec($sql);
     $config = new Config();
     $config->readKey('database-version');
     $config->value = 3;
     $config->save();
     $this->printLine('DB upgraded to 3!');
 }
Example #3
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;
 }
Example #4
0
 /**
  * @param int $id
  * @return int
  */
 protected function deleteValue($id)
 {
     $config = new Config();
     $config->read($id);
     if ($config->delete()) {
         $this->printLine("Key with the id: {$id} has been deleted!");
         return 0;
     }
     $this->printLine("Could not delete the key with the id: {$id}!");
     return 255;
 }