[Pkg-owncloud-commits] [php-sabredav] 185/220: Postgres support for propertystorage
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit b56a649e629b6a0a14ef14d3ddd10cc0c02a63a6
Author: Evert Pot <me at evertpot.com>
Date: Thu Apr 28 13:02:58 2016 +0700
Postgres support for propertystorage
---
examples/sql/pgsql.addressbook.sql | 2 +-
examples/sql/pgsql.calendars.sql | 2 +-
examples/sql/pgsql.propertystorage.sql | 2 +-
lib/DAV/PropertyStorage/Backend/PDO.php | 33 ++++++++++++++++++++--
tests/Sabre/DAV/Auth/Backend/PDOPgSqlTest.php | 4 +--
.../DAV/PropertyStorage/Backend/PDOPgSqlTest.php | 32 +++++++++++++++++++++
tests/bootstrap.php | 4 +--
7 files changed, 70 insertions(+), 9 deletions(-)
diff --git a/examples/sql/pgsql.addressbook.sql b/examples/sql/pgsql.addressbook.sql
index ef2cc5b..48a7365 100644
--- a/examples/sql/pgsql.addressbook.sql
+++ b/examples/sql/pgsql.addressbook.sql
@@ -16,7 +16,7 @@ CREATE UNIQUE INDEX addressbooks_ukey
CREATE TABLE cards (
id SERIAL NOT NULL,
addressbookid INTEGER NOT NULL,
- carddata TEXT,
+ carddata BYTEA,
uri VARCHAR(200),
lastmodified INTEGER,
etag VARCHAR(32),
diff --git a/examples/sql/pgsql.calendars.sql b/examples/sql/pgsql.calendars.sql
index 87bad72..6d898d1 100644
--- a/examples/sql/pgsql.calendars.sql
+++ b/examples/sql/pgsql.calendars.sql
@@ -21,7 +21,7 @@ CREATE UNIQUE INDEX calendars_ukey
CREATE TABLE calendarobjects (
id SERIAL NOT NULL,
- calendardata TEXT,
+ calendardata BYTEA,
uri VARCHAR(200),
calendarid INTEGER NOT NULL,
lastmodified INTEGER,
diff --git a/examples/sql/pgsql.propertystorage.sql b/examples/sql/pgsql.propertystorage.sql
index 1642e22..d1463fa 100644
--- a/examples/sql/pgsql.propertystorage.sql
+++ b/examples/sql/pgsql.propertystorage.sql
@@ -3,7 +3,7 @@ CREATE TABLE propertystorage (
path VARCHAR(1024) NOT NULL,
name VARCHAR(100) NOT NULL,
valuetype INT,
- value TEXT
+ value BYTEA
);
ALTER TABLE ONLY propertystorage
diff --git a/lib/DAV/PropertyStorage/Backend/PDO.php b/lib/DAV/PropertyStorage/Backend/PDO.php
index 910e497..2fe8438 100644
--- a/lib/DAV/PropertyStorage/Backend/PDO.php
+++ b/lib/DAV/PropertyStorage/Backend/PDO.php
@@ -88,6 +88,9 @@ class PDO implements BackendInterface {
$stmt->execute([$path]);
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ if (gettype($row['value']) === 'resource') {
+ $row['value'] = stream_get_contents($row['value']);
+ }
switch ($row['valuetype']) {
case null :
case self::VT_STRING :
@@ -121,7 +124,26 @@ class PDO implements BackendInterface {
$propPatch->handleRemaining(function($properties) use ($path) {
- $updateStmt = $this->pdo->prepare("REPLACE INTO " . $this->tableName . " (path, name, valuetype, value) VALUES (?, ?, ?, ?)");
+
+ if ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'pgsql') {
+
+ $updateSql = <<<SQL
+INSERT INTO {$this->tableName} (path, name, valuetype, value)
+VALUES (:path, :name, :valuetype, :value)
+ON CONFLICT (path, name)
+DO UPDATE SET valuetype = :valuetype, value = :value
+SQL;
+
+
+ } else {
+ $updateSql = <<<SQL
+REPLACE INTO {$this->tableName} (path, name, valuetype, value)
+VALUES (:path, :name, :valuetype, :value)
+SQL;
+
+ }
+
+ $updateStmt = $this->pdo->prepare($updateSql);
$deleteStmt = $this->pdo->prepare("DELETE FROM " . $this->tableName . " WHERE path = ? AND name = ?");
foreach ($properties as $name => $value) {
@@ -136,7 +158,14 @@ class PDO implements BackendInterface {
$valueType = self::VT_OBJECT;
$value = serialize($value);
}
- $updateStmt->execute([$path, $name, $valueType, $value]);
+
+ $updateStmt->bindParam('path', $path, \PDO::PARAM_STR);
+ $updateStmt->bindParam('name', $name, \PDO::PARAM_STR);
+ $updateStmt->bindParam('valuetype', $valueType, \PDO::PARAM_INT);
+ $updateStmt->bindParam('value', $value, \PDO::PARAM_LOB);
+
+ $updateStmt->execute();
+
} else {
$deleteStmt->execute([$path, $name]);
}
diff --git a/tests/Sabre/DAV/Auth/Backend/PDOPgSqlTest.php b/tests/Sabre/DAV/Auth/Backend/PDOPgSqlTest.php
index 8bee7b9..a6fd70c 100644
--- a/tests/Sabre/DAV/Auth/Backend/PDOPgSqlTest.php
+++ b/tests/Sabre/DAV/Auth/Backend/PDOPgSqlTest.php
@@ -13,8 +13,8 @@ class PDOPgSqlTest extends AbstractPDOTest {
$sql = file_get_contents(__DIR__ . '/../../../../../examples/sql/pgsql.users.sql');
$pdo->query("DROP TABLE IF EXISTS users");
- foreach(explode(';', $sql) as $statement) {
- if(trim($statement) === '') continue;;
+ foreach (explode(';', $sql) as $statement) {
+ if (trim($statement) === '') continue;
$pdo->query($statement); // Yup
}
$pdo->query("INSERT INTO users (username,digesta1) VALUES ('user','hash')");
diff --git a/tests/Sabre/DAV/PropertyStorage/Backend/PDOPgSqlTest.php b/tests/Sabre/DAV/PropertyStorage/Backend/PDOPgSqlTest.php
new file mode 100644
index 0000000..a579b9c
--- /dev/null
+++ b/tests/Sabre/DAV/PropertyStorage/Backend/PDOPgSqlTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Sabre\DAV\PropertyStorage\Backend;
+
+class PDOPgSqlTest extends AbstractPDOTest {
+
+ function getPDO() {
+
+ if (!SABRE_HASPGSQL) $this->markTestSkipped('PGSQL driver is not available, or not properly configured');
+ $pdo = \Sabre\TestUtil::getPgSqlDB();
+ if (!$pdo) $this->markTestSkipped('Pos is not enabled');
+
+
+ $setupSql = file_get_contents(__DIR__ . '/../../../../../examples/sql/pgsql.propertystorage.sql');
+ // Sloppy multi-query, but it works
+ $setupSql = explode(';', $setupSql);
+
+ $pdo->exec('DROP TABLE IF EXISTS propertystorage');
+
+ foreach ($setupSql as $sql) {
+
+ if (!trim($sql)) continue;
+ $pdo->exec($sql);
+
+ }
+ $pdo->exec("INSERT INTO propertystorage (path, name, value, valuetype) VALUES ('dir', '{DAV:}displayname', 'Directory', 1)");
+
+ return $pdo;
+
+ }
+
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 1d9a242..27c1941 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -17,8 +17,8 @@ $config = [
'SABRE_HASSQLITE' => in_array('sqlite', PDO::getAvailableDrivers()),
'SABRE_HASMYSQL' => in_array('mysql', PDO::getAvailableDrivers()),
'SABRE_HASPGSQL' => in_array('pgsql', PDO::getAvailableDrivers()),
- 'SABRE_MYSQLDSN' => 'mysql:host=127.0.0.1;dbname=sabredav',
- 'SABRE_MYSQLUSER' => 'root',
+ 'SABRE_MYSQLDSN' => 'mysql:host=127.0.0.1;dbname=sabredav_test',
+ 'SABRE_MYSQLUSER' => 'sabredav',
'SABRE_MYSQLPASS' => '',
'SABRE_PGSQLDSN' => 'pgsql:host=localhost;dbname=sabredav;user=sabredav;password=sabredav',
];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list