Feature PR-5.3-dev Pending

User tests: Successful: Unsuccessful:

avatar HLeithner
HLeithner
7 Nov 2024

Summary of Changes

This PR adds the data before the update in the table happend to the before and after save event.
This allows a plugin to check the changed values in the after save event and trigger further actions.

Before this PR, the Plugin needs to listen on the beforeSaveEvent, load the row from the database manually and preserve it in the plugin object and read the preserved data in the afterSaveEvent.

A event listener should be self contained and should not depend on any other plugin triggers (if possible).

In this case we now only need the afterSaveEvent and don't need to do another database query, which both increase performance.

Testing Instructions

Create a plugin, or use an existing plugin which listen to the onContentAfterSave and onContentBeforeSave events.

Test with the all extensions (also 3rd party) especially

  • com_content
  • com_category
  • com_language
  • com_template (styles)
  • com_menus
  • com_modules
  • com_tags
  • com_mails (mail templates)

check the value of $event->getArgument('oldData'); this should have the old values before the row has been updated.

Actual result BEFORE applying this Pull Request

No old Data

Expected result AFTER applying this Pull Request

Old Data exists

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org: TBA

  • No documentation changes for manual.joomla.org needed

Additional information

This PR doesn't touch the UserBeforeSave and UserAfterSave event since it doesn't implement the \Joomla\CMS\Event\Model\SaveEvent class, the User Save events already include the old data. Never the less it would make sense to move the User Save events inline with all other Save events.

In the Documentation a migration part have to be added with motivate 3rd party extension developer to check there save function and also provide the old data to the event handler.

avatar HLeithner HLeithner - open - 7 Nov 2024
avatar HLeithner HLeithner - change - 7 Nov 2024
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Nov 2024
Category Administration com_categories com_languages com_menus com_modules com_tags com_templates Libraries
c1b198d 8 Nov 2024 avatar HLeithner CS
avatar HLeithner HLeithner - change - 8 Nov 2024
Labels Added: Feature PR-5.3-dev
avatar Fedik
Fedik - comment - 8 Nov 2024

Nice nice idea.
However it should be done on Table level instead of Model, as other ORM doing:

class Table{
  function bind($data) {
   $this->createDataSnapshot(); // Store old data
   //... bind new data
  }
}

Then you can do $table->getPreviousData() everywhere.

32fc8c6 8 Nov 2024 avatar HLeithner CS
avatar HLeithner
HLeithner - comment - 8 Nov 2024

Also possible, issue on this is that it only works if you use bind() in the table object for adding values, which might be true for this use case, but not if you just set a simple value.

So maybe this could be added additionally and adding the checkbox at the end of the load function.

avatar rdeutz
rdeutz - comment - 13 Nov 2024

Looks good to me

Add a Comment

Login with GitHub to post a comment