mirror of
https://github.com/chevereto/chevereto.git
synced 2025-10-26 07:46:18 +01:00
mysql support for tags
This commit is contained in:
@@ -224,6 +224,8 @@ class Image
|
||||
if ($requester !== []) {
|
||||
$image_db['image_liked'] = (bool) $image_db['like_user_id'];
|
||||
}
|
||||
$image_tags = [];
|
||||
$image_tags_string = '';
|
||||
if (version_compare(cheveretoVersionInstalled(), '4.2.0', '>=')) {
|
||||
$tagsFilesTable = $tables['tags_files'];
|
||||
$tagsTable = $tables['tags'];
|
||||
@@ -238,13 +240,14 @@ class Image
|
||||
$db = DB::getInstance();
|
||||
$db->query($tagsSql);
|
||||
$db->bind(':image_id', $id);
|
||||
$image_tags = $db->fetchAll();
|
||||
$image_tags = $db->fetchAll() ?: [];
|
||||
foreach ($image_tags as $k => $v) {
|
||||
$image_tags[$k] = Tag::row($v['name']);
|
||||
}
|
||||
$image_db['image_tags'] = $image_tags;
|
||||
$image_db['image_tags_string'] = implode(', ', array_column($image_tags, 'name'));
|
||||
$image_tags_string = implode(', ', array_column($image_tags, 'name'));
|
||||
}
|
||||
$image_db['image_tags'] = $image_tags;
|
||||
$image_db['image_tags_string'] = $image_tags_string;
|
||||
$return = $image_db;
|
||||
$return = $pretty ? self::formatArray($return) : $return;
|
||||
if (! isset($return['file_resource'])) {
|
||||
@@ -1376,13 +1379,12 @@ class Image
|
||||
WHERE `tag_user_user_id` = :user_id
|
||||
AND FIND_IN_SET(`tag_user_tag_id`, @TAGS_IDS);
|
||||
|
||||
IF (@ALBUM_ID IS NOT NULL)
|
||||
THEN
|
||||
UPDATE `{$tagsAlbumsTable}` SET `tag_album_count` = `tag_album_count` - 1
|
||||
WHERE `tag_album_album_id` = @ALBUM_ID
|
||||
AND `tag_album_user_id` = :user_id
|
||||
AND FIND_IN_SET(`tag_album_tag_id`, @TAGS_IDS);
|
||||
END IF;
|
||||
UPDATE `{$tagsAlbumsTable}`
|
||||
SET `tag_album_count` = `tag_album_count` - 1
|
||||
WHERE `tag_album_album_id` = @ALBUM_ID
|
||||
AND `tag_album_user_id` = :user_id
|
||||
AND FIND_IN_SET(`tag_album_tag_id`, @TAGS_IDS)
|
||||
AND @ALBUM_ID IS NOT NULL;
|
||||
|
||||
UPDATE `{$tagsTable}` SET `tag_files` = `tag_files` - 1
|
||||
WHERE FIND_IN_SET(`tag_id`, @TAGS_IDS);
|
||||
@@ -1409,12 +1411,10 @@ class Image
|
||||
VALUES (@TAG_ID, :user_id, 1)
|
||||
ON DUPLICATE KEY UPDATE `tag_user_count` = `tag_user_count` + 1;
|
||||
|
||||
IF (@ALBUM_ID IS NOT NULL)
|
||||
THEN
|
||||
INSERT INTO `{$tagsAlbumsTable}` (`tag_album_tag_id`, `tag_album_album_id`, `tag_album_user_id`, `tag_album_count`)
|
||||
VALUES (@TAG_ID, @ALBUM_ID, :user_id, 1)
|
||||
ON DUPLICATE KEY UPDATE `tag_album_count` = `tag_album_count` + 1;
|
||||
END IF;
|
||||
INSERT INTO `{$tagsAlbumsTable}` (`tag_album_tag_id`, `tag_album_album_id`, `tag_album_user_id`, `tag_album_count`)
|
||||
SELECT @TAG_ID, @ALBUM_ID, :user_id, 1
|
||||
WHERE @ALBUM_ID IS NOT NULL
|
||||
ON DUPLICATE KEY UPDATE `tag_album_count` = `tag_album_count` + 1;
|
||||
|
||||
UPDATE `{$tagsTable}` SET `tag_files` = `tag_files` + 1
|
||||
WHERE `tag_id` = @TAG_ID;
|
||||
|
||||
@@ -1148,7 +1148,8 @@ class Listing
|
||||
FROM `{$tagsFilesTable}` tf
|
||||
LEFT JOIN `{$filesTable}` files ON tf.tag_file_file_id = files.image_id
|
||||
LEFT JOIN `{$tagsTable}` tags ON tf.tag_file_tag_id = tags.tag_id
|
||||
WHERE tf.tag_file_file_id IN ({$inFiles});
|
||||
WHERE tf.tag_file_file_id IN ({$inFiles})
|
||||
AND tags.tag_name IS NOT NULL;
|
||||
|
||||
MySQL;
|
||||
$fetchTags = DB::queryFetchAll($tagsSQL);
|
||||
@@ -1167,6 +1168,7 @@ class Listing
|
||||
$fileToTags[$fileId][] = $tag;
|
||||
}
|
||||
}
|
||||
/** @var callable $tagFn */
|
||||
$tagFn = require_theme_file_return('snippets/tag');
|
||||
$items = [];
|
||||
foreach ($this->output as $pos => &$row) {
|
||||
|
||||
@@ -17,7 +17,6 @@ use PDO;
|
||||
use function Chevereto\Legacy\assertNotStopWords;
|
||||
use function Chevereto\Legacy\G\get_base_url;
|
||||
use function Chevereto\Legacy\G\safe_html;
|
||||
use function Chevereto\Legacy\strip_tags_content;
|
||||
use function Chevereto\Vars\env;
|
||||
|
||||
/**
|
||||
@@ -197,15 +196,19 @@ final class Tag
|
||||
NULL,
|
||||
@TRY_TAG
|
||||
);
|
||||
IF (@MISSING IS NOT NULL)
|
||||
THEN
|
||||
INSERT INTO `{$tagsTable}` (`tag_name`, `tag_user_id`)
|
||||
VALUES (@MISSING, :tag_user_id);
|
||||
UPDATE `{$statsTable}` SET stat_tags = stat_tags + 1 WHERE stat_type = "total";
|
||||
INSERT `{$statsTable}` (stat_type, stat_date_gmt, stat_tags)
|
||||
VALUES ("date", DATE(CURRENT_TIMESTAMP), 1)
|
||||
ON DUPLICATE KEY UPDATE stat_tags = stat_tags + 1;
|
||||
END IF;
|
||||
INSERT INTO `{$tagsTable}` (`tag_name`, `tag_user_id`)
|
||||
SELECT @MISSING, :tag_user_id
|
||||
WHERE @MISSING IS NOT NULL;
|
||||
|
||||
UPDATE `{$statsTable}`
|
||||
SET stat_tags = stat_tags + 1
|
||||
WHERE stat_type = "total"
|
||||
AND @MISSING IS NOT NULL;
|
||||
|
||||
INSERT INTO `{$statsTable}` (stat_type, stat_date_gmt, stat_tags)
|
||||
SELECT "date", DATE(CURRENT_TIMESTAMP), 1
|
||||
WHERE @MISSING IS NOT NULL
|
||||
ON DUPLICATE KEY UPDATE stat_tags = stat_tags + 1;
|
||||
|
||||
MySQL;
|
||||
foreach ($tag as $pos => $name) {
|
||||
@@ -298,14 +301,19 @@ final class Tag
|
||||
foreach ($id as $tagId) {
|
||||
$sql .= <<<MySQL
|
||||
SET @DATE = (SELECT DATE(`tag_date_gmt`) FROM `{$tagsTable}` WHERE `tag_id` = {$tagId});
|
||||
IF (@DATE IS NOT NULL)
|
||||
THEN
|
||||
DELETE FROM `{$tagsTable}` WHERE `tag_id` = {$tagId};
|
||||
SET @ROW_COUNT = ROW_COUNT();
|
||||
SET @DELETE_COUNT = @DELETE_COUNT + @ROW_COUNT;
|
||||
UPDATE `{$statsTable}` SET stat_tags = GREATEST(GREATEST(0, stat_tags) - @ROW_COUNT, 0)
|
||||
WHERE stat_type = "date" AND stat_date_gmt = @DATE;
|
||||
END IF;
|
||||
|
||||
DELETE FROM `{$tagsTable}`
|
||||
WHERE `tag_id` = {$tagId}
|
||||
AND @DATE IS NOT NULL;
|
||||
|
||||
SET @ROW_COUNT = ROW_COUNT();
|
||||
SET @DELETE_COUNT = @DELETE_COUNT + @ROW_COUNT;
|
||||
|
||||
UPDATE `{$statsTable}`
|
||||
SET stat_tags = GREATEST(GREATEST(0, stat_tags) - @ROW_COUNT, 0)
|
||||
WHERE stat_type = "date"
|
||||
AND stat_date_gmt = @DATE
|
||||
AND @DATE IS NOT NULL;
|
||||
|
||||
MySQL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user