Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion administrator/components/com_finder/src/Indexer/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Tree\NodeInterface;
use Joomla\Component\Finder\Administrator\Table\MapTable;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -256,7 +257,7 @@ protected static function storeNode($node, $parentId)
$nodeTable->rebuildPath($nodeTable->id);

// Add the node to the cache.
static::$nodes[$parentId . ':' . $nodeTable->title] = (object) $nodeTable->getProperties();
static::$nodes[$parentId . ':' . $nodeTable->title] = (object) ArrayHelper::fromObject($nodeTable, false);

return static::$nodes[$parentId . ':' . $nodeTable->title]->id;
}
Expand Down
3 changes: 2 additions & 1 deletion administrator/components/com_finder/src/Table/MapTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Table\Nested;
use Joomla\Database\DatabaseInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function check()
$this->alias = ApplicationHelper::stringURLSafe($this->title, $this->language);

if (trim($this->alias) == '') {
$this->alias = md5(serialize($this->getProperties()));
$this->alias = md5(serialize(ArrayHelper::fromObject($this, false)));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function getItem($pk = null)
}

// Convert to an object before adding other data.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$item = ArrayHelper::toObject($properties);

if (property_exists($item, 'params')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function getItem($langId = null)
$table->access = (int) Factory::getApplication()->get('access');
}

$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$value = ArrayHelper::toObject($properties);

return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function getItem($pk = null)
}

// Convert to an object before adding other data.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$item = ArrayHelper::toObject($properties);

if (property_exists($item, 'params')) {
Expand Down Expand Up @@ -219,7 +219,7 @@ public function getMaster($pk = null)
}

// Convert to an object before adding other data.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$item = ArrayHelper::toObject($properties);

if (property_exists($item, 'params')) {
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_menus/src/Model/ItemModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public function getItem($pk = null)
$this->setState('item.type', $table->type);

// Convert to the \Joomla\CMS\Object\CMSObject before adding the params.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$result = ArrayHelper::toObject($properties);

// Convert the params field to an array.
Expand Down Expand Up @@ -1022,7 +1022,7 @@ protected function getMenuType($menutype)

$table->load(['menutype' => $menutype]);

return (object) $table->getProperties();
return (object) ArrayHelper::fromObject($table, false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_menus/src/Model/MenuModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getItem($itemId = null)
return false;
}

$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$value = ArrayHelper::toObject($properties);

return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public function getItem($pk = null)
}

// Convert to an object before adding other data.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$this->_cache[$pk] = ArrayHelper::toObject($properties);

// Convert the params field to an array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getItem($pk = null)
}

// Convert to an object before adding other data.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$this->_cache[$cacheId] = ArrayHelper::toObject($properties);

