]> git.koha-community.org Git - koha.git/commit
Bug 29121: Catch errors in ->install and ->upgrade calls on plugins
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Sep 2021 11:24:53 +0000 (08:24 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 1 Oct 2021 14:28:55 +0000 (16:28 +0200)
commit375a9197b1170b92c9cd27e809bb0dcfce050517
treec203a591be55602b9202036fa057ecff36fd1ddf
parentedc8f4933585cae8986e4a1eae58cabf5ba07918
Bug 29121: Catch errors in ->install and ->upgrade calls on plugins

This patch adds a try/catch block when instantiating plugins. Calling
->new on a plugin eventually triggers a call to ->install (this has
always been like this since bug 7804). If the ->install method is
somehow borked, then the process dies. We need to prevent that, and
report back some error took place. That's what this patch does.

The same happens to the ->upgrade.

To test:
1. Install any plugin you like
2. Restart plack (just in case)
=> SUCCESS: All good
3. Manually change its install method to:

sub install {
    die "plugin, die!";
}

4. Run:
   $ koha-mysql kohadev
   > DELETE FROM plugin_data;
(to make sure there's no __INSTALLED__ entry, do on a safe to delete DB).
5. Point your browser to the plugins-home.pl page
=> FAIL: Boom
6. Apply up to the regression tests
7. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Plugins.t \
           t/Koha/Exceptions.t
=> FAIL: Tests fail!
8. Apply this patch
9. Repeat 2
=> SUCCESS: Tests pass!
10. Run:
    $ restart_all
11. Repeat 5
=> SUCCESS: The page is not broken
12. Sign off :-D

Note: I used
    $ kshell
   k$ perl misc/devel/install_plugins.pl
to test as well.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Plugins.pm
Koha/Plugins/Base.pm