Fix mysql datetime format

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-10-08 14:26:37 +02:00
committed by Julius Härtl
parent 1b0ac8c1e2
commit 05395dbfbe
4 changed files with 29 additions and 3 deletions

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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());

View File

@@ -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));
}
}