Ejemplo n.º 1
0
 /**
  * @param int $id
  * @param string $value
  * @return int
  */
 protected function updateValue($id, $value)
 {
     $config = new Config();
     $config->read($id);
     $config->value = $value;
     if ($config->save()) {
         $this->printLine("Key {$config->key}: {$value} has been updated!");
         return 0;
     }
     $this->printLine("Could not update the key {$config->key}: {$value}!");
     return 255;
 }
Ejemplo n.º 2
0
 public function edit($key)
 {
     $config = new Config();
     if (!$config->readKey($key)) {
         $this->app->render(404);
         return;
     }
     $config->setArray(json_decode($this->app->request()->getBody(), true));
     if ($config->save()) {
         $this->app->render(200, ['response' => $config->id]);
     } else {
         $this->app->render(500);
     }
 }
Ejemplo n.º 3
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!');
 }