diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index efcf3bbb6..31ed68a49 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -54,6 +54,10 @@ class Application extends App { }); $container->registerMiddleware('SharingMiddleware'); + $container->registerService('databaseType', function($container) { + return $container->getServer()->getConfig()->getSystemValue('dbtype', 'sqlite'); + }); + // Delete user/group acl entries when they get deleted /** @var IUserManager $userManager */ $userManager = $server->getUserManager(); diff --git a/lib/Db/Card.php b/lib/Db/Card.php index 5680986d1..885339d74 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -43,6 +43,8 @@ class Card extends RelationalEntity implements JsonSerializable { protected $duedate = null; protected $notified = false; + private $databaseType = 'sqlite'; + const DUEDATE_FUTURE = 0; const DUEDATE_NEXT = 1; const DUEDATE_NOW = 2; @@ -60,10 +62,17 @@ class Card extends RelationalEntity implements JsonSerializable { $this->addResolvable('owner'); } - public function getDuedate() { + public function setDatabaseType($type) { + $this->databaseType = $type; + } + + public function getDuedate($isoFormat = false) { if($this->duedate === null) return null; $dt = new DateTime($this->duedate); + if (!$isoFormat && $this->databaseType === 'mysql') { + return $dt->format('Y-m-d H:i:s'); + } return $dt->format('c'); } @@ -93,7 +102,7 @@ class Card extends RelationalEntity implements JsonSerializable { $json['overdue'] = self::DUEDATE_OVERDUE; } } - $json['duedate'] = $this->getDuedate(); + $json['duedate'] = $this->getDuedate(true); unset($json['notified']); return $json; } diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index 64de8b55e..f509b3e89 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -37,26 +37,32 @@ class CardMapper extends DeckMapper implements IPermissionMapper { private $userManager; /** @var IManager */ private $notificationManager; + private $databaseType; public function __construct( IDBConnection $db, LabelMapper $labelMapper, IUserManager $userManager, - IManager $notificationManager + IManager $notificationManager, + $databaseType ) { parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card'); $this->labelMapper = $labelMapper; $this->userManager = $userManager; $this->notificationManager = $notificationManager; + $this->databaseType = $databaseType; } public function insert(Entity $entity) { + $entity->setDatabaseType($this->databaseType); $entity->setCreatedAt(time()); $entity->setLastModified(time()); return parent::insert($entity); } public function update(Entity $entity, $updateModified = true) { + $entity->setDatabaseType($this->databaseType); + if ($updateModified) $entity->setLastModified(time()); diff --git a/tests/unit/Db/CardTest.php b/tests/unit/Db/CardTest.php index 184c5b569..a81df4c2c 100644 --- a/tests/unit/Db/CardTest.php +++ b/tests/unit/Db/CardTest.php @@ -99,4 +99,11 @@ class CardTest extends \PHPUnit_Framework_TestCase { ], $card->jsonSerialize()); } + public function testMysqlDateFallback() { + $date = new DateTime(); + $card = new Card(); + $card->setDuedate($date->format('c')); + $card->setDatabaseType('mysql'); + $this->assertEquals($date->format('Y-m-d H:i:s'), $card->getDuedate(false)); + } } \ No newline at end of file