/**
  * Save a chartconfig entity to the database
  *
  * @param ChartConfig $config
  * @return boolean
  */
 public function save(ChartConfig $config)
 {
     $id = $config->getId();
     if (!empty($id)) {
         $query = $this->db->prepareQuery('UPDATE *PREFIX*uc_chartconfig SET created = ?, username = ?, charttype = ?, chartprovider = ?, metadata = ? WHERE id = ?');
         $query->execute(array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider(), $config->getMetaData(), $config->getId()));
     } else {
         $query = $this->db->prepareQuery('INSERT INTO *PREFIX*uc_chartconfig(created, username, charttype, chartprovider, metadata) VALUES (?,?,?,?,?)');
         $query->execute(array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider(), $config->getMetaData()));
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Checks if a backup can be restored
  *
  * @depends testBackup
  */
 public function testRestore()
 {
     $timestampList = $this->backupService->fetchBackupTimestamps();
     $this->assertEquals(1, count($timestampList));
     // drop table
     $this->db->dropTable(self::TEST_TABLE_NO_PREFIX);
     // check if table is gone
     $tableExists = $this->db->tableExists(self::TEST_TABLE_NO_PREFIX);
     $this->assertFalse($tableExists);
     // restore table
     $timestamp = $timestampList[0];
     $tableList = [self::TEST_TABLE];
     $this->backupService->doRestoreTables($timestamp, $tableList);
     // check if table is present again
     $tableExists = $this->db->tableExists(self::TEST_TABLE_NO_PREFIX);
     $this->assertTrue($tableExists);
     // test if 0 timestamp is handled
     $result = $this->backupService->doRestoreTables(0, $tableList);
     $this->assertFalse($result);
     // test if 0 timestamp is handled
     $result = $this->backupService->doRestoreTable(0, self::TEST_TABLE);
     $this->assertFalse($result);
 }
 /**
  * @return array
  */
 public function findAllPerMonth()
 {
     $sql = 'SELECT DISTINCT CONCAT(MONTH(`created`), \' \', YEAR(`created`)) as month, avg(`usage`) as average, username FROM oc_uc_storageusage WHERE `usage` > 0 GROUP BY username, month';
     $query = $this->db->prepareQuery($sql);
     $result = $query->execute();
     $entities = array();
     while ($row = $result->fetch()) {
         if (!isset($entities[$row['username']])) {
             $entities[$row['username']] = array();
         }
         $date = explode(' ', $row['month']);
         $dateTime = new \Datetime();
         $dateTime->setDate($date[1], $date[0], 1);
         $entities[$row['username']] = array_merge($entities[$row['username']], array(new StorageUsage($dateTime, $row['average'], $row['username'])));
     }
     return $entities;
 }
 /**
  * Save a chartconfig entity to the database
  *
  * @param ChartConfig $config
  */
 public function save(ChartConfig $config)
 {
     $query = $this->db->prepareQuery('INSERT INTO oc_uc_chartconfig(created, username, charttype, chartprovider) VALUES (?,?,?,?)');
     $query->execute(Array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider()));
 }
Esempio n. 5
0
 /**
  * @brief Add a set of tags for a bookmark
  * @param IDb $db Database Interface
  * @param int $bookmarkID The bookmark reference
  * @param array $tags Set of tags to add to the bookmark
  * @return null
  * */
 private static function addTags(IDb $db, $bookmarkID, $tags)
 {
     $sql = 'INSERT INTO `*PREFIX*bookmarks_tags` (`bookmark_id`, `tag`) select ?, ? ';
     $dbtype = \OCP\Config::getSystemValue('dbtype', 'sqlite');
     if ($dbtype === 'mysql') {
         $sql .= 'from dual ';
     }
     $sql .= 'where not exists(select * from `*PREFIX*bookmarks_tags` where `bookmark_id` = ? and `tag` = ?)';
     $query = $db->prepareQuery($sql);
     foreach ($tags as $tag) {
         $tag = trim($tag);
         if (empty($tag)) {
             //avoid saving white spaces
             continue;
         }
         $params = array($bookmarkID, $tag, $bookmarkID, $tag);
         $query->execute($params);
     }
 }