[Bug 36650] New: When uninstalling an ILL backend plugin, check if it can be uninstalled
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36650 Bug ID: 36650 Summary: When uninstalling an ILL backend plugin, check if it can be uninstalled Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Plugin architecture Assignee: koha-bugs@lists.koha-community.org Reporter: pedro.amorim@ptfs-europe.com QA Contact: testopia@bugs.koha-community.org Depends on: 19605 If ILL requests of a specific plugin backend exist, we should prevent uninstalling that plugin and show an appropriate message, e.g: "ILL requests exist in this backend, uninstalling it is not possible" Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19605 [Bug 19605] ILL backends should be pluggable through regular Koha plugins -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36650 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 209870 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209870&action=edit Bug 36650: (follow-up) Allow uninstall reasons to provide links This patch makes it possible for each reason returned by Koha::Plugins::Base->can_uninstall to provide its own link: - Reasons defined in Koha build their links in the template, which already maps message codes to translatable text, and can decide whether the link should be displayed (e.g. user permissions). To allow this, the payload for 'ill_requests_exist' now also contains the 'backend' name. - Reasons added by plugins overriding `can_uninstall` can provide optional 'text' and 'url' keys in their payload, as core templates cannot know about them. Previously the raw message code was displayed. This is documented in the method POD. The 'cannot_uninstall_reasons' template block now takes a 'with_links' parameter: plain text is still used for the lock badge tooltip, links are rendered in the 'Actions' menu and the alert. Each reason is displayed on its own line there. Test plan: 1. Apply patch 2. Set up the BackendClass plugin with an ILL request as in the previous patch test plan 3. Add this method to the installed copy of the plugin (/var/lib/koha/kohadev/plugins/Koha/Plugin/BackendClass.pm), before the trailing '1;': sub can_uninstall { my ($self) = @_; my $result = $self->SUPER::can_uninstall; $result->set_value(0)->add_message( { message => 'pending_things', payload => { text => 'There are pending things', url => '/cgi-bin/koha/plugins/plugins-home.pl?method=ill_backend', } } ); $result->add_message( { message => 'no_text_reason' } ); return $result; } 4. Restart services: $ ktd --shell k$ restart_all 5. Go to Administration > Manage plugins and hover the lock badge => SUCCESS: The tooltip lists the three reasons, as plain text 6. Open the 'Actions' menu for BackendClass => SUCCESS: Each reason is displayed on its own line => SUCCESS: 'There are pending things' is a link => SUCCESS: 'no_text_reason' is displayed as-is (no 'text' provided) 7. Point your browser to: /cgi-bin/koha/plugins/plugins-uninstall.pl?class=Koha::Plugin::BackendClass => SUCCESS: The alert displays the same reasons and link as step 6 8. Run: k$ prove t/db_dependent/Koha/Plugins/ILL/Backends.t => SUCCESS: Tests pass! 9. 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36650 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org