Added tags tables

Avoid long files name breaking the table
This commit is contained in:
Sergio Brighenti 2020-03-13 19:44:42 +01:00
parent d8a5e28577
commit 6d573457dd
7 changed files with 57 additions and 5 deletions

View file

@ -219,7 +219,6 @@ class UserController extends Controller
return redirect($response, route('user.index'));
}
/**
* @param Request $request
* @param Response $response

View file

@ -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;

View file

@ -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();

View file

@ -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
);

View file

@ -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
);

View file

@ -40,7 +40,7 @@
<i class="far {{ mime2font(media.mimetype) }} fa-2x"></i>
{% endif %}
</td>
<td>{{ media.filename }}</td>
<td><span class="text-maxlen">{{ media.filename }}</span></td>
<td>{{ media.size }}</td>
<td id="published_{{ media.id }}">
{% if media.published %}

View file

@ -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;
}