Skip to content

Commit 23c79b5

Browse files
[5.4] Fix author filter for not existing user (joomla#45264)
1 parent 5ef1cfd commit 23c79b5

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

administrator/components/com_content/src/Model/ArticlesModel.php

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,18 +400,49 @@ protected function getListQuery()
400400

401401
if (is_numeric($authorId)) {
402402
$authorId = (int) $authorId;
403-
$type = $this->getState('filter.author_id.include', true) ? ' = ' : ' <> ';
404-
$query->where($db->quoteName('a.created_by') . $type . ':authorId')
405-
->bind(':authorId', $authorId, ParameterType::INTEGER);
403+
404+
if ($authorId === 0) {
405+
// Only show deleted authors' articles
406+
$subQuery = $db->getQuery(true)
407+
->select($db->quoteName('id'))
408+
->from($db->quoteName('#__users'));
409+
410+
$query->where($db->quoteName('a.created_by') . ' NOT IN (' . $subQuery . ')');
411+
} else {
412+
$type = $this->getState('filter.author_id.include', true) ? ' = ' : ' <> ';
413+
$query->where($db->quoteName('a.created_by') . $type . ':authorId')
414+
->bind(':authorId', $authorId, ParameterType::INTEGER);
415+
}
406416
} elseif (\is_array($authorId)) {
407417
// Check to see if by_me is in the array
408-
if (\in_array('by_me', $authorId)) {
418+
$keyByMe = array_search('by_me', $authorId);
419+
420+
if ($keyByMe !== false) {
409421
// Replace by_me with the current user id in the array
410-
$authorId['by_me'] = $user->id;
422+
$authorId[$keyByMe] = $user->id;
411423
}
412424

413425
$authorId = ArrayHelper::toInteger($authorId);
414-
$query->whereIn($db->quoteName('a.created_by'), $authorId);
426+
427+
if (\in_array(0, $authorId)) {
428+
// Remove 0 from array and handle deleted users with OR condition
429+
$authorId = array_filter($authorId);
430+
431+
// Subquery for deleted users
432+
$subQuery = $db->getQuery(true)
433+
->select($db->quoteName('id'))
434+
->from($db->quoteName('#__users'));
435+
436+
// Build WHERE with both conditions
437+
$query->where('(' .
438+
$db->quoteName('a.created_by') . ' NOT IN (' . $subQuery . ')' .
439+
(!empty($authorId)
440+
? ' OR ' . $db->quoteName('a.created_by') . ' IN (' . implode(',', $query->bindArray($authorId)) . ')'
441+
: '') .
442+
')');
443+
} else {
444+
$query->whereIn($db->quoteName('a.created_by'), $authorId);
445+
}
415446
}
416447

417448
// Filter by search in title.

0 commit comments

Comments
 (0)