diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 05f056107ddc6..3d6450b17f8eb 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -1498,6 +1498,31 @@ public function publish($pks = null, $state = 1, $userId = 0) { $k = $this->_tbl_keys; + // Check if the table has a state field at all using common titles. + $field = null; + + if (!property_exists($this, 'published') && !property_exists($this, 'state')) + { + $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_PUBLISH_FAILED', get_class($this), 'Table has no state field.')); + $this->setError($e); + + return false; + } + // Calculate, which field most probably acts as the state field. + else + { + // If the most commonly used field exists, use this. + if (property_exists($this, 'published')) + { + $field = 'published'; + } + // If not, but there is a 'state' field, use that. + elseif (property_exists($this, 'state')) + { + $field = 'state'; + } + } + if (!is_null($pks)) { foreach ($pks AS $key => $pk) @@ -1538,7 +1563,8 @@ public function publish($pks = null, $state = 1, $userId = 0) // Update the publishing state for rows with the given primary keys. $query = $this->_db->getQuery(true) ->update($this->_tbl) - ->set('published = ' . (int) $state); + // Don't hardcode the field name. Use our detected field. + ->set("{$field} = " . (int) $state); // Determine if there is checkin support for the table. if (property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time')) @@ -1575,7 +1601,8 @@ public function publish($pks = null, $state = 1, $userId = 0) if ($ours) { - $this->published = $state; + // Don't hardcode the field name. Use our detected field. + $this->{$field} = $state; } }