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

onExtensionBeforeSave and onExtensionAfterSave not working on plugins #7529

Closed
sisko1990 opened this issue Jul 22, 2015 · 6 comments
Closed

Comments

@sisko1990
Copy link
Contributor

Steps to reproduce the issue

Search for e.g. „onExtensionAfterSave“ in Core-Files:
find . -type f -name "*.php" | xargs grep -sl "onExtensionAfterSave"
./administrator/components/com_modules/models/module.php
./administrator/components/com_plugins/models/plugin.php
./administrator/components/com_config/model/component.php
./administrator/components/com_templates/models/style.php
./administrator/components/com_languages/models/language.php

Now look for the trigger method in these files:
find . -type f -name "*.php" | xargs grep -sl "onExtensionAfterSave" | xargs grep -sl "trigger"
./administrator/components/com_modules/models/module.php
./administrator/components/com_config/model/component.php
./administrator/components/com_templates/models/style.php
./administrator/components/com_languages/models/language.php

Expected result

No trigger is used in ./administrator/components/com_plugins/models/plugin.php, but the config for a trigger is prepared. So now a developer cannot use the event on plugins but on all other types.
It would be better as a developer to be able to use that event on plugins, too.

@Bakual
Copy link
Contributor

Bakual commented Jul 22, 2015

Can you propose a PR? See https://docs.joomla.org/Using_the_Github_UI_to_Make_Pull_Requests if you need assistance in how to create one.

@amazeika Is that related to #4308? Sounds at least like a similar issue.

@sisko1990
Copy link
Contributor Author

If I know the solution, I would not commit the issue without code. The code looks ok [in ./administrator/components/com_plugins/models/plugin.php the parent:save from JModelAdmin is called and that save method has the triggers]... but I don't know why they are not used...

@amazeika
Copy link
Contributor

@Bakual Hello Thomas, these events are triggering just fine on my end when saving plugins. I've just reviewed the code and tried it myself.

@sisko1990
Copy link
Contributor Author

I tried it, too - again.
Installation: Joomla! 3.4.3 Stable with Sample Data.

I added this:

public function onExtensionAfterSave($context, &$table, $isNew)
{
      var_dump($context);
      die(); // I know that die() isn't for debugging but it shows the best contrast (-> white site with a bit of text) 
}

to a standard core system plugin that is always activated: Logout (plugins/system/logout/logout.php) right after the constructor.
Its working in modules, templates, languages and on saving components options but not on plugins.

@Bakual
Copy link
Contributor

Bakual commented Jul 23, 2015

Removing the & from the $table in your code fixed it for me.
The issue comes from the fact that com_plugin is using the save method from JModelAdmin while the other managers have own save methods.
They differ in the trigger call in that JModelAdmin doesn't explicitely pass $table as reference while the others do.
Imho, the table is passed by reference anyway, so this isn't needed.

If you look at your PHP log, you will see a warning like this:

PHP Warning: Parameter 2 to PlgSystemLogout::onExtensionAfterSave() expected to be a reference, value given in D:\xampp\htdocs\joomla3.4\libraries\joomla\event\event.php on line 69

@sisko1990
Copy link
Contributor Author

That it was! Sorry. log_errors show more errors on Joomla, as only display_errors...

For me the issue is closed. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants