[Pkg-owncloud-commits] [php-sabredav] 13/66: Replaced hardcoded table names with class variables

David Prévot taffit at moszumanska.debian.org
Sat Jan 18 20:08:19 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 5fe14162bc9a7d12f35766470e50409897847fe2
Author: Jan Pieper <jan.pieper at adcloud.com>
Date:   Fri Nov 29 14:02:24 2013 +0100

    Replaced hardcoded table names with class variables
    
    * Added optional parameter $calendarSubscriptionsTableName to
      Sabre\CalDAV\Backend\PDO::__construct()
---
 lib/Sabre/CalDAV/Backend/PDO.php  | 24 +++++++++++++++++-------
 lib/Sabre/CardDAV/Backend/PDO.php |  6 +++---
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/Sabre/CalDAV/Backend/PDO.php b/lib/Sabre/CalDAV/Backend/PDO.php
index 0528134..514d102 100644
--- a/lib/Sabre/CalDAV/Backend/PDO.php
+++ b/lib/Sabre/CalDAV/Backend/PDO.php
@@ -59,6 +59,13 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
     protected $calendarChangesTableName;
 
     /**
+     * The table name that will be used for calendar subscriptions.
+     *
+     * @var string
+     */
+    protected $calendarSubscriptionsTableName;
+
+    /**
      * List of CalDAV properties, and how they map to database fieldnames
      * Add your own properties by simply adding on to this array.
      *
@@ -95,13 +102,16 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
      * @param \PDO $pdo
      * @param string $calendarTableName
      * @param string $calendarObjectTableName
+     * @param string $calendarChangesTableName
+     * @param string $calendarSubscriptionsTableName
      */
-    public function __construct(\PDO $pdo, $calendarTableName = 'calendars', $calendarObjectTableName = 'calendarobjects', $calendarChangesTableName = 'calendarchanges') {
+    public function __construct(\PDO $pdo, $calendarTableName = 'calendars', $calendarObjectTableName = 'calendarobjects', $calendarChangesTableName = 'calendarchanges', $calendarSubscriptionsTableName = 'calendarsubscriptions') {
 
         $this->pdo = $pdo;
         $this->calendarTableName = $calendarTableName;
         $this->calendarObjectTableName = $calendarObjectTableName;
         $this->calendarChangesTableName = $calendarChangesTableName;
+        $this->calendarSubscriptionsTableName = $calendarSubscriptionsTableName;
 
     }
 
@@ -835,7 +845,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
     public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) {
 
         // Current synctoken
-        $stmt = $this->pdo->prepare('SELECT synctoken FROM calendars WHERE id = ?');
+        $stmt = $this->pdo->prepare('SELECT synctoken FROM ' .$this->calendarTableName . ' WHERE id = ?');
         $stmt->execute([ $calendarId ]);
         $currentToken = $stmt->fetchColumn(0);
 
@@ -884,7 +894,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
             }
         } else {
             // No synctoken supplied, this is the initial sync.
-            $query = "SELECT uri FROM calendarobjects WHERE calendarid = ?";
+            $query = "SELECT uri FROM " . $this->calendarObjectTableName . " WHERE calendarid = ?";
             $stmt = $this->pdo->prepare($query);
             $stmt->execute([$calendarId]);
 
@@ -960,7 +970,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
 
         // Making fields a comma-delimited list
         $fields = implode(', ', $fields);
-        $stmt = $this->pdo->prepare("SELECT " . $fields . " FROM calendarsubscriptions WHERE principaluri = ? ORDER BY calendarorder ASC");
+        $stmt = $this->pdo->prepare("SELECT " . $fields . " FROM " . $this->calendarSubscriptionsTableName . " WHERE principaluri = ? ORDER BY calendarorder ASC");
         $stmt->execute([$principalUri]);
 
         $subscriptions = [];
@@ -1029,7 +1039,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
             }
         }
 
-        $stmt = $this->pdo->prepare("INSERT INTO calendarsubscriptions (".implode(', ', $fieldNames).") VALUES (".implode(', ',array_keys($values)).")");
+        $stmt = $this->pdo->prepare("INSERT INTO " . $this->calendarSubscriptionsTableName . " (".implode(', ', $fieldNames).") VALUES (".implode(', ',array_keys($values)).")");
         $stmt->execute($values);
 
         return $this->pdo->lastInsertId();
@@ -1127,7 +1137,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
             $valuesSql[] = $fieldName . ' = ?';
         }
 
-        $stmt = $this->pdo->prepare("UPDATE calendarsubscriptions SET " . implode(', ',$valuesSql) . ", lastmodified = ? WHERE id = ?");
+        $stmt = $this->pdo->prepare("UPDATE " . $this->calendarSubscriptionsTableName . " SET " . implode(', ',$valuesSql) . ", lastmodified = ? WHERE id = ?");
         $newValues['lastmodified'] = time();
         $newValues['id'] = $subscriptionId;
         $stmt->execute(array_values($newValues));
@@ -1144,7 +1154,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport {
      */
     public function deleteSubscription($subscriptionId) {
 
-        $stmt = $this->pdo->prepare('DELETE FROM calendarsubscriptions WHERE id = ?');
+        $stmt = $this->pdo->prepare('DELETE FROM ' . $this->calendarSubscriptionsTableName . ' WHERE id = ?');
         $stmt->execute([$subscriptionId]);
 
     }
diff --git a/lib/Sabre/CardDAV/Backend/PDO.php b/lib/Sabre/CardDAV/Backend/PDO.php
index 20c947b..30a0e7a 100644
--- a/lib/Sabre/CardDAV/Backend/PDO.php
+++ b/lib/Sabre/CardDAV/Backend/PDO.php
@@ -439,7 +439,7 @@ class PDO extends AbstractBackend implements SyncSupport {
     public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) {
 
         // Current synctoken
-        $stmt = $this->pdo->prepare('SELECT synctoken FROM addressbooks WHERE id = ?');
+        $stmt = $this->pdo->prepare('SELECT synctoken FROM ' . $this->addressBooksTableName . ' WHERE id = ?');
         $stmt->execute([ $addressBookId ]);
         $currentToken = $stmt->fetchColumn(0);
 
@@ -488,7 +488,7 @@ class PDO extends AbstractBackend implements SyncSupport {
             }
         } else {
             // No synctoken supplied, this is the initial sync.
-            $query = "SELECT uri FROM cards WHERE addressbookid = ?";
+            $query = "SELECT uri FROM " . $this->cardsTableName . " WHERE addressbookid = ?";
             $stmt = $this->pdo->prepare($query);
             $stmt->execute([$addressBookId]);
 
@@ -508,7 +508,7 @@ class PDO extends AbstractBackend implements SyncSupport {
      */
     protected function addChange($addressBookId, $objectUri, $operation) {
 
-        $stmt = $this->pdo->prepare('INSERT INTO ' . $this->addressBookChangesTableName .' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM addressbooks WHERE id = ?');
+        $stmt = $this->pdo->prepare('INSERT INTO ' . $this->addressBookChangesTableName .' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM ' . $this->addressBooksTableName . ' WHERE id = ?');
         $stmt->execute([
             $objectUri,
             $addressBookId,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list