Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#33348] fix JModelAdmin::publish() #3190

Closed
wants to merge 6 commits into from
Closed

Conversation

itbra
Copy link
Contributor

@itbra itbra commented Feb 26, 2014

Fixing issue described in bug #33348, related to JModelAdmin (libraries/legacy/model/admin.php)

When trying to publish an item, the related table might be(en) checked out by another user. Thus, publishing will fail silently, since the table is going to try to check in only if is not checked out at all or if the user trying to check it in equals the one having checked it out. If they mismatch nothing is stated to the user trying to change its state, which is no good. So i added a check for this circumstance.

When trying to publish an item, the related table might be(en) checked out by another user. Thus, publishing will fail silently, since the table is going to try to check in only if is not checked out at all or if the user trying to check it in equals the one having checked it out. If they mismatch nothing is stated to the user trying to change its state, which is no good. So i added a check for this circumstance.
Replaced 'AND' by '&&'
The model assumed the table has a field named 'checked_out'. But this might cause an error being thrown trying to access a non-existing property with tables not having this field.
Added property existence check
Fixed logical error in line 936
@jissues-bot jissues-bot changed the title [#33348] fix JModelAdmin::publish() fix JModelAdmin::publish() Oct 17, 2014
// If the table is checked out by another user, drop it and report to the user trying to change its state.
if (property_exists($table, 'checked_out') && $table->checked_out && ($table->checked_out != $user->id))
{
JLog::add(JText::sprintf('COM_KEY2SWAP_ERROR_ROW_IS_CHECKED_OUT_BY', $pks[$i]), JLog::WARNING, 'jerror');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itbra
COM_KEY2SWAP_ERROR_ROW_IS_CHECKED_OUT_BY
Is not a Core language string can you change it to something that is a core one or add an new core one?

@joomla-cms-bot joomla-cms-bot changed the title fix JModelAdmin::publish() [#33348] fix JModelAdmin::publish() May 3, 2015
@roland-d
Copy link
Contributor

roland-d commented May 4, 2015

@itbra Could you please update the PR so it is up-to-date. I did a quick test with manual code change and it works for me and is a good fix. Thanks.

@itbra
Copy link
Contributor Author

itbra commented May 4, 2015

I can do that, but i'm afraid it makes no sense as it seems there is no further interest to accept and merge it. See how old it is.

@zero-24
Copy link
Contributor

zero-24 commented May 4, 2015

@itbra I have just also tested as @roland-d per manual code change and it works here too. So the only thing for RTC/merge is now is a up-to-date PR. 😄

@roland-d
Copy link
Contributor

roland-d commented May 4, 2015

Agree, once the PR is up-to-date I will merge it as we have 2 good tests. Thanks @itbra

@itbra
Copy link
Contributor Author

itbra commented May 4, 2015

Ok, so i'll close this PR and create a new one as i don't know how to update this one against the latest Joomla! version here on GitHub and creating a new one is the fastest way for me. I create all my PRs directly on GitHub.

@itbra
Copy link
Contributor Author

itbra commented May 5, 2015

Guys i need your opinions!

When i started to create the new PR i noticed that JModelAdmin::reorder() and JModelAdmin::saveorder() also change an item's state not considering that it might be checked out by a different user. As i think every change to an item's state while it might be checked out by a different user should be checked for this conflict i wonder if it wouldn't be better to extend JModelAdmin::canEditState() rather than introducing code duplication.

I don't want to create the new PR with duplicate code but would like to update all methods that appear to be buggy like JModelAdmin::publish() regarding the editor mismatch.

What do you think?

@roland-d
Copy link
Contributor

roland-d commented May 6, 2015

@itbra I agree with your comment that the checked out status should be taken into account of the reorder/saveorder actions.

However I think we should fix it a little higher up in the chain. If you look at JTable::published() we have the checked out check there as well. This code:

// Determine if there is checkin support for the table.
if (property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time'))
{
    $query->where('(' . $this->getColumnAlias('checked_out') . ' = 0 OR ' . $this->getColumnAlias('checked_out') . ' = ' . (int) $userId . ')');
    $checkin = true;
}
else
{
    $checkin = false;
}

Not sure if we can/should wrap this into a method of it's own. You are setting 2 values here and it is only a single if/else block. Using this block in the existing methods might be just as effective as you don't have to juggle with parameters and return values.

That is my idea.

@RonakParmar
Copy link

I have checked this issue in my local, able to reproduce the issue of changing the state of checked item.
Here is my system information:

Joomla! Version: Joomla! 3.4.8 Stable [ Ember ] 24-December-2015 19:30 GMT
Joomla! Platform Version: Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
PHP Version: 5.4.45-3+deb.sury.orgprecise+1
System Linux desktop 3.5.0-54-generic #81
precise1-Ubuntu SMP Tue Jul 15 04:02:22 UTC 2014 x86_64


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

@RonakParmar
Copy link

I have tested this item ✅ successfully on 61cca9a

I have applied this patch and it works fine for me.


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

@yvesh
Copy link
Member

yvesh commented Apr 9, 2016

I have tested this item ✅ successfully on 61cca9a

Works fine


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

@rdeutz rdeutz added the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@rdeutz rdeutz added the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@brianteeman
Copy link
Contributor

@rdeutz if you want to make something RTC you have to make a comment RTC at the same time or the bot will unset it


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

@brianteeman
Copy link
Contributor

Also not 100% certain but if it fails the travis tests it probably cant be marked RTC either


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

@mbabker
Copy link
Contributor

mbabker commented Apr 9, 2016

It shouldn't be RTC/merged with Travis failures, no. There's extra whitespace on the new line 929 (should be a blank line). The rest of the failures come from the fact this PR is based on such an old version of staging that the Travis config at the time is no longer valid.

@rdeutz
Copy link
Contributor

rdeutz commented Apr 9, 2016

I think I will remake the PR or @itbra can you make a new PR?


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

@rdeutz rdeutz added the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@rdeutz rdeutz added the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@rdeutz
Copy link
Contributor

rdeutz commented Apr 9, 2016

Setting to RTC


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

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@rdeutz
Copy link
Contributor

rdeutz commented Apr 9, 2016

(headbang) seems it is above my level of knowledge to set something to RTC

rdeutz added a commit to rdeutz/joomla-cms that referenced this pull request Apr 11, 2016
@rdeutz rdeutz mentioned this pull request Apr 11, 2016
@rdeutz
Copy link
Contributor

rdeutz commented Apr 11, 2016

next try to set to RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Apr 11, 2016
@brianteeman
Copy link
Contributor

Closing here so that #9848 is merged


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

@rdeutz
Copy link
Contributor

rdeutz commented Apr 11, 2016

closing this one because of #9848

@rdeutz rdeutz closed this Apr 11, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 11, 2016
roland-d added a commit that referenced this pull request Apr 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants