General developer forum

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

 
Picture of Dragon Dionysius
Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
Plugin developers

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: -
Picture of Sam Chaffee
Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
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

 
Average of ratings: -
Picture of Dragon Dionysius
Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
Plugin developers

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

 
Average of ratings: -
Picture of Michael Milette
Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
Core developersParticularly helpful MoodlersPlugin developers

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

 
Average of ratings: -
Picture of Dragon Dionysius
Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
Plugin developers

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.

 
Average of ratings: -
Picture of Michael Milette
Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
Core developersParticularly helpful MoodlersPlugin developers

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

 
Average of ratings: -
Picture of Dragon Dionysius
Re: Plugin not required anymore, best way to auto uninstall or make a warning on a "fake" upgrade?
Plugin developers

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

 
Average of ratings: -