diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-10-03 12:09:27 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-10-03 12:09:27 -0400 |
commit | d67d7c54e65e80d1b484490e42dbecb969aa7686 (patch) | |
tree | e62446885fac0d3af5b29d409d8e9a4f6c50940e /app/Schema/Mysql.php | |
parent | b5a2b8f9f7ac9ef947357acd3981993159d64b52 (diff) |
Add web notifications
Diffstat (limited to 'app/Schema/Mysql.php')
-rw-r--r-- | app/Schema/Mysql.php | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index a1cef344..92225279 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,44 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 88; +const VERSION = 89; + +function version_89($pdo) +{ + $pdo->exec(" + CREATE TABLE user_has_unread_notifications ( + id INT NOT NULL AUTO_INCREMENT, + user_id INT NOT NULL, + date_creation BIGINT NOT NULL, + event_name VARCHAR(50) NOT NULL, + event_data TEXT NOT NULL, + PRIMARY KEY(id), + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8 + "); + + $pdo->exec(" + CREATE TABLE user_has_notification_types ( + id INT NOT NULL AUTO_INCREMENT, + user_id INT NOT NULL, + notification_type VARCHAR(50), + PRIMARY KEY(id), + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8 + "); + + $pdo->exec('CREATE UNIQUE INDEX user_has_notification_types_user_idx ON user_has_notification_types(user_id, notification_type)'); + + // Migrate people who have notification enabled before + $rq = $pdo->prepare('SELECT id FROM users WHERE notifications_enabled=1'); + $rq->execute(); + $user_ids = $rq->fetchAll(PDO::FETCH_COLUMN, 0); + + foreach ($user_ids as $user_id) { + $rq = $pdo->prepare('INSERT INTO user_has_notification_types (user_id, notification_type) VALUES (?, ?)'); + $rq->execute(array($user_id, 'email')); + } +} function version_88($pdo) { |