https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36650 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 209869 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209869&action=edit Bug 36650: Prevent uninstalling ILL backend plugins with existing requests This patch adds a generic `can_uninstall` method to Koha::Plugins::Base. It returns a Koha::Result::Boolean carrying Koha::Object::Message objects that explain why the plugin cannot be uninstalled. For now it only checks if the plugin is an ILL backend with ILL requests using it, regardless of their status, as any request can be opened in the UI and would fail to load the missing backend. More checks can be added later, and plugins can override it. Koha::Plugins::Handler->delete now calls `can_uninstall` before running the plugin's `uninstall` method, and throws the new Koha::Exceptions::Plugin::CannotUninstall exception if it returns false. Nothing is removed in that case. On the plugins page: - Plugins that cannot be uninstalled display a lock badge next to their name, with the (translatable) reasons on a tooltip. - The 'Uninstall' action is disabled and the reasons are displayed below it. - If the uninstall URL is used anyway, the user is redirected back to the plugins page and an alert explains why it was not uninstalled. Test plan: 1. Apply patch 2. Install the test ILL backend plugin and create an ILL request: $ ktd --shell k$ mkdir -p /var/lib/koha/kohadev/plugins/Koha/Plugin/ILL k$ cp t/lib/plugins/Koha/Plugin/BackendClass.pm \ /var/lib/koha/kohadev/plugins/Koha/Plugin/ k$ cp t/lib/plugins/Koha/Plugin/ILL/TestClass.pm \ /var/lib/koha/kohadev/plugins/Koha/Plugin/ILL/ k$ perl misc/devel/install_plugins.pl k$ perl -MKoha::ILL::Request -MKoha::Patrons -e 'my $p = Koha::Patrons->search->next; Koha::ILL::Request->new({ borrowernumber => $p->id, branchcode => $p->branchcode, backend => "BackendClass", status => "COMP" })->store' k$ restart_all 3. Go to Administration > Manage plugins => SUCCESS: BackendClass displays a lock badge next to its name 4. Hover the lock badge => SUCCESS: The tooltip reads "Cannot be uninstalled: 1 ILL request uses this backend." 5. Open the 'Actions' menu for BackendClass => SUCCESS: 'Uninstall' is disabled, the reason is displayed below it 6. Point your browser to: /cgi-bin/koha/plugins/plugins-uninstall.pl?class=Koha::Plugin::BackendClass => SUCCESS: You are redirected to the plugins page, an alert explains the plugin cannot be uninstalled => SUCCESS: The plugin is still listed 7. Delete the ILL request: k$ koha-mysql kohadev -e 'DELETE FROM illrequests WHERE backend="BackendClass"' 8. Reload the plugins page => SUCCESS: No lock badge, 'Uninstall' is available 9. Uninstall BackendClass => SUCCESS: The plugin is uninstalled 10. Run: k$ prove t/db_dependent/Koha/Plugins/ILL/Backends.t \ t/db_dependent/Koha/Plugins/Plugins.t => SUCCESS: Tests pass! 11. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.