Skip to content

Commit e16001b

Browse files
committed
feat: init files_reminders migration
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 9a7e2b1 commit e16001b

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
!/apps/sharebymail
2525
!/apps/encryption
2626
!/apps/files_external
27+
!/apps/files_reminders
2728
!/apps/files_sharing
2829
!/apps/files_trashbin
2930
!/apps/files_versions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
7+
*
8+
* @author Christopher Ng <chrng8@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\FilesReminders\Db;
28+
29+
use OCP\AppFramework\Db\Entity;
30+
31+
/**
32+
* @method void setUserId(string $userId)
33+
* @method string getUserId()
34+
*
35+
* @method void setFileId(int $fileId)
36+
* @method int getFileId()
37+
*
38+
* @method void setRemindAt(int $remindAt)
39+
* @method int getRemindAt()
40+
*
41+
* @method void setNotified(bool $notified)
42+
* @method bool getNotified()
43+
*/
44+
class Reminder extends Entity {
45+
protected string $userId;
46+
protected int $fileId;
47+
protected int $remindAt;
48+
protected bool $notified = false;
49+
50+
public function __construct() {
51+
$this->addType('userId', 'string');
52+
$this->addType('fileId', 'integer');
53+
$this->addType('remindAt', 'integer');
54+
$this->addType('notified', 'boolean');
55+
}
56+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
7+
*
8+
* @author Christopher Ng <chrng8@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\FilesReminders\Db;
28+
29+
use OCP\AppFramework\Db\QBMapper;
30+
use OCP\DB\QueryBuilder\IQueryBuilder;
31+
use OCP\IDBConnection;
32+
33+
/**
34+
* @template-extends QBMapper<Reminder>
35+
*/
36+
class ReminderMapper extends QBMapper {
37+
public const TABLE_NAME = 'files_reminders';
38+
39+
public function __construct(IDBConnection $db) {
40+
parent::__construct(
41+
$db,
42+
static::TABLE_NAME,
43+
Reminder::class,
44+
);
45+
}
46+
47+
public function markNotified(Reminder $reminder): Reminder {
48+
$reminderUpdate = new Reminder();
49+
$reminderUpdate->setId($reminder->getId());
50+
$reminderUpdate->setNotified(true);
51+
return parent::update($reminderUpdate);
52+
}
53+
54+
/**
55+
* @return Reminder[]
56+
*/
57+
public function findToRemind() {
58+
$qb = $this->db->getQueryBuilder();
59+
60+
$qb->select('user_id', 'file_id', 'remind_at')
61+
->from($this->getTableName())
62+
->where($qb->expr()->lt('remind_at', $qb->createFunction('NOW()')))
63+
->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)));
64+
65+
return $this->findEntities($qb);
66+
}
67+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
7+
*
8+
* @author Christopher Ng <chrng8@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\FilesReminders\Migration;
28+
29+
use Closure;
30+
use OCA\FilesReminders\Db\ReminderMapper;
31+
use OCP\DB\ISchemaWrapper;
32+
use OCP\DB\Types;
33+
use OCP\Migration\IOutput;
34+
use OCP\Migration\SimpleMigrationStep;
35+
36+
class Version10000Date20230725162149 extends SimpleMigrationStep {
37+
/**
38+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39+
*/
40+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
41+
/** @var ISchemaWrapper $schema */
42+
$schema = $schemaClosure();
43+
44+
$table = $schema->createTable(ReminderMapper::TABLE_NAME);
45+
$table->addColumn('id', Types::BIGINT, [
46+
'autoincrement' => true,
47+
'notnull' => true,
48+
'length' => 20,
49+
'unsigned' => true,
50+
]);
51+
$table->addColumn('user_id', Types::STRING, [
52+
'notnull' => true,
53+
'length' => 64,
54+
]);
55+
$table->addColumn('file_id', Types::BIGINT, [
56+
'notnull' => true,
57+
'length' => 20,
58+
]);
59+
$table->addColumn('remind_at', Types::BIGINT, [
60+
'notnull' => true,
61+
]);
62+
$table->addColumn('notified', Types::BOOLEAN, [
63+
'notnull' => false,
64+
'default' => false,
65+
]);
66+
$table->setPrimaryKey(['id']);
67+
$table->addUniqueIndex(['user_id', 'file_id', 'remind_at'], 'reminders_uniq_idx');
68+
69+
return $schema;
70+
}
71+
}

0 commit comments

Comments
 (0)