From b48c716155d0d8770cf33dfab4077c4ef9591b21 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Thu, 10 Mar 2022 08:57:48 +0100 Subject: [PATCH] Add session table --- index.php | 4 ++-- src/pages/install.php | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index ddf3c4db..1d49e737 100644 --- a/index.php +++ b/index.php @@ -66,7 +66,7 @@ if (isset($api)) { /** * Install */ -if (!$options) { +if (!$options || !$options->getOption('isInstalled')) { $page = 'install'; } @@ -84,7 +84,7 @@ if ($options) { */ use Github\Client; -if ($options && !isset($_POST['install'])) { +if ($options && $options->getOption('isInstalled')) { $updateLastChecked = $options->getOption('updateLastChecked'); if (!$updateLastChecked || time() - $updateLastChecked >= 86400) { diff --git a/src/pages/install.php b/src/pages/install.php index 61046ea0..20cffb40 100644 --- a/src/pages/install.php +++ b/src/pages/install.php @@ -111,9 +111,12 @@ switch ($step) { break; case 3: + $database->query('SET foreign_key_checks = 0;'); + /** * Users */ + $database->query('DROP TABLE IF EXISTS `users`;'); $database->query('CREATE TABLE `users` ( `id` INT PRIMARY KEY AUTO_INCREMENT, `email` VARCHAR(64) NOT NULL UNIQUE, @@ -128,6 +131,7 @@ switch ($step) { /** * Wishlists */ + $database->query('DROP TABLE IF EXISTS `wishlists`;'); $database->query('CREATE TABLE `wishlists` ( `id` INT PRIMARY KEY AUTO_INCREMENT, `user` INT NOT NULL, @@ -142,6 +146,7 @@ switch ($step) { /** * Wishes */ + $database->query('DROP TABLE IF EXISTS `wishes`;'); $database->query('CREATE TABLE `wishes` ( `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, `wishlist` INT NOT NULL, @@ -149,7 +154,7 @@ switch ($step) { `description` TEXT NULL DEFAULT NULL, `image` VARCHAR(255) NULL DEFAULT NULL, `url` VARCHAR(255) NULL DEFAULT NULL, - `priority` TINEINT(1) NULL DEFAULT NULL, + `priority` TINYINT(1) NULL DEFAULT NULL, `status` VARCHAR(32) NULL DEFAULT NULL, FOREIGN KEY (`wishlist`) REFERENCES `wishlists` (`id`) @@ -160,6 +165,7 @@ switch ($step) { /** * Options */ + $database->query('DROP TABLE IF EXISTS `options`;'); $database->query('CREATE TABLE `options` ( `id` INT PRIMARY KEY AUTO_INCREMENT, `key` VARCHAR(64) NOT NULL UNIQUE, @@ -171,6 +177,22 @@ switch ($step) { ("isInstalled", true), ("version", "' . VERSION . '") ;'); + + /** + * Sessions + */ + $database->query('DROP TABLE IF EXISTS `sessions`;'); + $database->query('CREATE TABLE `sessions` ( + `id` INT PRIMARY KEY AUTO_INCREMENT, + `user` INT NOT NULL, + `session` VARCHAR(32) NOT NULL, + FOREIGN KEY (`user`) + REFERENCES `users` (`id`) + ON DELETE CASCADE + );'); + $database->query('CREATE INDEX `idx_user` ON `sessions` (`user`);'); + + $database->query('SET foreign_key_checks = 1;'); ?>