J4 Issue ?
avatar simbunch
simbunch
17 Oct 2018

Steps to reproduce the issue

  1. Create a model for your component (extends JModelList)

  2. In the function getListQuery, return a query that is a union, eg:
    $query1 = $db->getQuery(true)->select(...);
    $query2 = $db->getQuery(true)->select(...);
    return $query1->union($query2);

  3. In the view.html.php, retrieve the pagination object:
    $pagination = $this->get('Pagination');

  4. Error is displayed

avatar simbunch simbunch - open - 17 Oct 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 17 Oct 2018
avatar PhilETaylor
PhilETaylor - comment - 23 Oct 2018
avatar laoneo
laoneo - comment - 23 Oct 2018

Is this issue reproducable also with a core extension?

avatar simbunch
simbunch - comment - 25 Oct 2018

Tested with com_content, same problem occurs.
Go to file /administrator/components/com_content/Model/ArticlesModel.php line 188 (in the function getListQuery) and insert:
$query = $db->getQuery(true)->select('id')->from($db->quoteName('#__content'));
$query2 = $db->getQuery(true)->select('id')->from($db->quoteName('#__content'));
return $query->union($query2);

You can use any 2 random queries, as long as you use a union, the error will be thrown.

avatar csthomas
csthomas - comment - 25 Oct 2018

Try this fix.

Go to libraries/vendor/joomla/database and patch below files. You can use patch -p1 < diff.patch

diff --git a/src/DatabaseQuery.php b/src/DatabaseQuery.php
index 2c02fcc..de694a6 100644
--- a/src/DatabaseQuery.php
+++ b/src/DatabaseQuery.php
@@ -1737,9 +1737,19 @@ abstract class DatabaseQuery implements QueryInterface
                                continue;
                        }
 
-                       if (\is_object($v) || \is_array($v))
+                       if (\is_object($v))
                        {
-                               $this->{$k} = unserialize(serialize($v));
+                               $this->{$k} = clone $v;
+                       }
+                       elseif (\is_array($v))
+                       {
+                               foreach ($v as $i => $element)
+                               {
+                                       if (\is_object($element))
+                                       {
+                                               $this->{$k}[$i] = clone $element;
+                                       }
+                               }
                        }
                }
        }
diff --git a/src/Query/QueryElement.php b/src/Query/QueryElement.php
index 271fb94..4ddd061 100644
--- a/src/Query/QueryElement.php
+++ b/src/Query/QueryElement.php
@@ -137,9 +137,19 @@ class QueryElement
        {
                foreach ($this as $k => $v)
                {
-                       if (\is_object($v) || \is_array($v))
+                       if (\is_object($v))
                        {
-                               $this->{$k} = unserialize(serialize($v));
+                               $this->{$k} = clone $v;
+                       }
+                       elseif (\is_array($v))
+                       {
+                               foreach ($v as $i => $element)
+                               {
+                                       if (\is_object($element))
+                                       {
+                                               $this->{$k}[$i] = clone $element;
+                                       }
+                               }
                        }
                }
        }

It replaces serialize/unserialize by simple cloning.

avatar simbunch
simbunch - comment - 25 Oct 2018

It works, thank you!

avatar brianteeman brianteeman - change - 30 Oct 2018
Labels Added: J4 Issue
avatar brianteeman brianteeman - labeled - 30 Oct 2018
avatar Quy Quy - change - 14 Dec 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-12-14 02:28:44
Closed_By Quy
avatar joomla-cms-bot joomla-cms-bot - change - 14 Dec 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-12-14 02:28:44
Closed_By joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 14 Dec 2018
avatar joomla-cms-bot
joomla-cms-bot - comment - 14 Dec 2018

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/22685

Add a Comment

Login with GitHub to post a comment