From 6d573457dd22b65f4ce65b1b39786b62c9ba6181 Mon Sep 17 00:00:00 2001 From: Sergio Brighenti Date: Fri, 13 Mar 2020 19:44:42 +0100 Subject: [PATCH] Added tags tables Avoid long files name breaking the table --- app/Controllers/UserController.php | 1 - bin/migrate | 4 ++-- install/index.php | 4 +++- resources/schemas/mysql/mysql.6.sql | 18 ++++++++++++++++++ resources/schemas/sqlite/sqlite.6.sql | 20 ++++++++++++++++++++ resources/templates/dashboard/list.twig | 2 +- src/css/app.css | 13 +++++++++++++ 7 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 resources/schemas/mysql/mysql.6.sql create mode 100644 resources/schemas/sqlite/sqlite.6.sql diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index e6bac29..68f5478 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -219,7 +219,6 @@ class UserController extends Controller return redirect($response, route('user.index')); } - /** * @param Request $request * @param Response $response diff --git a/bin/migrate b/bin/migrate index bb0d2c6..bc24bb0 100644 --- a/bin/migrate +++ b/bin/migrate @@ -33,8 +33,8 @@ if (isset($argv[1]) && $argv[1] === '--install') { $db->query("INSERT INTO `users` (`email`, `username`, `password`, `is_admin`, `user_code`) VALUES ('admin@example.com', 'admin', ?, 1, ?)", [password_hash('admin', PASSWORD_DEFAULT), humanRandomString(5)]); } -if (file_exists(__DIR__.'/../install')) { - removeDirectory(__DIR__.'/../install'); +if (file_exists(__DIR__.'/../install') && (!isset($config['debug']) || !$config['debug'])) { + //removeDirectory(__DIR__.'/../install'); } echo 'If you are upgrading from a previous version, please run a "php bin\clean".'.PHP_EOL; diff --git a/install/index.php b/install/index.php index 84f1dc6..2538b7e 100644 --- a/install/index.php +++ b/install/index.php @@ -230,7 +230,9 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor cleanDirectory(__DIR__.'/../resources/cache'); cleanDirectory(__DIR__.'/../resources/sessions'); - removeDirectory(__DIR__.'/../install'); + if (!isset($config['debug']) || !$config['debug']) { + removeDirectory(__DIR__.'/../install'); + } // Installed successfully, destroy the installer session $session->destroy(); diff --git a/resources/schemas/mysql/mysql.6.sql b/resources/schemas/mysql/mysql.6.sql new file mode 100644 index 0000000..d81d58e --- /dev/null +++ b/resources/schemas/mysql/mysql.6.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS `tags` ( + `id` INTEGER PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(32) NOT NULL, + `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX (`name`) +); + +CREATE TABLE IF NOT EXISTS `uploads_tags` ( + `upload_id` INTEGER, + `tag_id` INTEGER, + PRIMARY KEY (`upload_id`, `tag_id`), + FOREIGN KEY (`upload_id`) REFERENCES `uploads` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE +); \ No newline at end of file diff --git a/resources/schemas/sqlite/sqlite.6.sql b/resources/schemas/sqlite/sqlite.6.sql new file mode 100644 index 0000000..0b5ba34 --- /dev/null +++ b/resources/schemas/sqlite/sqlite.6.sql @@ -0,0 +1,20 @@ +CREATE TABLE IF NOT EXISTS `tags` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` VARCHAR(32) NOT NULL, + `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE UNIQUE INDEX IF NOT EXISTS `tag_name` + ON `tags` (`name`); + +CREATE TABLE IF NOT EXISTS `uploads_tags` ( + `upload_id` INTEGER, + `tag_id` INTEGER, + PRIMARY KEY (`upload_id`, `tag_id`), + FOREIGN KEY (`upload_id`) REFERENCES `uploads` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE +); \ No newline at end of file diff --git a/resources/templates/dashboard/list.twig b/resources/templates/dashboard/list.twig index 60802a2..33cdda2 100644 --- a/resources/templates/dashboard/list.twig +++ b/resources/templates/dashboard/list.twig @@ -40,7 +40,7 @@ {% endif %} - {{ media.filename }} + {{ media.filename }} {{ media.size }} {% if media.published %} diff --git a/src/css/app.css b/src/css/app.css index 971e409..17eab59 100644 --- a/src/css/app.css +++ b/src/css/app.css @@ -130,3 +130,16 @@ body { .grecaptcha-badge { top: 5px !important; } + +.text-maxlen { + display: inline-block; + max-width: 330px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.text-maxlen:hover { + overflow: auto; + text-overflow: unset; +}