// Convert the params field to an array.
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_users/src/Model/GroupModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function delete(&$pks)
if ($allow) {
// Fire the before delete event.
$beforeDeleteEvent = new UserGroupBeforeDeleteEvent($this->event_before_delete, [
'data' => $table->getProperties(), // @TODO: Remove data argument in Joomla 6, see UserGroupBeforeDeleteEvent
'data' => ArrayHelper::fromObject($table, false), // @TODO: Remove data argument in Joomla 6, see UserGroupBeforeDeleteEvent
'context' => $context,
'subject' => $table,
]);
Expand All @@ -297,7 +297,7 @@ public function delete(&$pks)

// Trigger the after delete event.
$dispatcher->dispatch($this->event_after_delete, new UserGroupAfterDeleteEvent($this->event_after_delete, [
'data' => $table->getProperties(), // @TODO: Remove data argument in Joomla 6, see UserGroupAfterDeleteEvent
'data' => ArrayHelper::fromObject($table, false), // @TODO: Remove data argument in Joomla 6, see UserGroupAfterDeleteEvent
'deletingResult' => true, // @TODO: Remove deletingResult argument in Joomla 6, see UserGroupAfterDeleteEvent
'errorMessage' => $this->getError(), // @TODO: Remove errorMessage argument in Joomla 6, see UserGroupAfterDeleteEvent
'context' => $context,
Expand Down
14 changes: 7 additions & 7 deletions administrator/components/com_users/src/Model/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function delete(&$pks)
$user_to_delete = $this->getUserFactory()->loadUserById($pk);

// Fire the before delete event.
Factory::getApplication()->triggerEvent($this->event_before_delete, [$table->getProperties()]);
Factory::getApplication()->triggerEvent($this->event_before_delete, [ArrayHelper::fromObject($table, false)]);

if (!$table->delete($pk)) {
$this->setError($table->getError());
Expand Down Expand Up @@ -399,7 +399,7 @@ public function block(&$pks, $value = 1)
unset($pks[$i]);
Factory::getApplication()->enqueueMessage(Text::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF'), 'error');
} elseif ($table->load($pk)) {
$old = $table->getProperties();
$old = ArrayHelper::fromObject($table, false);
$allow = $user->authorise('core.edit.state', 'com_users');

// Don't allow non-super-admin to delete a super admin
Expand Down Expand Up @@ -428,7 +428,7 @@ public function block(&$pks, $value = 1)
}

// Trigger the before save event.
$result = Factory::getApplication()->triggerEvent($this->event_before_save, [$old, false, $table->getProperties()]);
$result = Factory::getApplication()->triggerEvent($this->event_before_save, [$old, false, ArrayHelper::fromObject($table, false)]);

if (\in_array(false, $result, true)) {
// Plugin will have to raise its own error or throw an exception.
Expand All @@ -447,7 +447,7 @@ public function block(&$pks, $value = 1)
}

// Trigger the after save event
Factory::getApplication()->triggerEvent($this->event_after_save, [$table->getProperties(), false, true, null]);
Factory::getApplication()->triggerEvent($this->event_after_save, [ArrayHelper::fromObject($table, false), false, true, null]);
} catch (\Exception $e) {
$this->setError($e->getMessage());

Expand Down Expand Up @@ -542,7 +542,7 @@ public function activate(&$pks)
// Activate and send the notification email
foreach ($pks as $i => $pk) {
if ($table->load($pk)) {
$prevUserData = $table->getProperties();
$prevUserData = ArrayHelper::fromObject($table, false);
$allow = $user->authorise('core.edit.state', 'com_users');

// Don't allow non-super-admin to edit the active status of a super admin
Expand All @@ -569,7 +569,7 @@ public function activate(&$pks)
}

// Trigger the before save event.
$result = Factory::getApplication()->triggerEvent($this->event_before_save, [$prevUserData, false, $table->getProperties()]);
$result = Factory::getApplication()->triggerEvent($this->event_before_save, [$prevUserData, false, ArrayHelper::fromObject($table, false)]);

if (\in_array(false, $result, true)) {
// Plugin will have to raise it's own error or throw an exception.
Expand All @@ -584,7 +584,7 @@ public function activate(&$pks)
}

// Fire the after save event
Factory::getApplication()->triggerEvent($this->event_after_save, [$table->getProperties(), false, true, null]);
Factory::getApplication()->triggerEvent($this->event_after_save, [ArrayHelper::fromObject($table, false), false, true, null]);

// Send the email
if (!$sendMailTo($prevUserData)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -201,7 +202,7 @@ public function getWorkflow()
$table->load($workflowId);
}

return (object) $table->getProperties();
return (object) ArrayHelper::fromObject($table, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -298,7 +299,7 @@ public function getWorkflow()

$workflow->load($workflow_id);

return (object) $workflow->getProperties();
return (object) ArrayHelper::fromObject($workflow, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -246,6 +247,6 @@ public function getWorkflow()
$table->load($workflowId);
}

return (object) $table->getProperties();
return (object) ArrayHelper::fromObject($table, false);
}
}
2 changes: 1 addition & 1 deletion components/com_contact/src/Model/FormModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getItem($itemId = null)
return false;
}

$properties = $table->getProperties();
$properties = ArrayHelper::fromObject($table, false);
$value = ArrayHelper::toObject($properties);

// Convert field to Registry.
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/src/Model/FormModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getItem($itemId = null)
return false;
}

$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$value = ArrayHelper::toObject($properties);

// Convert attrib field to Registry.
Expand Down
2 changes: 1 addition & 1 deletion components/com_tags/src/Model/TagModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function getItem($pk = null)
}

// Convert the Table to a clean object.
$properties = $table->getProperties(1);
$properties = ArrayHelper::fromObject($table, false);
$this->item[] = ArrayHelper::toObject($properties);
} catch (\RuntimeException $e) {
$this->setError($e->getMessage());
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Joomla\Event\DispatcherInterface;
use Joomla\Filesystem\Path;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -45,7 +46,6 @@ abstract class Table extends \stdClass implements TableInterface, DispatcherAwar
use LegacyErrorHandlingTrait;
use LegacyPropertyManagementTrait;


/**
* Include paths for searching for Table classes.
*
Expand Down Expand Up @@ -728,7 +728,7 @@ public function bind($src, $ignore = [])
}

// Bind the source value, excluding the ignored fields.
foreach ($this->getProperties() as $k => $v) {
foreach (ArrayHelper::fromObject($this, false) as $k => $v) {
// Only process fields not in the ignore array.
if (!\in_array($k, $ignore)) {
if (\array_key_exists($k, $src)) {
Expand Down Expand Up @@ -816,7 +816,7 @@ public function load($keys = null, $reset = true)
$query = $db->createQuery()
->select('*')
->from($db->quoteName($this->_tbl));
$fields = array_keys($this->getProperties());
$fields = array_keys(ArrayHelper::fromObject($this, false));

foreach ($keys as $field => $value) {
// Check that $field is in the table.
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ public function load($id)
}

// Assuming all is well at this point let's bind the data
foreach ($table->getProperties() as $key => $value) {
foreach (ArrayHelper::fromObject($table, false) as $key => $value) {
$this->$key = $value;
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/content/joomla/src/Extension/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,28 +735,28 @@ private function canDeleteCategories($data)
$table = $tableInfo[$extension]['table_name'];

// See if this category has any content items
$count = $this->countItemsInCategory($table, $data->get('id'));
$count = $this->countItemsInCategory($table, $data->id);

// Return false if db error
if ($count === false) {
$result = false;
} else {
// Show error if items are found in the category
if ($count > 0) {
$msg = Text::sprintf('COM_CATEGORIES_DELETE_NOT_ALLOWED', $data->get('title'))
$msg = Text::sprintf('COM_CATEGORIES_DELETE_NOT_ALLOWED', $data->title)
. ' ' . Text::plural('COM_CATEGORIES_N_ITEMS_ASSIGNED', $count);
$this->getApplication()->enqueueMessage($msg, 'error');
$result = false;
}

// Check for items in any child categories (if it is a leaf, there are no child categories)
if (!$data->isLeaf()) {
$count = $this->countItemsInChildren($table, $data->get('id'), $data);
$count = $this->countItemsInChildren($table, $data->id, $data);

if ($count === false) {
$result = false;
} elseif ($count > 0) {
$msg = Text::sprintf('COM_CATEGORIES_DELETE_NOT_ALLOWED', $data->get('title'))
$msg = Text::sprintf('COM_CATEGORIES_DELETE_NOT_ALLOWED', $data->title)
. ' ' . Text::plural('COM_CATEGORIES_HAS_SUBCATEGORY_ITEMS', $count);
$this->getApplication()->enqueueMessage($msg, 'error');
$result = false;
Expand Down
6 changes: 5 additions & 1 deletion tests/Integration/Libraries/Cms/Table/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ public function testBindJSONEncodesFields()
],
];

$this->object->set('_jsonEncode', ['params']);
$reflection = new \ReflectionClass($this->object);
Comment thread
laoneo marked this conversation as resolved.
$reflection_property = $reflection->getProperty('_jsonEncode');
$reflection_property->setAccessible(true);

$reflection_property->setValue($this->object, ['params']);

$this->object->bind($data);

Expand Down
Loading