Skip to content

Commit

Permalink
[3.x] [RFC] Fix SQL error 1093 in com_finder's removeOrphanNodes func…
Browse files Browse the repository at this point in the history
…tion with particular MySQL server versions (#34818)
  • Loading branch information
richard67 committed Jul 19, 2021
1 parent db24fef commit bf7184a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions administrator/components/com_finder/helpers/indexer/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,23 +329,29 @@ public static function removeOrphanNodes()
{
// Delete all orphaned nodes.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$subquery = $db->getQuery(true);
$subquery1 = $db->getQuery(true);

$subquery1->select($db->quoteName('t.id'))
$query = $db->getQuery(true)
->select($db->quoteName('t.id'))
->from($db->quoteName('#__finder_taxonomy', 't'))
->join('LEFT', $db->quoteName('#__finder_taxonomy_map', 'm') . ' ON ' . $db->quoteName('m.node_id') . '=' . $db->quoteName('t.id'))
->where($db->quoteName('t.parent_id') . ' > 1 ')
->where($db->quoteName('m.link_id') . ' IS NULL');

$subquery->select($db->quoteName('id'))
->from('(' . $subquery1 . ') temp');
$db->setQuery($query);

$ids = $db->loadColumn();

if (empty($ids))
{
return 0;
}

$query->delete($db->quoteName('#__finder_taxonomy'))
->where($db->quoteName('id') . ' IN (' . $subquery . ')');
$query->clear()
->delete($db->quoteName('#__finder_taxonomy'))
->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')');

$db->setQuery($query);

$db->execute();

return $db->getAffectedRows();
Expand Down

0 comments on commit bf7184a

Please sign in to comment.