No Code Attached Yet
avatar skillet-actual
skillet-actual
21 Jan 2024

Steps to reproduce the issue

Create a MySQL table that uses the column name "checked_out_foo" instead of the standard column name, "checked_out". Extend the Joomla\CMS\Table\Nested class and, in its constructor, set an alias for the "checked_out" column:

$this->setColumnAlias('checked_out', 'checked_out_foo');

Attempt to change the state of a table item through the admin list.

Expected result

State change succeeds.

Actual result

State change fails with the following error:

"Unknown column 'checked_out' in 'where clause'"

System information (as much as possible)

Joomla 5.0.2
PHP 8.1.27
MySQL 8.0.32-cll-lve

Additional comments

The problem is in the Joomla\CMS\Table\Nested::publish() function definition near line 920. In the query definition, the "checked_out" field name is hard-coded and no checks are made to see if that column is aliased:

$query->clear()
->select('COUNT(' . $k . ')')
->from($this->_tbl)
->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt)
->where('(checked_out <> 0 AND checked_out <> ' . (int) $userId . ')');

To fix the issue, use this instead:

$checkedOutField = $this->_db->quoteName($this->getColumnAlias('checked_out'));
$query->clear()
->select('COUNT(' . $k . ')')
->from($this->_tbl)
->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt)
->where('(' . $checkedOutField . ' <> 0 AND ' . $checkedOutField . ' <> ' . (int) $userId . ')');

EDIT: Note that the parent class (Joomla\CMS\Table\Table) supports aliasing the "checked_out" column, but this support is removed in child class's override of the method. Support (or lack thereof) should be consistent between parent and child.

avatar skillet-actual skillet-actual - open - 21 Jan 2024
avatar skillet-actual skillet-actual - change - 21 Jan 2024
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 21 Jan 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 21 Jan 2024
avatar skillet-actual
skillet-actual - comment - 21 Jan 2024

NOTE: Forgot to quote my column name in the fix...

$checkedOutField = $this->_db->quoteName($this->getColumnAlias('checked_out'));


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42688.

avatar skillet-actual
skillet-actual - comment - 22 Jan 2024

Hi Brian, this is one of two "special" columns that is commonly aliased. The other is "published", a.k.a. "state".

The Nested class extends Joomla\CMS\Table\Table.php. If you look at the definition of the parent class's publish() method, you'll see that it does indeed check for aliasing the "checked_out" column name (near line 1717 in my editor). For consistency, the Nested class should also respect aliasing.

IMO, table classes either should support aliasing the column or not. As you can see, the Table class supports it but it's child Nested class does not.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42688.

avatar skillet-actual skillet-actual - change - 22 Jan 2024
The description was changed
avatar skillet-actual skillet-actual - edited - 22 Jan 2024
avatar skillet-actual skillet-actual - change - 22 Jan 2024
The description was changed
avatar skillet-actual skillet-actual - edited - 22 Jan 2024
avatar alikon
alikon - comment - 22 Jan 2024

please submit a pr
we need to remove hard-code when possible

avatar skillet-actual
skillet-actual - comment - 22 Jan 2024

Done:

#42697


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42688.

avatar richard67 richard67 - close - 22 Jan 2024
avatar richard67 richard67 - change - 22 Jan 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-01-22 23:03:02
Closed_By richard67
avatar richard67
richard67 - comment - 22 Jan 2024

Closing as having a pull request. See #42697 .

Add a Comment

Login with GitHub to post a comment