[Pkg-owncloud-commits] [php-sabredav] 16/40: Added a "tableName" member to the PDO Backend class for PropertyStorage.

David Prévot taffit at moszumanska.debian.org
Sat Sep 5 15:24:08 UTC 2015


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

taffit pushed a commit to tag 3.1.0-alpha2
in repository php-sabredav.

commit 5005d3cd9795a8853ea3474b4247efe31e2038bf
Author: François KUBLER <francois+github at kubler.org>
Date:   Sat Aug 1 23:24:26 2015 +0200

    Added a "tableName" member to the PDO Backend class for PropertyStorage.
    
    Also modified the methods of the class so that they use this new member.
    
    This allows to set your own table name for properties storage without rewriting everything.
---
 lib/DAV/PropertyStorage/Backend/PDO.php | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/DAV/PropertyStorage/Backend/PDO.php b/lib/DAV/PropertyStorage/Backend/PDO.php
index 25c2892..8c8e0ca 100644
--- a/lib/DAV/PropertyStorage/Backend/PDO.php
+++ b/lib/DAV/PropertyStorage/Backend/PDO.php
@@ -43,6 +43,13 @@ class PDO implements BackendInterface {
     protected $pdo;
 
     /**
+     * PDO table name we'll be using
+     *
+     * @var string
+     */
+    public $tableName = 'propertystorage';
+
+    /**
      * Creates the PDO property storage engine
      *
      * @param \PDO $pdo
@@ -76,7 +83,7 @@ class PDO implements BackendInterface {
             return;
         }
 
-        $query = 'SELECT name, value, valuetype FROM propertystorage WHERE path = ?';
+        $query = 'SELECT name, value, valuetype FROM ' . $this->tableName . ' WHERE path = ?';
         $stmt = $this->pdo->prepare($query);
         $stmt->execute([$path]);
 
@@ -114,8 +121,8 @@ class PDO implements BackendInterface {
 
         $propPatch->handleRemaining(function($properties) use ($path) {
 
-            $updateStmt = $this->pdo->prepare("REPLACE INTO propertystorage (path, name, valuetype, value) VALUES (?, ?, ?, ?)");
-            $deleteStmt = $this->pdo->prepare("DELETE FROM propertystorage WHERE path = ? AND name = ?");
+            $updateStmt = $this->pdo->prepare("REPLACE INTO " . $this->tableName . " (path, name, valuetype, value) VALUES (?, ?, ?, ?)");
+            $deleteStmt = $this->pdo->prepare("DELETE FROM " . $this->tableName . " WHERE path = ? AND name = ?");
 
             foreach ($properties as $name => $value) {
 
@@ -155,7 +162,7 @@ class PDO implements BackendInterface {
      */
     function delete($path) {
 
-        $stmt = $this->pdo->prepare("DELETE FROM propertystorage WHERE path = ? OR path LIKE ? ESCAPE '='");
+        $stmt = $this->pdo->prepare("DELETE FROM " . $this->tableName . "  WHERE path = ? OR path LIKE ? ESCAPE '='");
         $childPath = strtr(
             $path,
             [
@@ -186,10 +193,10 @@ class PDO implements BackendInterface {
         // also compatible across db engines, so we're letting PHP do all the
         // updates. Much slower, but it should still be pretty fast in most
         // cases.
-        $select = $this->pdo->prepare('SELECT id, path FROM propertystorage WHERE path = ? OR path LIKE ?');
+        $select = $this->pdo->prepare('SELECT id, path FROM ' . $this->tableName . '  WHERE path = ? OR path LIKE ?');
         $select->execute([$source, $source . '/%']);
 
-        $update = $this->pdo->prepare('UPDATE propertystorage SET path = ? WHERE id = ?');
+        $update = $this->pdo->prepare('UPDATE ' . $this->tableName . ' SET path = ? WHERE id = ?');
         while ($row = $select->fetch(\PDO::FETCH_ASSOC)) {
 
             // Sanity check. SQL may select too many records, such as records

-- 
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