Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Dragon Dionysius -
Number of replies: 7

Hi all

First post here. I'm a Moodle Plugin Developer and I don't know if plugin related questions are right here.

I picked up a moodle plugin on which I work on during this semester and this plugin consisted of 2 separate plugin. The "main" plugin and a "question behavior" plugin. We managed to switch to the question-engine so we don't rely on the core quiz module and it's behavior settings anymore.

Is there a way to auto-uninstall a plugin? Or is there at least a neat way to inform the admin that this plugin is not required anymore?

Once the "main" plugin changes gets rolled out, they shouldn't use the "behavior" plugin anymore.

Any ideas? Thanks in advance!

Average of ratings: -
In reply to Dragon Dionysius

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Sam Chaffee -
Picture of Core developers

Hi,

There isn't a way to auto-uninstall plugins in a site you don't administer because it would just re-install immediately since the plugin code would still be on the server. Also, uninstalling a plugin from a site you don't administer might cause those who do administer it some worry.

Without knowing more of the details, here is something that may work for you. It sounds like the "question behavior" plugin was a dependency of the "main" plugin. You could use that to require a new version of the "question behavior" plugin that is deprecated in some way. See the $plugin->dependencies section of this doc for more details.

If the new version of "main" plugin breaks when the the "question behavior" plugin is used then maybe that means the new version of the "question behavior" plugin is essentially a dummy plugin that does nothing. If that's not the case then maybe the new version of the "question behavior" plugin just has some indication that it's deprecated (in its settings page maybe) and that it should be uninstalled.

HTH,

Sam

In reply to Sam Chaffee

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Dragon Dionysius -

Hi Sam

Thank you for your help!


> Also, uninstalling a plugin from a site you don't administer might cause those who do administer it some worry.

That's a good point.


> It sounds like the "question behavior" plugin was a dependency of the "main" plugin.

Unfortunately it was the other way around, the behavior was optional. But the behavior was only able to work when the "main" plugin was installed so that had a dependency to it.


> If the new version of "main" plugin breaks when the the "question behavior" plugin is used then maybe that means the new version of the "question behavior" plugin is essentially a dummy plugin that does nothing.

That's a good idea. It basically inherited immediatefeedback behavior and this would be a good fallback as dummy.


Overall thank you very much for your points

In reply to Dragon Dionysius

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Dragon,

You'll need to start by including a yourplugin/db/uninstall.php and a yourplugin/db/upgrade.php to the plugin you want to keep. Upgrade and uninstallation steps (such as database scheme changes and other things that must happen when the plugin is being upgraded/uninstalled) are defined here.

In these files, you will want to have them call the uninstall_plugin($type, $name) function, found in lib/adminlib.php.

Then, the next time the admin upgrades or uninstalls your plugin, it will automatically remove the unwanted plugin.

I haven't actually tried this myself but it should be enough to get you started on the right path.

Hope you find this useful.

Best regards,

Michael Milette

In reply to Michael Milette

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Dragon Dionysius -

HI Michael

Thank you for your help!


> In these files, you will want to have them call the uninstall_plugin($type, $name) function, found in lib/adminlib.php.

That's actually a neat idea.


> I haven't actually tried this myself but it should be enough to get you started on the right path.

It is, thank you.

In reply to Dragon Dionysius

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

As for notifying the administrator that the old plugin is no longer required...

You know how new settings sometimes show up when you install a new plugin or upgrade an existing plugin? Well, if you add a new checkbox setting to the plugin and make the description, or heading contain the message you want to deliver, it will automatically show up the next time the plugin is upgraded or when it is installed. Hopefully the administrator will read the message instead of just clicking Save. In fact, you could add a check in your settings.php file so that the setting only appears if the old plugin exists.

This is just a backup plan in case you can't figure out my previous suggestion.

Hope you find this useful.

Michael

In reply to Michael Milette

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Dragon Dionysius -

Hi Michael

Thanks again for your answer!


> You know how new settings sometimes show up when you install a new plugin or upgrade an existing plugin?

That's right, I actually saw that when I added another setting a while ago. This is a good behavior to let the admin decide the setting instead of hiddenly activate the default behavior

In reply to Michael Milette

Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?

by Dragon Dionysius -

Hi Michael

I combined your two answers. For completeness these changes are required: https://github.com/frankkoch/moodle-mod_studentquiz/commit/3b206b962b678da75af328c87d65c2cf6d5b996c

For all systems I had access to, I got the new setting shown, but also the removal of the files during uninstallation didn't work due detected missing permissions. That means, that the upgrade process will automatically install it again (thats how the moodle upgrade works it seems).

So I can't confirm that we'll see this option when uninstall works flawlessly. At least the info gets surely shown when it didn't work, and that's fine for now.

Overall: Removal of question behaviours plugins is not easy for administrators at all, as you can't change the behavior entry in question_attempts by moodle offered functionality. According to https://moodle.org/mod/forum/discuss.php?d=343295, specific conditions must be met in the database. So this upgrade process at least makes sure you can finally uninstall the plugin, as there will be no assignment for it anymore.