From b19b36fb6260932dff3961ec9ed1202188d367de Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 8 Jan 2019 13:10:53 -0500 Subject: [PATCH] Bug 22084: Plugin upgrade method and database plugin version storage will never be triggered for existing installs If an existing plugin begins using the upgrade() method, it will never actually get triggered because the installation has already occurred and no database plugin version was stored at the time. Without that database version, the upgrade method will never be triggered. In addition, if the plugin has no upgrade method, the installed version is never updated in the database! Lastly, when an upgrade succeeds it prints a warning that the upgrade failed. Test Plan: 1) Install an older version of the Kitchen sink plugin: * https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases/download/v2.1.0/koha-plugin-kitchen-sink-v2.1.0.kpz 2) Delete the "__INSTALLED_VERSION__" key, and the "last_upgraded" key from plugin_data for this plugin, to simulate having installed from an earlier version of Koha 3) Upgrade to the latest version of the Kitchen sink plugin: * https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases/download/v2.1.22/koha-plugin-kitchen-sink-v2.1.22.kpz 4) Note "__INSTALLED_VERSION__" still doesn't exist for the plugin, in the plugin_data table 5) Apply this patch 6) Restart all the things 7) Browse to the Kitchen sink configuration page, this should trigger the upgrade method 8) Note the "__INSTALLED_VERSION__" and "last_upgraded" keys exist in plugin_data for the Kitchen Sink plugin Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens (cherry picked from commit 8c2e03020dc02519dec70b9697794a3624c73937) Signed-off-by: Martin Renvoize --- Koha/Plugins/Base.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm index ed87253a02..2cebe636d9 100644 --- a/Koha/Plugins/Base.pm +++ b/Koha/Plugins/Base.pm @@ -45,7 +45,7 @@ sub new { my $self = bless( $args, $class ); my $plugin_version = $self->get_metadata->{version}; - my $database_version = $self->retrieve_data('__INSTALLED_VERSION__'); + my $database_version = $self->retrieve_data('__INSTALLED_VERSION__') || 0; ## Run the installation method if it exists and hasn't been run before if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) { @@ -57,13 +57,16 @@ sub new { } else { warn "Plugin $class failed during installation!"; } - } elsif ( $self->can('upgrade') && $plugin_version && $database_version ) { + } elsif ( $self->can('upgrade') ) { if ( _version_compare( $plugin_version, $database_version ) == 1 ) { if ( $self->upgrade() ) { $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version }); + } else { warn "Plugin $class failed during upgrade!"; } } + } elsif ( $plugin_version ne $database_version ) { + $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version }); } return $self; -- 2.39.5