Skip to content

Commit

Permalink
Fix 'NOTUPDATED' state after plugin uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored and trasher committed Apr 11, 2019
1 parent b3bfd53 commit 2039040
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
8 changes: 5 additions & 3 deletions inc/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -475,7 +478,6 @@ function uninstall($ID) {
$this->update([
'id' => $ID,
'state' => self::NOTINSTALLED,
'version' => ''
]);
$this->setUnloadedByName($this->fields['directory']);

Expand Down
37 changes: 35 additions & 2 deletions tests/functionnal/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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".
Expand Down

0 comments on commit 2039040

Please sign in to comment.