diff --git a/inc/plugin.class.php b/inc/plugin.class.php index 2d86ce02dd1..47136fd13b0 100644 --- a/inc/plugin.class.php +++ b/inc/plugin.class.php @@ -357,11 +357,14 @@ public function checkPluginState($directory) { if ($informations['version'] != $plugin->fields['version'] || $directory != $plugin->fields['directory']) { // Plugin known version differs from informations or plugin has been renamed, - // mark it as 'updatable' + // update informations in database $input = $informations; $input['id'] = $plugin->fields['id']; $input['directory'] = $directory; - $input['state'] = self::NOTUPDATED; + if (!in_array($plugin->fields['state'], [self::ANEW, self::NOTINSTALLED])) { + // mark it as 'updatable' unless it was not installed + $input['state'] = self::NOTUPDATED; + } $this->update($input); @@ -475,7 +478,6 @@ function uninstall($ID) { $this->update([ 'id' => $ID, 'state' => self::NOTINSTALLED, - 'version' => '' ]); $this->setUnloadedByName($this->fields['directory']); diff --git a/tests/functionnal/Plugin.php b/tests/functionnal/Plugin.php index 2975d1a2f67..3f06658c5ff 100644 --- a/tests/functionnal/Plugin.php +++ b/tests/functionnal/Plugin.php @@ -362,10 +362,11 @@ public function testCheckPluginStateForNewPlugin() { } /** - * Test state checking on a valid directory corresponding to a known plugin with a different version. + * Test state checking on a valid directory corresponding to a known and installed plugin + * with a different version. * Should results in changing plugin state to "NOTUPDATED". */ - public function testCheckPluginStateForUpdatablePlugin() { + public function testCheckPluginStateForInstalledAndUpdatablePlugin() { $initial_data = [ 'directory' => $this->test_plugin_directory, @@ -392,6 +393,38 @@ public function testCheckPluginStateForUpdatablePlugin() { ); } + /** + * Test state checking on a valid directory corresponding to a known and NOT installed plugin + * with a different version. + * Should results in keeping plugin state to "NOTINSTALLED". + */ + public function testCheckPluginStateForNotInstalledAndUpdatablePlugin() { + + $initial_data = [ + 'directory' => $this->test_plugin_directory, + 'name' => 'Test plugin', + 'version' => '1.0', + 'state' => \Plugin::NOTINSTALLED, + ]; + $setup_informations = [ + 'name' => 'Test plugin NG', + 'version' => '2.0', + ]; + $expected_data = array_merge( + $initial_data, + $setup_informations, + [ + 'state' => \Plugin::NOTINSTALLED, + ] + ); + + $this->doTestCheckPluginState( + $initial_data, + $setup_informations, + $expected_data + ); + } + /** * Test state checking on a valid directory corresponding to a known plugin that has been renamed. * Should results in changing plugin directory to new value and state to "NOTUPDATED".