Information Required ? Pending

User tests: Successful: Unsuccessful:

avatar bembelimen
bembelimen
1 May 2020

Summary of Changes

When you do something like:

$articleModel = new \Joomla\Component\Content\Administrator\Model\ArticleModel;

$articles = [
  [
    'id' => 0,
    'title' => 'bla',
    'alias' => 'bla'
    'catid' => 1,
    'ordering' => 1
  ],
  [
    'id' => 0,
    'title' => 'foobar',
    'alias' => 'foobar',
    'catid' => 1,
    'ordering' => 2
  ]
];

foreach ($articles as $article)
{
  $articleModel->save($article);

  var_dump($articleModel->getState($articleModel->getName() . '.new'));
}

You will get:

true
false

Because giving the save method directly the ID does create a new article but does not reset the internal ID state in the model. So e.g. plugins which rely on this $isNew get the wrong information.

This happens e.g. heavily in the sample data plugin: https://github.com/joomla/joomla-cms/blob/4.0-dev/plugins/sampledata/blog/blog.php#L220-L298 So plugins which hear on "onContentAfterSave" could act the wrong way.

Testing Instructions

  1. Install a clean Joomla
  2. Go to https://github.com/joomla/joomla-cms/blob/4.0-dev/plugins/sampledata/blog/blog.php#L295
  3. Add var_dump($articleModel->getState($articleModel->getName() . '.new'));
  4. Open browser developer console
  5. Execute sample data installation

(Adding this test/debug code will break the installation of the sample datas, but that's ok, as we're testing a specific part and not the whole sample data)

Expected result

bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)

Actual result

bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
avatar bembelimen bembelimen - open - 1 May 2020
avatar bembelimen bembelimen - change - 1 May 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 1 May 2020
Category Libraries
avatar bembelimen bembelimen - change - 1 May 2020
Labels Added: ?
avatar bembelimen bembelimen - change - 1 May 2020
The description was changed
avatar bembelimen bembelimen - edited - 1 May 2020
avatar bembelimen bembelimen - change - 1 May 2020
Title
Fix wrong ID loading when "0" is given as saving parameter
[4.0] Fix wrong ID loading when "0" is given as saving parameter
avatar bembelimen bembelimen - edited - 1 May 2020
avatar chmst
chmst - comment - 1 May 2020

I have tested this item successfully on a980c17

Tested following instructions.


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

avatar chmst chmst - test_item - 1 May 2020 - Tested successfully
avatar bembelimen bembelimen - change - 2 May 2020
The description was changed
avatar bembelimen bembelimen - edited - 2 May 2020
avatar joomla-cms-bot joomla-cms-bot - change - 2 May 2020
Category Libraries Libraries Front End Plugins
avatar bembelimen
bembelimen - comment - 2 May 2020

After a talk with @richard67 we decided to update this PR, because the sample data (at least for the blog) uses a wrong approach in loading the model (e.g. no ignore_request parameter, no proper cleanup after each saving).
This is directly linked with this bug fix itself. So if we do it in two PR (which was the plan), we have a small moment of broken sample data.

avatar richard67
richard67 - comment - 2 May 2020

I have tested this item successfully on 068eb24


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

avatar richard67 richard67 - test_item - 2 May 2020 - Tested successfully
avatar richard67
richard67 - comment - 2 May 2020

@chmst Could you repeat your test on 4.0-dev (or nightly)?

avatar chmst
chmst - comment - 3 May 2020

I have tested this item successfully on 068eb24

Tested on fresh 4.0 dev following testinstructions.


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

avatar chmst chmst - test_item - 3 May 2020 - Tested successfully
avatar bembelimen bembelimen - change - 30 May 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-05-30 17:11:08
Closed_By bembelimen
Labels Added: Information Required
avatar bembelimen bembelimen - close - 30 May 2020
avatar SharkyKZ
SharkyKZ - comment - 1 Jun 2020

@bembelimen Why did you close this?

Add a Comment

Login with GitHub to post a comment