User tests: Successful: Unsuccessful:
Pull Request for Issue #12475 .
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
Delete a featured article and check that the content_id item is deleted from #__content_frontpage table too
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
Category | ⇒ | Front End Plugins |
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
Category | Front End Plugins | ⇒ | Administration Components Front End Plugins |
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!
so we need some kind of deprecation for these that are misplaced ?
or they are simply bad pattern
Probably yes, but first rewrite them in a B/C manner to use the models :)
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".
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.
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.
@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
?
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.
That way if you want to delete a few articles and for the not first one you:
before
or after
delete event failed for at least one articlethen 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.
Category | Front End Plugins Administration Components | ⇒ | Administration Components |
Easy | No | ⇒ | Yes |
I have tested this item
Tested successfully when a featured item is completely deleted (trash is emptied) then the item is removed from the frontpage table
I have tested this item
works like described, thanks!
Status | Pending | ⇒ | Ready to Commit |
RTC
Milestone |
Added: |
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 |
Category | Administration Components | ⇒ | Administration com_content Components |
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) andonContentChangeState
(updates UCM table with changed state) andf your proposed new method. If that plugin is disabled, you would get wrong data entries.