diff --git a/lib/public/share.php b/lib/public/share.php index d33b16148d..6dbcd5b67b 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -827,11 +827,12 @@ 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, 'datetime'); foreach ($items as $item) { - $query->execute(array($date, $item['id'])); + $query->bindValue(2, (int) $item['id']); + $query->execute(); } return true; } @@ -847,7 +848,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; diff --git a/tests/lib/db.php b/tests/lib/db.php index c87bee4ab9..1977025cf1 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.' - ); - } }