#37: Use public database interface; fixes graupel on ownCloud 9
authorChristian Weiske <cweiske@cweiske.de>
Fri, 18 Mar 2016 17:05:50 +0000 (18:05 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 18 Mar 2016 17:05:50 +0000 (18:05 +0100)
controller/apicontroller.php
lib/notestorage.php
lib/tokenstorage.php

index 90c036f39ae8c2a4091ecd0cc98dd4076f131575..23a47e796abc0fff201ccde79bb046561137edd0 100644 (file)
@@ -287,7 +287,8 @@ class ApiController extends Controller
         }
 
         //update
-        \OC_DB::beginTransaction();
+        $db = \OC::$server->getDatabaseConnection();
+        $db->beginTransaction();
         try {
             ++$syncdata->latestSyncRevision;
             foreach ($arPut['note-changes'] as $noteUpdate) {
@@ -306,9 +307,9 @@ class ApiController extends Controller
             }
 
             $this->notes->saveSyncData($syncdata);
-            \OC_DB::commit();
+            $db->commit();
         } catch (\DatabaseException $e) {
-            \OC_DB::getConnection()->rollBack();
+            $db->rollBack();
             throw $e;
         }
     }
index 27bb7025770f8327ea1059887978fc286d0a2da2..2ae9fcb405702a9728f63488b268fe5933ae56c2 100644 (file)
@@ -26,12 +26,18 @@ namespace OCA\Grauphel\Lib;
  */
 class NoteStorage
 {
+    /**
+     * @var \OCP\IDBConnection
+     */
+    protected $db;
+
     protected $urlGen;
     protected $username;
 
     public function __construct($urlGen)
     {
-        $this->urlGen   = $urlGen;
+        $this->urlGen = $urlGen;
+        $this->db     = \OC::$server->getDatabaseConnection();
     }
 
     public function setUsername($username)
@@ -54,14 +60,14 @@ class NoteStorage
 
     public function getTags()
     {
-        $result = \OC_DB::executeAudited(
+        $result = $this->db->executeQuery(
             'SELECT `note_tags` FROM `*PREFIX*grauphel_notes`'
             . ' WHERE note_user = ?',
             array($this->username)
         );
 
         $tags = array();
-        while ($row = $result->fetchRow()) {
+        while ($row = $result->fetch()) {
             $tags = array_merge($tags, json_decode($row['note_tags']));
         }
         return array_unique($tags);
@@ -131,11 +137,11 @@ class NoteStorage
      */
     public function loadSyncData()
     {
-        $row = \OC_DB::executeAudited(
+        $row = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_syncdata`'
             . ' WHERE `syncdata_user` = ?',
             array($this->username)
-        )->fetchRow();
+        )->fetch();
 
         if ($row === false) {
             $syncdata = $this->getNewSyncData();
@@ -158,11 +164,11 @@ class NoteStorage
      */
     public function saveSyncData(SyncData $syncdata)
     {
-        $row = \OC_DB::executeAudited(
+        $row = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_syncdata`'
             . ' WHERE `syncdata_user` = ?',
             array($this->username)
-        )->fetchRow();
+        )->fetch();
 
         if ($row === false) {
             //INSERT
@@ -186,7 +192,7 @@ class NoteStorage
             $params = array_values($data);
             $params[] = $this->username;
         }
-        \OC_DB::executeAudited($sql, $params);
+        $this->db->executeQuery($sql, $params);
     }
 
     /**
@@ -198,7 +204,7 @@ class NoteStorage
      */
     public function deleteSyncData()
     {
-        \OC_DB::executeAudited(
+        $this->db->executeQuery(
             'DELETE FROM `*PREFIX*grauphel_syncdata`'
             . ' WHERE `syncdata_user` = ?',
             array($this->username)
@@ -215,11 +221,11 @@ class NoteStorage
      */
     public function load($guid, $createNew = true)
     {
-        $row = \OC_DB::executeAudited(
+        $row = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_notes`'
             . ' WHERE `note_user` = ? AND `note_guid` = ?',
             array($this->username, $guid)
-        )->fetchRow();
+        )->fetch();
 
         if ($row === false) {
             if (!$createNew) {
@@ -258,11 +264,11 @@ class NoteStorage
      */
     public function loadGuidByTitle($title)
     {
-        $row = \OC_DB::executeAudited(
+        $row = $this->db->executeQuery(
             'SELECT note_guid FROM `*PREFIX*grauphel_notes`'
             . ' WHERE `note_user` = ? AND `note_title` = ?',
             array($this->username, htmlspecialchars($title))
-        )->fetchRow();
+        )->fetch();
 
         if ($row === false) {
             return null;
@@ -301,7 +307,7 @@ class NoteStorage
             }
         }
 
-        $result = \OC_DB::executeAudited(
+        $result = $this->db->executeQuery(
             'SELECT `note_guid`, `note_title`'
             . ' FROM `*PREFIX*grauphel_notes`'
             . ' WHERE note_user = ?'
@@ -311,7 +317,7 @@ class NoteStorage
         );
 
         $notes = array();
-        while ($row = $result->fetchRow()) {
+        while ($row = $result->fetch()) {
             $notes[] = $row;
         }
         return $notes;
@@ -326,11 +332,11 @@ class NoteStorage
      */
     public function save($note)
     {
-        $row = \OC_DB::executeAudited(
+        $row = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_notes`'
             . ' WHERE `note_user` = ? AND `note_guid` = ?',
             array($this->username, $note->guid)
-        )->fetchRow();
+        )->fetch();
 
         $data = $this->rowFromNote($note);
         if ($row === false) {
@@ -349,7 +355,7 @@ class NoteStorage
             $params[] = $this->username;
             $params[] = $note->guid;
         }
-        \OC_DB::executeAudited($sql, $params);
+        $this->db->executeQuery($sql, $params);
     }
 
     /**
@@ -361,7 +367,7 @@ class NoteStorage
      */
     public function delete($guid)
     {
-        \OC_DB::executeAudited(
+        $this->db->executeQuery(
             'DELETE FROM `*PREFIX*grauphel_notes`'
             . ' WHERE `note_user` = ? AND `note_guid` = ?',
             array($this->username, $guid)
@@ -375,7 +381,7 @@ class NoteStorage
      */
     public function deleteAll()
     {
-        \OC_DB::executeAudited(
+        $this->db->executeQuery(
             'DELETE FROM `*PREFIX*grauphel_notes`'
             . ' WHERE `note_user` = ?',
             array($this->username)
@@ -421,9 +427,9 @@ class NoteStorage
             $sql .= ' AND note_tags LIKE ?';
         }
 
-        $result = \OC_DB::executeAudited($sql, $sqlData);
+        $result = $this->db->executeQuery($sql, $sqlData);
         $notes = array();
-        while ($row = $result->fetchRow()) {
+        while ($row = $result->fetch()) {
             $note = array(
                 'guid' => $row['note_guid'],
                 'ref'  => array(
@@ -466,14 +472,14 @@ class NoteStorage
      */
     public function loadNotesFull($since = null)
     {
-        $result = \OC_DB::executeAudited(
+        $result = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_notes`'
             . ' WHERE note_user = ?',
             array($this->username)
         );
 
         $notes = array();
-        while ($row = $result->fetchRow()) {
+        while ($row = $result->fetch()) {
             if ($since !== null && $row['note_last_sync_revision'] <= $since) {
                 continue;
             }
index 92736cc2aa79f4243c8e1b125825807235916799..a184d8ef8ada9eda2ae586ec2d384f98c46a1025 100644 (file)
@@ -14,7 +14,7 @@
 namespace OCA\Grauphel\Lib;
 
 /**
- * Token store
+ * OAuth token store
  *
  * @category  Tools
  * @package   Grauphel
@@ -26,6 +26,16 @@ namespace OCA\Grauphel\Lib;
  */
 class TokenStorage
 {
+    /**
+     * @var \OCP\IDBConnection
+     */
+    protected $db;
+
+    public function __construct($urlGen)
+    {
+        $this->db = \OC::$server->getDatabaseConnection();
+    }
+
     /**
      * Delete token
      *
@@ -38,7 +48,7 @@ class TokenStorage
      */
     public function delete($type, $tokenKey)
     {
-        \OC_DB::executeAudited(
+        $this->db->executeQuery(
             'DELETE FROM `*PREFIX*grauphel_oauth_tokens`'
             . ' WHERE `token_key` = ? AND `token_type` = ?',
             array($tokenKey, $type)
@@ -54,7 +64,7 @@ class TokenStorage
      */
     public function store(Token $token)
     {
-        \OC_DB::executeAudited(
+        $this->db->executeQuery(
             'INSERT INTO `*PREFIX*grauphel_oauth_tokens`'
             . '(`token_user`, `token_type`, `token_key`, `token_secret`, `token_verifier`, `token_callback`, `token_client`, `token_lastuse`)'
             . ' VALUES(?, ?, ?, ?, ?, ?, ?, ?)',
@@ -105,11 +115,11 @@ class TokenStorage
      */
     public function load($type, $tokenKey)
     {
-        $tokenRow = \OC_DB::executeAudited(
+        $tokenRow = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_oauth_tokens`'
             . ' WHERE `token_key` = ? AND `token_type` = ?',
             array($tokenKey, $type)
-        )->fetchRow();
+        )->fetch();
 
         if ($tokenRow === false) {
             throw new OAuthException(
@@ -136,14 +146,14 @@ class TokenStorage
      */
     public function loadForUser($username, $type)
     {
-        $result = \OC_DB::executeAudited(
+        $result = $this->db->executeQuery(
             'SELECT * FROM `*PREFIX*grauphel_oauth_tokens`'
             . ' WHERE `token_user` = ? AND `token_type` = ?',
             array($username, $type)
         );
 
         $tokens = array();
-        while ($tokenRow = $result->fetchRow()) {
+        while ($tokenRow = $result->fetch()) {
             $tokens[] = $this->fromDb($tokenRow);
         }
 
@@ -159,7 +169,7 @@ class TokenStorage
      */
     public function updateLastUse($tokenKey)
     {
-        \OC_DB::executeAudited(
+        $this->db->executeQuery(
             'UPDATE `*PREFIX*grauphel_oauth_tokens`'
             . ' SET `token_lastuse` = ? WHERE `token_key` = ?',
             array(