? Success

User tests: Successful: Unsuccessful:

avatar alikon
alikon
22 Oct 2016

Pull Request for Issue #12475 .

Summary of Changes

added method to the joomla content plugin
used controller postDeleteHook + new model method delete_featured
used method delete override to delete item on #__content_frontpage when the deleted article was featured

Testing Instructions

Delete a featured article and check that the content_id item is deleted from #__content_frontpage table too

avatar alikon alikon - open - 22 Oct 2016
avatar alikon alikon - change - 22 Oct 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 Oct 2016
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 22 Oct 2016
Category Front End Plugins
ea936e2 22 Oct 2016 avatar alikon tabs
avatar Bakual
Bakual - comment - 22 Oct 2016

Sorry, but a content plugin is the wrong place for such kind of stuff. This belongs to the component controller or model. You can for example use the controllers postDeleteHook to do that.

There are other methods in that plugin which should never have been put there. The only valid one is the onContentAfterSave which sends a notification.
Plugins are (or should be) optional. They can be disabled by the user and the system should still work without getting corrupt data. That is not the case here for the onContentBeforeDelete (prevents deleting non-empty categories) and onContentChangeState (updates UCM table with changed state) andf your proposed new method. If that plugin is disabled, you would get wrong data entries.

avatar alikon
alikon - comment - 22 Oct 2016

ok i've got your point,
but following this logic all stuff done by the joomla content plugin wich can be disabled are misplaced
even onContentAfterSave

BTW used the postDeleteHook now

avatar alikon alikon - change - 22 Oct 2016
The description was changed
avatar alikon alikon - edited - 22 Oct 2016
avatar joomla-cms-bot joomla-cms-bot - change - 22 Oct 2016
Category Front End Plugins Administration Components Front End Plugins
avatar Bakual
Bakual - comment - 22 Oct 2016

but following this logic all stuff done by the joomla content plugin wich can be disabled are misplaced even onContentAfterSave

The onContentAfterSave is fine. It's sort of a coupling between com_content and com_users and sends a message to the admins when a new article is submitted in frontend. It's a completely optional feature and nothing breaks here if the plugin is disabled.

All the other stuff is in the wrong place.

BTW used the postDeleteHook now

Looks much better to me now. Thanks!

avatar alikon
alikon - comment - 22 Oct 2016

so we need some kind of deprecation for these that are misplaced ?
or they are simply bad pattern

avatar Bakual
Bakual - comment - 22 Oct 2016

Probably yes, but first rewrite them in a B/C manner to use the models :)

avatar csthomas
csthomas - comment - 22 Oct 2016

What about move the action to JTableObserver?
Means create a new observer like JTableObserverFeatured.

For now I do not know how to do that because there no exists onAfterDelete method but it is onBeforeDelete.
I would put a new observer here:
https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/table/content.php#L35

and in subclass override that method:
https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/table/observer.php#L106

This way we can better simulate foreign key relationship "ON DELETE CASCADE".

avatar chrisdavenport
chrisdavenport - comment - 22 Oct 2016

As this is a referential integrity issue, it is a responsibility of the model. Why not simply override the delete method in the model and add the extra code there? The controller should not be involved at all.

Adding observers to JTable is more for cross-cutting concerns that need to work across multiple components. This code is specifically tied to articles, as I understand it.

avatar Bakual
Bakual - comment - 22 Oct 2016

Yeah, no need for an observer as it is strictly com_content code.

Either the controllers postDeleteHook or an overridden delete method in the model does the job correctly. @chrisdavenport has a valid point there as well.

avatar alikon alikon - change - 22 Oct 2016
The description was changed
avatar alikon alikon - edited - 22 Oct 2016
avatar alikon alikon - change - 22 Oct 2016
The description was changed
avatar alikon alikon - edited - 22 Oct 2016
avatar alikon
alikon - comment - 31 Oct 2016

@chrisdavenport do you mean to add the delete for #__content_frontpage item here https://github.com/joomla/joomla-cms/blob/6aaae6e07d7b345c9a926f2b3db31bd600716c82/libraries/legacy/model/admin.php#L748

something like is already made for Associations ie when $context is com_content.article ?

avatar Bakual
Bakual - comment - 31 Oct 2016

No. That is a generic library model, your code is com_content code only.
But you can override that delete method from JModelAdmin in ContentModelArticle. Eg

public function delete(&$pks)
{
    $return = parent::delete($pks);

    if ($return)
    {
        do your stuff here
    }

    return $return;
}

That will use the delete method from the JModelAdmin (parent::delete()) and if that was successfull afterwards you do the additional work.

avatar alikon
alikon - comment - 31 Oct 2016

thanks @Bakual for the explanation make perfect sense now ;).

avatar csthomas
csthomas - comment - 31 Oct 2016

That way if you want to delete a few articles and for the not first one you:

  • do not have access (ex. 1 article is not your) or
  • plugin on before or after delete event failed for at least one article

then featured item won't be deleted but some articles will be deleted.

Simple test.
First article is my, second is your (I do not have access to delete your article).
I want to delete them, but then featured items won't be deleted.

avatar alikon alikon - change - 31 Oct 2016
The description was changed
avatar alikon alikon - edited - 31 Oct 2016
avatar joomla-cms-bot joomla-cms-bot - change - 31 Oct 2016
Category Front End Plugins Administration Components Administration Components
avatar alikon
alikon - comment - 31 Oct 2016

@csthomas can we go step by step, before this pr, frontpage items won't have deleted at all

avatar brianteeman brianteeman - change - 4 Dec 2016
Easy No Yes
avatar brianteeman
brianteeman - comment - 5 Dec 2016

I have tested this item successfully on 255488e

Tested successfully when a featured item is completely deleted (trash is emptied) then the item is removed from the frontpage table


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

avatar brianteeman brianteeman - test_item - 5 Dec 2016 - Tested successfully
avatar coolcat-creations
coolcat-creations - comment - 6 Dec 2016

I have tested this item successfully on 255488e

works like described, thanks!


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

avatar coolcat-creations coolcat-creations - test_item - 6 Dec 2016 - Tested successfully
avatar brianteeman brianteeman - change - 6 Dec 2016
Status Pending Ready to Commit
avatar brianteeman
brianteeman - comment - 6 Dec 2016

RTC


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

avatar brianteeman brianteeman - change - 6 Dec 2016
Milestone Added:
avatar rdeutz rdeutz - change - 9 Dec 2016
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2016-12-09 22:29:06
Closed_By rdeutz
avatar rdeutz rdeutz - close - 9 Dec 2016
avatar rdeutz rdeutz - merge - 9 Dec 2016
avatar rdeutz rdeutz - reference | 8059d4d - 9 Dec 16
avatar rdeutz rdeutz - merge - 9 Dec 2016
avatar rdeutz rdeutz - close - 9 Dec 2016
avatar joomla-cms-bot joomla-cms-bot - change - 9 Dec 2016
Category Administration Components Administration com_content Components
avatar cpfeifer cpfeifer - reference | fb3e6ba - 22 Dec 16

Add a Comment

Login with GitHub to post a comment