Commit 2039040a authored by Cédric Anne's avatar Cédric Anne Committed by Johan Cwiklinski

Fix 'NOTUPDATED' state after plugin uninstall

parent b3bfd532
......@@ -357,11 +357,14 @@ class Plugin extends CommonDBTM {
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 @@ class Plugin extends CommonDBTM {
$this->update([
'id' => $ID,
'state' => self::NOTINSTALLED,
'version' => ''
]);
$this->setUnloadedByName($this->fields['directory']);
......
......@@ -362,10 +362,11 @@ class Plugin extends DbTestCase {
}
/**
* 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 @@ class Plugin extends DbTestCase {
);
}
/**
* 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".
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment