Uninstall plugins via CLI

Uninstall plugins via CLI

by Ben Kahn -
Number of replies: 19

Hello, I just completed my first test upgrade entirely via CLI. I'm upgrading from 3.4 to 3.6.5. As part of the upgrade I need to uninstall some old themes and plugins. Is there a way to do this via CLI? Specifically is there a good way to trigger the uninstall script first, so the code folders can then be removed safely? I would expect to see an "uninstall.php" or similar script in the plugin/db folder of a plugin but that doesn't seem to be there.

Yes I COULD uninstall through the site, then do the rest of the upgrade after, but I'd like to use the CLI maintenance mode and it would be nicer not to have to turn on and off multiple times.

Average of ratings: -
In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

Please see:

https://moosh-online.com/

https://moosh-online.com/commands/

plugin-uninstall

Removes given plugin from the DB and disk. It can remove plugins that have no folder on the disk and have some redundant data inside DB tables. If you do not have write permissions on the plugins' folder it will advice you with the command that will give the right permissions and then you are asked to run the command again.

Example:

moosh plugin-uninstall theme_elegance

moosh can be used in conjunction with scripts in admin/cli/ I have a nasty habit of using -n with moosh commands and then check/set ownerships/permissions again via CLI.

As always advised ... backup DB and code dir first.

'SoS', Ken


Average of ratings: Useful (5)
In reply to Ken Task

Re: Uninstall plugins via CLI

by Ben Kahn -

Ken, thanks as always for sharing. I have heard "moosh" thrown around but didn't think to check it out for this purpose. I will see if I can test it out before my upcoming maintenance but if I don't get a chance will definitely do so soon after. Thanks!

In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

Welcome!  Always glad to share.  One of these days, future versions of Moodle would hopefully have 'opposite' PHP scripts to compliment what one finds in admin/cli/

Until then, moosh fills the gap. smile

'SoS', Ken

In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Ben Kahn -
OK, I was just perusing the admin/cli folder on a Moodle 3.8 site and realized ther *is* CLI plugin uninstall script....

admin/cli/uninstall_plugins.php

--help Print this help.
--show-all Displays a list of all installed plugins.
--show-missing Displays a list of plugins missing from disk.
--purge-missing Uninstall all missing from disk plugins.
--plugins= A comma separated list of plugins to be uninstalled. E.g. mod_assign,mod_forum
--run Execute uninstall. If this option is not set, then the script will be run in a dry mode.

Examples:

# php uninstall_plugins.php --show-all
Prints tab-separated list of all installed plugins.

# php uninstall_plugins.php --show-missing
Prints tab-separated list of all missing from disk plugins.

# php uninstall_plugins.php --purge-missing
A dry run of uninstalling all missing plugins.

# php uninstall_plugins.php --purge-missing --run
Run uninstall of all missing plugins.

# php uninstall_plugins.php --plugins=mod_assign,mod_forum
A dry run of uninstalling mod_assign and mod_forum plugins.

# php uninstall_plugins.php --plugins=mod_assign,mod_forum --run
Run uninstall for mod_assign and mod_forum plugins.
Average of ratings: Useful (9)
In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Mina Attia -
dear Ben,

we have installed conditional profile fields plugin,

can we uninstall it by the way you mentioned?
In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Mina Attia -
bitnami@ip-:/opt/bitnami/apps/moodle/htdocs/admin/cli$ sudo php uninstall_plugins.php plugins=profilefield_checkbox,profilefield_conditional,profilefield_datetime,profilefield_menu --run
Uninstalling: profilefield_checkbox Checkbox
-->profilefield_checkbox
++ Success ++

Can not be uninstalled: profilefield_conditional Conditional field
Can not be uninstalled: profilefield_datetime Date/Time
Can not be uninstalled: profilefield_menu Drop-down menu

i need to uninstall these plugins because , when it was installed it keep asking me to fill in fields and i can't logon even by administratot
In reply to Mina Attia

Re: Uninstall plugins via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

What version of Moodle?

What is it asking you to fill in?   Could you 'fake it' ... ie, enter something in those fields ... even if in-correct ... and whatever it is won't function or it will throw errors, at least you regain access to admin area where you can properly (via GUI method) remove the plugin.

