Feature PR-5.0-dev Pending

User tests: Successful: Unsuccessful:

avatar BrainforgeUK
BrainforgeUK
17 Jul 2023

Pull Request for Issue # .

Summary of Changes

Ensure plugin has been loaded before triggering events:
$this->event_before_save
$this->event_after_save

Testing Instructions

Install
plg_brainforgeuk_bftest.zip

Enable plugin, enter a parameter value and save it.

Actual result BEFORE applying this Pull Request

Message showing entered parameter value not displayed.

Expected result AFTER applying this Pull Request

Message showing entered parameter value displayed.

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:

  • No documentation changes for manual.joomla.org needed

avatar joomla-cms-bot joomla-cms-bot - change - 17 Jul 2023
Category Libraries
avatar BrainforgeUK BrainforgeUK - open - 17 Jul 2023
avatar BrainforgeUK BrainforgeUK - change - 17 Jul 2023
Status New Pending
avatar brianteeman
brianteeman - comment - 17 Jul 2023

what am I supposed to see with this PR as I dont see any changed behaviour

avatar BrainforgeUK BrainforgeUK - change - 17 Jul 2023
Labels Added: PR-4.3-dev
avatar BrainforgeUK
BrainforgeUK - comment - 17 Jul 2023

Before change onExtensionBeforeSave() was not executed for plugins in brainforgeuk folder.
Always executed for plugins in system folder, in most cases not executed for other folders.

avatar BrainforgeUK
BrainforgeUK - comment - 17 Jul 2023

One outstanding issue - when a disabled plugin is enabled event_after_save is not executed.
To fix that would require a method of clearing static::$plugins in PluginHelper.php
That would allow PluginHelper::importPlugin() to be called again.

avatar brianteeman
brianteeman - comment - 17 Jul 2023

One outstanding issue - when a disabled plugin is enabled event_after_save is not executed.

That is why I didnt observe any changes

avatar wilsonge
wilsonge - comment - 17 Jul 2023

Gut feeling is that this feels like a potential security incident waiting to happen because we're loading plugin groups from user data. But I'm not quite sure if it's actually exploitable or not. @joomla/security thoughts?

No just realised this is only loading the plugin being modified. Maybe it's fine

avatar HLeithner
HLeithner - comment - 17 Jul 2023

in my opinion you are in charge to import your own plugins when you need them.

avatar HLeithner
HLeithner - comment - 17 Jul 2023

as george found out ;-) it make sense but please don't do it in the AdminModel move this code the the PluginModel we should have one.

avatar BrainforgeUK
BrainforgeUK - comment - 17 Jul 2023

Agree moving code to PluginModel makes more sense.
Bit more complex, but easier to resolve the caveat I mentioned about enabling disabled plugins.

How do I merge change to another file into this pull request?
The proposed change to AdminModel.php can be removed.
The PluginModel changes I propose is at line 342.

`
public function save($data)
{
// Setup type.
$data['type'] = 'plugin';

    // Make sure onExtensionBeforeSave(), if it exists, gets executed.
    // Note it is the responsibility of the plugin to only respond to relevent event triggers.
    // E.G. for system plugins onExtensionBeforeSave() and onExtensionAfterSave() get executed everywhere they exist.
    $pluginBeingSaved = PluginHelper::importPlugin($data['folder'], $data['element']);

    if ($result = parent::save($data)) {

        if (empty($pluginBeingSaved)) {
            if (!empty($data['enabled'])) {
                // Plugin was previously disabled
                $plugin = Factory::getApplication()->bootPlugin($data['element'], $data['folder']);

                // Execute, if it exists, onExtensionAfterSave() for this plugin ONLY.
                $plugin->onExtensionAfterSave('com_plugins.plugin', null, false, $data);
            }
        }
        else {
            // Nothing to do as onExtensionAfterSave(), if it exists, has already been executed
        }
    }

    return $result;
}

`

avatar richard67
richard67 - comment - 20 Jul 2023

@BrainforgeUK You can go to your branch on GitHub https://github.com/BrainforgeUK/joomla-cms/tree/patch-15 and then edit any file on GitHub.

avatar joomla-cms-bot joomla-cms-bot - change - 21 Jul 2023
Category Libraries Administration com_plugins Libraries
avatar joomla-cms-bot joomla-cms-bot - change - 21 Jul 2023
Category Libraries Administration com_plugins Administration com_plugins
avatar BrainforgeUK
BrainforgeUK - comment - 21 Jul 2023

Thanks, PluginModel.php changed.

