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.
State change succeeds.
State change fails with the following error:
"Unknown column 'checked_out' in 'where clause'"
Joomla 5.0.2
PHP 8.1.27
MySQL 8.0.32-cll-lve
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.
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
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.
please submit a pr
we need to remove hard-code when possible
Done:
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-01-22 23:03:02 |
Closed_By | ⇒ | richard67 |
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.