Skip to content

Commit

Permalink
Fix same tag created by different users not filterable in videos table
Browse files Browse the repository at this point in the history
If another user adds an existing tag to a video, a new tag will be stored in the database since a tag references to the creator. Thus the video filter won't work because two tags of the same tag will be found with different ids.
  • Loading branch information
Dennis Benz committed Dec 4, 2023
1 parent 88eb405 commit 09408ef
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/Models/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ protected static function getFilteredVideos($query, $filters)
$tags = Tags::findBySQL($sq = 'tag LIKE ?', [$filter['value']]);

if (!empty($tags)) {
foreach ($tags as $tag) {
$tag_ids[$tag->id] = [
'id' => $tag->id,
'compare' => $filter['compare']
];
}
$tag_ids[$filter['value']] = [
'tag_ids' => array_map(function ($tag) {
return $tag->id;
}, $tags),
'compare' => $filter['compare'],
];
} else {
$tag_ids[] = '-1';
}
Expand Down Expand Up @@ -269,15 +269,17 @@ protected static function getFilteredVideos($query, $filters)


if (!empty($tag_ids)) {
foreach ($tag_ids as $tag) {
if ($tag['compare'] == '=') {
$sql .= ' INNER JOIN oc_video_tags AS t'. $tag['id'] .' ON (t'. $tag['id'] .'.video_id = oc_video.id '
.' AND t'. $tag['id'] .'.tag_id = '. $tag['id'] .')';
foreach ($tag_ids as $value => $tag_filter) {
$tags_param = ':tags' . $value;
$params[$tags_param] = $tag_filter['tag_ids'];
if ($tag_filter['compare'] == '=') {
$sql .= ' INNER JOIN oc_video_tags AS t'. $value .' ON (t'. $value .'.video_id = oc_video.id '
.' AND t'. $value .'.tag_id IN ('. $tags_param .'))';
} else {
$sql .= ' LEFT JOIN oc_video_tags AS t'. $tag['id'] .' ON (t'. $tag['id'] .'.video_id = oc_video.id '
.' AND t'. $tag['id'] .'.tag_id = '. $tag['id'] .')';
$sql .= ' LEFT JOIN oc_video_tags AS t'. $value .' ON (t'. $value .'.video_id = oc_video.id '
.' AND t'. $value .'.tag_id IN ('. $tags_param .'))';

$where .= ' AND t'. $tag['id'] . '.tag_id IS NULL ';
$where .= ' AND t'. $value . '.tag_id IS NULL ';
}
}
}
Expand Down

0 comments on commit 09408ef

Please sign in to comment.