Add web notifications

This commit is contained in:
Frederic Guillot
2015-10-03 12:09:27 -04:00
parent b5a2b8f9f7
commit d67d7c54e6
41 changed files with 1670 additions and 567 deletions

View File

@@ -6,7 +6,42 @@ use PDO;
use Core\Security;
use Model\Link;
const VERSION = 68;
const VERSION = 69;
function version_69($pdo)
{
$pdo->exec("
CREATE TABLE user_has_unread_notifications (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
date_creation BIGINT NOT NULL,
event_name VARCHAR(50) NOT NULL,
event_data TEXT NOT NULL,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
)
");
$pdo->exec("
CREATE TABLE user_has_notification_types (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
notification_type VARCHAR(50),
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
)
");
$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_68($pdo)
{