From 9fb1da28110192422e7ca7ee8b0fe6996687d3c0 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 26 Nov 2013 11:50:14 +0100 Subject: Use bindValue() instead of passing parameters in execute(). --- lib/public/share.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/public/share.php b/lib/public/share.php index 6178a5ae043..e887740ac4c 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -826,8 +826,10 @@ class Share { $date = date('Y-m-d H:i', $date->format('U') - $date->getOffset()); } $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); + $query->bindValue(1, $date); foreach ($items as $item) { - $query->execute(array($date, $item['id'])); + $query->bindValue(2, (int) $item['id']); + $query->execute(); } return true; } -- cgit v1.2.3 From a330b2ef9b8f3e755be0260832ba8db01c62a515 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 26 Nov 2013 12:00:31 +0100 Subject: Use DateTime object instead of fixed format date string. Use a DateTime object and have conversion handled by Doctrine instead of using a date string with a fixed format. --- lib/public/share.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index e887740ac4c..708adba4237 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -823,10 +823,9 @@ class Share { $date = null; } else { $date = new \DateTime($date); - $date = date('Y-m-d H:i', $date->format('U') - $date->getOffset()); } $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); - $query->bindValue(1, $date); + $query->bindValue(1, $date, 'datetime'); foreach ($items as $item) { $query->bindValue(2, (int) $item['id']); $query->execute(); -- cgit v1.2.3 From 3bbaba1ecae1f5322fcc594d40d707edadc95446 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 26 Nov 2013 12:21:31 +0100 Subject: Use the Doctrine to convert date string to DateTime object. --- lib/public/share.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/public/share.php b/lib/public/share.php index 708adba4237..86b6cfa46ad 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -844,7 +844,8 @@ class Share { protected static function expireItem(array $item) { if (!empty($item['expiration'])) { $now = new \DateTime(); - $expirationDate = new \DateTime($item['expiration'], new \DateTimeZone('UTC')); + $expirationDate = \Doctrine\DBAL\Types\Type::getType('datetime') + ->convertToPhpValue($item['expiration'], \OC_DB::getConnection()->getDatabasePlatform()); if ($now > $expirationDate) { self::unshareItem($item); return true; -- cgit v1.2.3 From 06df3822a0c52c44df4d5c8cc99576f5ac15864f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 26 Nov 2013 12:22:08 +0100 Subject: Timestamp test is no longer necessary as we rely on Doctrine and DateTime. --- tests/lib/db.php | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/tests/lib/db.php b/tests/lib/db.php index c87bee4ab99..1977025cf12 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -145,42 +145,4 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertEquals(1, $result->numRows()); } - - /** - * Tests whether the database is configured so it accepts and returns dates - * in the expected format. - */ - public function testTimestampDateFormat() { - $table = '*PREFIX*'.$this->test_prefix.'timestamp'; - $column = 'timestamptest'; - - $expectedFormat = 'Y-m-d H:i:s'; - $expected = new \DateTime; - - $query = OC_DB::prepare("INSERT INTO `$table` (`$column`) VALUES (?)"); - $result = $query->execute(array($expected->format($expectedFormat))); - $this->assertEquals( - 1, - $result, - "Database failed to accept dates in the format '$expectedFormat'." - ); - - $id = OC_DB::insertid($table); - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `id` = ?"); - $result = $query->execute(array($id)); - $row = $result->fetchRow(); - - $actual = \DateTime::createFromFormat($expectedFormat, $row[$column]); - $this->assertInstanceOf( - '\DateTime', - $actual, - "Database failed to return dates in the format '$expectedFormat'." - ); - - $this->assertEquals( - $expected, - $actual, - 'Failed asserting that the returned date is the same as the inserted.' - ); - } } -- cgit v1.2.3