? ? Pending

User tests: Successful: Unsuccessful:

avatar richard67
richard67
5 May 2021

Pull Request for Issue #33553 .

Summary of Changes

Back-integrate from 4.0-dev to here (3.10-dev) the following changes from PR #25761 for fixing bind() with objects in the JTable class:

  • Change order of processing in the bind() routine and add a get_object_vars if the $src parameter is an object, so that it is:
  1. Check if the source value is an array or object and throw an exception if not.
  2. If the ignore value is a string, explode it over spaces.
  3. If the source value is an object, get its accessible properties with get_object_vars.
  4. JSON encode any fields if required.
  5. Bind the source value, excluding the ignored fields.
  • Add a unit test for bind() with an object.

I'm wondering why the 4th step in the above list currently comes before the 1st without this PR.

Testing Instructions

Step 1: On a current 3.10-dev branch or latest 3.10 nightly build, switch on ""Debug System" and set "Error Reporting" to "Maximum" or "Development".

Step 2: Add the following code to some administrator view:

// Test PR-33558 begin
JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_contact/tables');

$row1 = JTable::getInstance('Contact', 'ContactTable');

$contact1 = [
	'name'      => 'Bat Man',
	'alias'     => 'bat-man',
	'catid'     => 4,
	'params'    => ['show_contact_list' => 0, 'show_tags' => ''],
	'language'  => '*',
	'published' => 1,
	'access'    => 1,
];

$row1->bind($contact1);
$row1->store();

echo '<div>Contact 1 saved.<div>';

$row2 = JTable::getInstance('Contact', 'ContactTable');

$contact2            = new stdClass;
$contact2->name      = 'John Doe';
$contact2->alias     = 'john-doe';
$contact2->catid     = 4;
$contact2->params    = ['show_contact_list' => 0, 'show_tags' => ''];
$contact2->language  = '*';
$contact2->published = 1;
$contact2->access    = 1;

$row2->bind($contact2);
$row2->store();

echo '<div>Contact 2 saved.<div>';
// Test PR-33558 end

E.g. you can add it just before the following line in the users view's default template:
https://github.com/joomla/joomla-cms/blob/3.10-dev/administrator/components/com_users/views/users/tmpl/default.php#L20

The code creates or updates 2 new contact records in database, using bind() and store(), one contact given as array and the other one as object (stdClass).

Step 3: Navigate to the view modified in the previous step.
In my example: "Users -> Manage" (administrator/index.php?option=com_users&view=users).

Result: Error 'Cannot use object of type stdClass as array', see issue #33553 and section "Actual result BEFORE applying this Pull Request" below.

Step 4: Check in database if the two contacts have been created.

Result: Only the first contact "Bat Man" has been created.

Step 5: Delete that contact.

Step 6: Apply the patch of this PR.

Step 7: Navigate again to the view modified in the previous step, or reload the page if still there.

Result: No error, the debug output is shown, see section "Expected result AFTER applying this Pull Request" below.

Step 8: Check in database if the two contacts have been created.

Result: Both contacts "Bat Man" and "John Doe" have been created.

Actual result BEFORE applying this Pull Request

Storing data fails with error 'Cannot use object of type stdClass as array'.

2021-05-06_1

Expected result AFTER applying this Pull Request

Storing data succeeds.

The debug output is shown.

2021-05-06_2

Documentation Changes Required

None.

avatar richard67 richard67 - open - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 May 2021
Category Unit Tests Repository Administration com_admin
avatar richard67 richard67 - change - 5 May 2021
Labels Added: ? ?
avatar joomla-cms-bot joomla-cms-bot - change - 5 May 2021
Category Unit Tests Repository Administration com_admin Libraries
avatar richard67 richard67 - change - 5 May 2021
Build staging 3.10-dev
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 5 May 2021
Category Libraries Libraries Unit Tests
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 5 May 2021
The description was changed
avatar richard67 richard67 - edited - 5 May 2021
avatar richard67 richard67 - change - 6 May 2021
The description was changed
avatar richard67 richard67 - edited - 6 May 2021
avatar richard67 richard67 - change - 6 May 2021
The description was changed
avatar richard67 richard67 - edited - 6 May 2021
avatar richard67 richard67 - change - 6 May 2021
Title
[3.10] [WiP] Correctly handle objects when storing data in tables with _jsonEncode being set
[3.10] Correctly handle objects when storing data in tables with _jsonEncode being set
avatar richard67 richard67 - edited - 6 May 2021
avatar richard67
richard67 - comment - 7 May 2021

@HLeithner As agreed on Glip, I have made this PR here for the 3.10-dev branch. But meanwhile it's clear it fixes a bug only and not introduces any new feature. Shall I rebase it for staging and set the 3.9.27 milestone? Or leave it as it is?

avatar HLeithner
HLeithner - comment - 7 May 2021

I think keep it as it is. We should see a 3.10 stable in a not so far future.

avatar richard67
richard67 - comment - 7 May 2021

As agreed on Glip: Closing in favour of #33633 .

avatar richard67 richard67 - change - 7 May 2021
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2021-05-07 14:06:08
Closed_By richard67
Labels Added: ?
avatar richard67 richard67 - close - 7 May 2021

Add a Comment

Login with GitHub to post a comment