? Success

User tests: Successful: Unsuccessful:

avatar smz
smz
17 Dec 2014

Description

This PR extends #5449 by @okonomiyaki3000 (thanks!) by also removing a duplicated method, and identifying the nature of the problem.

Test instructions:

There are no specific test instructions: this is just code clean-up, but it would be advisable to test that nothing is broken in Tags (setting, deleting, selecting, batch processing)

Perform a batch "Set tag" operation on categories

Expected result:

Tags are set

Actual result:

Tags are not set

The fix:

Apply this PR and repeat the above: tags will be set

avatar smz smz - open - 17 Dec 2014
avatar jissues-bot jissues-bot - change - 17 Dec 2014
Labels Added: ?
avatar smz
smz - comment - 17 Dec 2014

Many thanks to @okonomiyaki3000: I didn't mean to steal his PR: the honor of finding and fixing the issue is totally to him.

avatar smz
smz - comment - 17 Dec 2014

... and if he instead wants to take the mods I made and incorporate them into his PR, I'll have no objections at all!

avatar brianteeman brianteeman - change - 17 Dec 2014
Category Tags
avatar okonomiyaki3000
okonomiyaki3000 - comment - 17 Dec 2014

No no, please. Use this PR.

avatar smz
smz - comment - 18 Dec 2014
avatar smz smz - change - 19 Dec 2014
The description was changed
avatar infograf768
infograf768 - comment - 26 Dec 2014

Although tags are set here OK in staging, using this PR also works

avatar smz
smz - comment - 26 Dec 2014

@infograf768, you tried to batch-set tags on categories and it worked? :confused:

avatar infograf768
infograf768 - comment - 26 Dec 2014

Batch: Add Tags.
Yes

avatar smz
smz - comment - 26 Dec 2014

That's curious... it didn't work when this PR was created. I'll re-try later. Have you seen the diff in libraries/cms/helper/tags.php ?

avatar infograf768
infograf768 - comment - 26 Dec 2014

Yep, saw it.

avatar smz
smz - comment - 26 Dec 2014

You're right, it works now! Absurd... I'll re-check the conditions affected by the botched if()...

avatar smz
smz - comment - 26 Dec 2014

@infograf768 I reverted my test environment to the point in time when I opened this PR and described the issue and... no: even in those conditions batch setting tags on categories does work :confused:

I really don't know what had I smoked at the time: something really bad for sure.

I'm also unable to understand when and for which reasons that piece of code inside the botched if() should be executed and what can be the effects of executing it.

Essentially I'm giving up with this and of course you can freely decide what to do with this PR, if either leave things as they are (if it ain't broken, don't fix it) or accept the PR on the basis that the code is clearly formally broken (but with unknown consequences)...

Sorry for the huge f++k-up...

avatar smz
smz - comment - 26 Dec 2014

I would like to add that while batch setting categories tags I had those variables values:

$newTags = array(1) { [0]=> string(1) "2" }
!$newTags = bool(false)
$replace = bool(false)
$this->tagsChanged = bool(false) 

so the the code should not be executed and is not executed (!$newTags = bool(false))
I'd also add that this is the first time in my life I see a boolean operator applied to an array...

avatar infograf768
infograf768 - comment - 27 Dec 2014

Until we clear that issue, I guess that removing the duplicate method is anyway necessary. What you think?

avatar wilsonge
wilsonge - comment - 29 Dec 2014

Yes we should fix both. The if() statement is just clearly wrong anyhow even if we can't quite replicate it yet!

avatar smz
smz - comment - 29 Dec 2014

Unsure: it can also happen that by "fixing" that if() something gets broken...
IMHO a deeper "code review" is needed here

avatar wilsonge
wilsonge - comment - 29 Dec 2014

#2157 This is why it was added in and it was directly related to the batch processing.

avatar smz
smz - comment - 29 Dec 2014

@wilsonge Thanks for the head-up! Will look into that...

avatar rmittl
rmittl - comment - 14 Mar 2015

I didn't apply the patch and the batch to add a new tag to categories is working.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5459.
avatar asysta
asysta - comment - 14 Mar 2015

i didnt apply the patch too, add tags ist working without the patch.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 15 Mar 2015

You guys are missing the point. This patch extends #5449. That patch fixes a typo which exposes a bug in the batch operation. This patch fixes that bug.

avatar smz
smz - comment - 30 May 2015

As this PR is lingering since about 5 months I decided to give it a new look and see if it was still actual.

After a thorough code review I can say it is still valid but it needs to be re-purposed: there was no "issue" to fix, but the code introduced by @okonomiyaki3000 and myself was anyway good.


Let's separately analyse the modifications introduced by this PR:

  1. correct the test inside an if () ... statement (@okonomiyaki3000)
  2. eliminate a duplicate method from an extended class (@smz)
  3. correct a docbloc (@smz)

1.) the purpose of the code inside the botched if in JHelperTags::postStoreProcess() is to "Delete all tags data" if no $newTags = array() are passed and the $replace = true parameter is TRUE.

The affected method is called either directly or through the JTableObserverTags::setNewTags() method.

As the botched test is affected only in case of $replace being FALSE (and its default value is TRUE) we should concentrate on cases where it is either explicitly set to FALSE or can assume that value.

JHelperTags::postStoreProcess() by itself is always called without expressing the $replace parameter which then assumes the TRUE value by default and hence the botched test is not affected (good!).

setNewTags(), on the contrary is always called with its $replaceTags parameter set to FALSE and then passses it down to JHelperTags::postStoreProcess() as $replace. These, thus, can be affected cases.

But setNewTags() is called only inside the two batchTag($value, $pks, $contexts) methods - one in JModelAdmin and the second in CategoriesModelCategory (which is an extended class of JModelAdmin) - and I'm pretty sure that in those cases (we are batch processing tags...) $newTags is populated, and thus the the botched test is not affected here as well.

At the end of the story, the botched test doesn't practically affects any operation: it could only in case JHelperTags::postStoreProcess() would be called with the intention of deleting all tags data, an empty $newTags parameter and the $replace parameter set to false. In that case the method should just return; but, due to the botched test it will actually delete all tags. Happliy enough this condition doesn't seems to happen in our code right now. In any case my personal opinion is that it is correct to fix the botched test.

2.) Easy: we have the very same method verbatim duplicated in an extended class: for simplicity and code "cleanness", it should be eliminated from the extended class.

3.) Easy: a method returning boolean was documented as returning void


Now, as my original description was absolutely wrong (and test instructions were wrong as well...), I'm going to fix PR title and description.

I hope this help...

avatar smz smz - change - 30 May 2015
Title
Fixes batch tagging of categories
Some code clean-up in Tags
avatar smz smz - change - 30 May 2015
The description was changed
Title
Fixes batch tagging of categories
Some code clean-up in Tags
avatar smz smz - change - 30 May 2015
The description was changed
avatar smz smz - change - 13 Jul 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-07-13 08:10:58
Closed_By smz
avatar smz smz - close - 13 Jul 2015
avatar smz smz - close - 13 Jul 2015
avatar okonomiyaki3000
okonomiyaki3000 - comment - 13 Jul 2015

Yay

Add a Comment

Login with GitHub to post a comment