avatar HLeithner HLeithner - change - 26 Jul 2023
Title
Modified before / after plugin save event execution
[5.0] Modified before / after plugin save event execution
avatar HLeithner HLeithner - edited - 26 Jul 2023
avatar HLeithner
HLeithner - comment - 26 Jul 2023

I rebased this for 5.0 since 4.x is more or less in feature freeze mode

avatar HLeithner HLeithner - change - 26 Jul 2023
Labels Added: PR-5.0-dev
avatar BrainforgeUK
BrainforgeUK - comment - 26 Jul 2023

Thanks

avatar ceford
ceford - comment - 13 Sep 2023

In 5.0.0-beta2-dev after applying the patch I get this:

An error has occurred.

    0 Class "Joomla\Component\Plugins\Administrator\Model\PluginHelper" not found 

So this is a test fail!


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

avatar richard67
richard67 - comment - 13 Sep 2023

It seems the file "administrator/components/com_plugins/src/Model/PluginModel.php" is missing a use statement for the PluginHelper at the top. Done 2023-09-26.

avatar BrainforgeUK BrainforgeUK - change - 26 Sep 2023
Labels Added: Feature
Removed: PR-4.3-dev
avatar BrainforgeUK
BrainforgeUK - comment - 26 Sep 2023

Added use statement for PluginHelper.

avatar Fedik
Fedik - comment - 26 Sep 2023

I have looked at it again. And it still looks bad :)

Please trash it all, and use following code for save() method:

public function save($data)
{
  // Setup type.
  $data['type'] = 'plugin';

  PluginHelper::importPlugin($data['folder'], $data['element'], true, $this->getDispatcher());

  return parent::save($data);
}

Then all will work.

avatar BrainforgeUK
BrainforgeUK - comment - 26 Sep 2023

The simplified version from Fedik does not work!

Plugin enabled, change it to disabled OK.
Plugin disabled, change it to enabled onExtensionAfterSave(() is not called.
... this change would not resolve the initial plugin development issue which led to this PR being created.
... and I just happen to have a dev site with that plugin installed open and could quickly test it!

avatar Fedik
Fedik - comment - 26 Sep 2023

Hm, I see you trying to load disabled plugin also.
I not sure that we should allow that.
@HLeithner @wilsonge what is your opinion about triggering event for disabled plugin?

avatar Fedik
Fedik - comment - 26 Sep 2023

@BrainforgeUK a note, your code also does not work for disabled plugin.
The code $plugin = Factory::getApplication()->bootPlugin($data['element'], $data['folder']); will return incorrectly loaded plugin, without actual parameters etc.

avatar HLeithner HLeithner - change - 26 Sep 2023
Title
[5.0] Modified before / after plugin save event execution
[5.1] Modified before / after plugin save event execution
avatar HLeithner HLeithner - edited - 26 Sep 2023
avatar BrainforgeUK
BrainforgeUK - comment - 26 Sep 2023

The data returned by bootPlugin() does not matter - the saved data is passed to the event.
bootPlugin() ensures that the plugin has been loaded (loadExtension) and its constructor has been called.
Before the save the plugin was disabled and had not been loaded.

avatar Fedik
Fedik - comment - 26 Sep 2023

The data returned by bootPlugin() does not matter - the saved data is passed to the event.

Unfortunately it does matter.
The call inside event listener $this->getParams() will be different for enabled and disabled plugin, and probably other inconsistency.
It may lead to unexpected bugs.

avatar joomla-cms-bot joomla-cms-bot - change - 26 Sep 2023
Category Administration com_plugins Administration com_plugins Libraries
avatar BrainforgeUK
BrainforgeUK - comment - 26 Sep 2023

Got solution to the bootplugin() / getParams() issue.
Now uses PluginHelper::reload(); to ensure the newly enabled plugin is in the right state.
Added reload function to PluginHelper.

avatar HLeithner
HLeithner - comment - 30 Sep 2023

This pull request has been automatically rebased to 5.1-dev.

avatar HLeithner
HLeithner - comment - 24 Apr 2024

This pull request has been automatically rebased to 5.2-dev.

avatar HLeithner HLeithner - change - 24 Apr 2024
Title
[5.1] Modified before / after plugin save event execution
[5.2] Modified before / after plugin save event execution
avatar HLeithner HLeithner - edited - 24 Apr 2024
avatar HLeithner
HLeithner - comment - 2 Sep 2024

This pull request has been automatically rebased to 5.3-dev.

avatar HLeithner HLeithner - change - 2 Sep 2024
Title
[5.2] Modified before / after plugin save event execution
[5.3] Modified before / after plugin save event execution
avatar HLeithner HLeithner - edited - 2 Sep 2024

Add a Comment

Login with GitHub to post a comment