Skip to content

Commit 2ef74b9

Browse files
authored
Merge pull request #47329 from nextcloud/feat/add-datetime-qbmapper-support
feat(AppFramework): Add full support for date / time / datetime columns
2 parents 7e99fd3 + 0e54c2b commit 2ef74b9

File tree

29 files changed

+527
-146
lines changed

29 files changed

+527
-146
lines changed

apps/contactsinteraction/lib/Db/RecentContact.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\ContactsInteraction\Db;
1010

1111
use OCP\AppFramework\Db\Entity;
12+
use OCP\DB\Types;
1213

1314
/**
1415
* @method void setActorUid(string $uid)
@@ -33,11 +34,11 @@ class RecentContact extends Entity {
3334
protected int $lastContact = -1;
3435

3536
public function __construct() {
36-
$this->addType('actorUid', 'string');
37-
$this->addType('uid', 'string');
38-
$this->addType('email', 'string');
39-
$this->addType('federatedCloudId', 'string');
40-
$this->addType('card', 'blob');
41-
$this->addType('lastContact', 'int');
37+
$this->addType('actorUid', Types::STRING);
38+
$this->addType('uid', Types::STRING);
39+
$this->addType('email', Types::STRING);
40+
$this->addType('federatedCloudId', Types::STRING);
41+
$this->addType('card', Types::BLOB);
42+
$this->addType('lastContact', Types::INTEGER);
4243
}
4344
}

apps/dav/lib/CalDAV/Proxy/Proxy.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\DAV\CalDAV\Proxy;
1010

1111
use OCP\AppFramework\Db\Entity;
12+
use OCP\DB\Types;
1213

1314
/**
1415
* @method string getOwnerId()
@@ -28,8 +29,8 @@ class Proxy extends Entity {
2829
protected $permissions;
2930

3031
public function __construct() {
31-
$this->addType('ownerId', 'string');
32-
$this->addType('proxyId', 'string');
33-
$this->addType('permissions', 'int');
32+
$this->addType('ownerId', Types::STRING);
33+
$this->addType('proxyId', Types::STRING);
34+
$this->addType('permissions', Types::INTEGER);
3435
}
3536
}

apps/dav/lib/Db/Direct.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\DAV\Db;
1010

1111
use OCP\AppFramework\Db\Entity;
12+
use OCP\DB\Types;
1213

1314
/**
1415
* @method string getUserId()
@@ -34,9 +35,9 @@ class Direct extends Entity {
3435
protected $expiration;
3536

3637
public function __construct() {
37-
$this->addType('userId', 'string');
38-
$this->addType('fileId', 'int');
39-
$this->addType('token', 'string');
40-
$this->addType('expiration', 'int');
38+
$this->addType('userId', Types::STRING);
39+
$this->addType('fileId', Types::INTEGER);
40+
$this->addType('token', Types::STRING);
41+
$this->addType('expiration', Types::INTEGER);
4142
}
4243
}

apps/federatedfilesharing/lib/FederatedShareProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ui
303303
->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
304304
->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
305305
->setValue('permissions', $qb->createNamedParameter($permissions))
306-
->setValue('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATE))
306+
->setValue('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATETIME_MUTABLE))
307307
->setValue('token', $qb->createNamedParameter($token))
308308
->setValue('stime', $qb->createNamedParameter(time()));
309309

@@ -333,7 +333,7 @@ public function update(IShare $share) {
333333
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
334334
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
335335
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
336-
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
336+
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATETIME_MUTABLE))
337337
->executeStatement();
338338

339339
// send the updated permission to the owner/initiator, if they are not the same

apps/files_reminders/lib/Db/ReminderMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function findNotified(DateTime $buffer, ?int $limit = null) {
135135
$qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
136136
->from($this->getTableName())
137137
->where($qb->expr()->eq('notified', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
138-
->andWhere($qb->expr()->lt('due_date', $qb->createNamedParameter($buffer, IQueryBuilder::PARAM_DATE)))
138+
->andWhere($qb->expr()->lt('due_date', $qb->createNamedParameter($buffer, IQueryBuilder::PARAM_DATETIME_MUTABLE)))
139139
->orderBy('due_date', 'ASC')
140140
->setMaxResults($limit);
141141

apps/oauth2/lib/Db/AccessToken.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OCA\OAuth2\Db;
77

88
use OCP\AppFramework\Db\Entity;
9+
use OCP\DB\Types;
910

1011
/**
1112
* @method int getTokenId()
@@ -36,12 +37,12 @@ class AccessToken extends Entity {
3637
protected $tokenCount;
3738

3839
public function __construct() {
39-
$this->addType('id', 'int');
40-
$this->addType('tokenId', 'int');
41-
$this->addType('clientId', 'int');
40+
$this->addType('id', Types::INTEGER);
41+
$this->addType('tokenId', Types::INTEGER);
42+
$this->addType('clientId', Types::INTEGER);
4243
$this->addType('hashedCode', 'string');
4344
$this->addType('encryptedToken', 'string');
44-
$this->addType('codeCreatedAt', 'int');
45-
$this->addType('tokenCount', 'int');
45+
$this->addType('codeCreatedAt', Types::INTEGER);
46+
$this->addType('tokenCount', Types::INTEGER);
4647
}
4748
}

apps/oauth2/lib/Db/Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OCA\OAuth2\Db;
77

88
use OCP\AppFramework\Db\Entity;
9+
use OCP\DB\Types;
910

1011
/**
1112
* @method string getClientIdentifier()
@@ -28,7 +29,7 @@ class Client extends Entity {
2829
protected $secret;
2930

3031
public function __construct() {
31-
$this->addType('id', 'int');
32+
$this->addType('id', Types::INTEGER);
3233
$this->addType('name', 'string');
3334
$this->addType('redirectUri', 'string');
3435
$this->addType('clientIdentifier', 'string');

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ protected function addShareToDB(
699699
->setValue('permissions', $qb->createNamedParameter($permissions))
700700
->setValue('token', $qb->createNamedParameter($token))
701701
->setValue('password', $qb->createNamedParameter($password))
702-
->setValue('password_expiration_time', $qb->createNamedParameter($passwordExpirationTime, IQueryBuilder::PARAM_DATE))
702+
->setValue('password_expiration_time', $qb->createNamedParameter($passwordExpirationTime, IQueryBuilder::PARAM_DATETIME_MUTABLE))
703703
->setValue('password_by_talk', $qb->createNamedParameter($sendPasswordByTalk, IQueryBuilder::PARAM_BOOL))
704704
->setValue('stime', $qb->createNamedParameter(time()))
705705
->setValue('hide_download', $qb->createNamedParameter((int)$hideDownload, IQueryBuilder::PARAM_INT))
@@ -712,7 +712,7 @@ protected function addShareToDB(
712712

713713
$qb->setValue('attributes', $qb->createNamedParameter($shareAttributes));
714714
if ($expirationTime !== null) {
715-
$qb->setValue('expiration', $qb->createNamedParameter($expirationTime, IQueryBuilder::PARAM_DATE));
715+
$qb->setValue('expiration', $qb->createNamedParameter($expirationTime, IQueryBuilder::PARAM_DATETIME_MUTABLE));
716716
}
717717

718718
$qb->executeStatement();
@@ -752,10 +752,10 @@ public function update(IShare $share, ?string $plainTextPassword = null): IShare
752752
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
753753
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
754754
->set('password', $qb->createNamedParameter($share->getPassword()))
755-
->set('password_expiration_time', $qb->createNamedParameter($share->getPasswordExpirationTime(), IQueryBuilder::PARAM_DATE))
755+
->set('password_expiration_time', $qb->createNamedParameter($share->getPasswordExpirationTime(), IQueryBuilder::PARAM_DATETIME_MUTABLE))
756756
->set('label', $qb->createNamedParameter($share->getLabel()))
757757
->set('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL))
758-
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
758+
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATETIME_MUTABLE))
759759
->set('note', $qb->createNamedParameter($share->getNote()))
760760
->set('hide_download', $qb->createNamedParameter((int)$share->getHideDownload(), IQueryBuilder::PARAM_INT))
761761
->set('attributes', $qb->createNamedParameter($shareAttributes))

apps/user_status/lib/Db/UserStatus.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\UserStatus\Db;
1010

1111
use OCP\AppFramework\Db\Entity;
12+
use OCP\DB\Types;
1213

1314
/**
1415
* Class UserStatus
@@ -73,13 +74,13 @@ class UserStatus extends Entity {
7374
public function __construct() {
7475
$this->addType('userId', 'string');
7576
$this->addType('status', 'string');
76-
$this->addType('statusTimestamp', 'int');
77+
$this->addType('statusTimestamp', Types::INTEGER);
7778
$this->addType('isUserDefined', 'boolean');
7879
$this->addType('messageId', 'string');
7980
$this->addType('customIcon', 'string');
8081
$this->addType('customMessage', 'string');
81-
$this->addType('clearAt', 'int');
82+
$this->addType('clearAt', Types::INTEGER);
8283
$this->addType('isBackup', 'boolean');
83-
$this->addType('statusMessageTimestamp', 'int');
84+
$this->addType('statusMessageTimestamp', Types::INTEGER);
8485
}
8586
}

core/Db/LoginFlowV2.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OC\Core\Db;
1010

1111
use OCP\AppFramework\Db\Entity;
12+
use OCP\DB\Types;
1213

1314
/**
1415
* @method int getTimestamp()
@@ -55,8 +56,8 @@ class LoginFlowV2 extends Entity {
5556
protected $appPassword;
5657

5758
public function __construct() {
58-
$this->addType('timestamp', 'int');
59-
$this->addType('started', 'int');
59+
$this->addType('timestamp', Types::INTEGER);
60+
$this->addType('started', Types::INTEGER);
6061
$this->addType('pollToken', 'string');
6162
$this->addType('loginToken', 'string');
6263
$this->addType('publicKey', 'string');

0 commit comments

Comments
 (0)