Alternative (not to be taken lightly and not recommended) is to maniuplate the DB directly.    Check mdl_config_plugins table and remove any reference to the plugin.   Remove any tables in DB related.   Remove directories/files related to plugin in code.

Obviously, if doing alt, backup database and code directory.  Know how to restore them should the alt created other issues.

'SoS', Ken

In reply to Ken Task

Re: Uninstall plugins via CLI

by Mina Attia -
Hello Mr. Ken
1- Bitnami Moodle 3.8.2-2 ,
2- The problem is We have installed conditional profile fields plugin and then even the administrator account cannot log on and keep directed to the "/user/edit.php?id=2&course=1" page each time i try to navigate any page.
3- how can i use Check mdl_config_plugins table and remove any reference to the plugin. Remove any tables in DB related. Remove directories/files related to plugin in code.

Thanks
In reply to Mina Attia

Re: Uninstall plugins via CLI

by Ben Kahn -
Mina, if you have direct access to the DB maybe you could try writing in some values for the admin account for those fields?

I don't know why the CLI uninstall script would not work. It doesn't give any other error output than "cannot uninstall"?

Did you try the "show missing" and "purge-missing" flags to see if that cleared them?
In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Mina Attia -
I've already tried "show missing" and "purge-missing" flags and there is no output. sad
In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Mina Attia -
I've already tried "show missing" and "purge-missing" flags and there is no output. sad
- I can connect to database, can you help me from where i can edit administrator account values ?
- can i create another administrator password have the same privileges of the old administrator first before editing the original admin ?
In reply to Ken Task

Re: Uninstall plugins via CLI

by Mina Attia -

I was able to connect to database and found `mdl_config_plugins`, and here are the tables that the plugins i couldn't uninstall using CLi

Attachment db-02.JPG
Attachment db-03.JPG
In reply to Mina Attia

Re: Uninstall plugins via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

@Mina ... congrats!   Found your work-around for un-installing (never first option to maniuplate DB but in this case, necessary).

Take aways ...

Don't install in-compat versions of plugins ... the plugin in question shows to be compat up to 3.4 and no higher (kinda wonder how it got installed to begin with now ... could it be related to bitnami?

The cli script for removing a plugins, which made appearance in 3.7, may not work when copied to an older version of Moodle (guessing there) ... or could still use some work on plugins that are not compat?)

Anyhoo ... all that ends well! smile

'SoS', Ken

In reply to Ken Task

Re: Uninstall plugins via CLI

by Mina Attia -
Thanks Mr. Ken

Now i can delete these tables, or do such action can negatively affect the service ?

BR, Thanks
In reply to Mina Attia

Re: Uninstall plugins via CLI

by Ken Task -
Picture of Particularly helpful Moodlers
Delete the *rows* in the table ... not the tables!
To the best of my knowledge, if a plugin will not un-install via Admin GUI, the only way to remove it is: 1 remove associated code and 2 remove related *rows* from mdl_config_plugins table.
'SoS', Ken
Average of ratings: Useful (1)
In reply to Ken Task

Re: Uninstall plugins via CLI

by Ben Kahn -
Just chiming back in because I finally got around to trying Moosh. Working on a Moodle 3.6 server that does not have the admin/cli/uninstall_plugins.php script (must have been added 3.7+).
Anyway, I had a nasty site crashing CURL exception coming from a plugin and was able to use:

moosh module-reinstall plugin_name

Which really saved my bacon!

Average of ratings: Useful (1)
In reply to Ben Kahn

Re: Uninstall plugins via CLI

by Steve Howes -
Sorry, newbie question how to use them, because when I try the dry run, I get 'can not be uninstalled: '

I have a local plugin that has no uninstall option, but I need to uninstall so that I can install an updated version. When I try the dry run, I get 'can not be uninstalled: '
In reply to Steve Howes

Re: Uninstall plugins via CLI

by Ken Task -
Picture of Particularly helpful Moodlers

@Steve ...

Move the /local/pluginname out of moodle code.  Unzip the new local plugin zip in /local/.   In mdl_config_plugins table remove rows for old local plugin.

Then install.

'SoS', Ken

In reply to Ken Task

Re: Uninstall plugins via CLI

by Steve Howes -
Thanks Ken, that worked I was just trying to avoid it if I was using php uninstall_plugins.php wrong it or was a permissions issue or something.