Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Plugin warnings only shown for active replacements #122

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/system/classes/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class PluginManager
*/
protected $replacementMap = [];

/**
* @var array A map of plugins that are currently replaced [Original.Plugin => Replacement.Plugin]
*/
protected $activeReplacementMap = [];

/**
* @var bool Flag to indicate that all plugins have had the register() method called by registerAll() being called on this class.
*/
Expand Down Expand Up @@ -686,6 +691,19 @@ public function getReplacementMap()
return $this->replacementMap;
}

/**
* Returns the actively replaced plugins defined in $this->activeReplacementMap
* @param string $pluginIdentifier Plugin code/namespace
* @return array|null
*/
public function getActiveReplacementMap(string $pluginIdentifier = null)
{
if (!$pluginIdentifier) {
return $this->activeReplacementMap;
}
return $this->activeReplacementMap[$pluginIdentifier] ?? null;
}

/**
* Evaluates and initializes the plugin replacements defined in $this->replacementMap
*
Expand All @@ -710,6 +728,8 @@ public function registerReplacedPlugins()
$this->aliasPluginAs($replacement, $target);
$this->disablePlugin($target);
$this->enablePlugin($replacement);
// Register this plugin as actively replaced
$this->activeReplacementMap[$target] = $replacement;
} else {
$this->disablePlugin($replacement);
$this->enablePlugin($target);
Expand Down
6 changes: 4 additions & 2 deletions modules/system/classes/UpdateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ public function update()

// Set replacement warning messages
foreach ($this->pluginManager->getReplacementMap() as $alias => $plugin) {
$this->addMessage($plugin, Lang::get('system::lang.updates.update_warnings_plugin_replace_cli', [
if ($this->pluginManager->getActiveReplacementMap($alias)) {
$this->addMessage($plugin, Lang::get('system::lang.updates.update_warnings_plugin_replace_cli', [
'alias' => '<info>' . $alias . '</info>'
]));
]));
}
}

// Print messages returned by migrations / seeders
Expand Down
10 changes: 6 additions & 4 deletions modules/system/controllers/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ protected function getWarnings()
$replacementMap = PluginManager::instance()->getReplacementMap();

foreach ($replacementMap as $alias => $plugin) {
$warnings[] = Lang::get('system::lang.updates.update_warnings_plugin_replace', [
'plugin' => '<strong>' . $plugin . '</strong>',
'alias' => '<strong>' . $alias . '</strong>'
]);
if (PluginManager::instance()->getActiveReplacementMap($alias)) {
$warnings[] = Lang::get('system::lang.updates.update_warnings_plugin_replace', [
'plugin' => '<strong>' . $plugin . '</strong>',
'alias' => '<strong>' . $alias . '</strong>'
]);
}
}

return $warnings;
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/system/classes/PluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,14 @@ public function testReplaceVersion()
$this->assertTrue($replacementPlugin->canReplacePlugin('Winter.Original', '1.0'));
$this->assertFalse($replacementPlugin->canReplacePlugin('Winter.Original', '2.0.1'));
}

public function testActiveReplacementMap()
{
$map = $this->manager->getActiveReplacementMap();
$this->assertArrayHasKey('Winter.Original', $map);
$this->assertEquals('Winter.Replacement', $map['Winter.Original']);

$this->assertEquals('Winter.Replacement', $this->manager->getActiveReplacementMap('Winter.Original'));
$this->assertNull($this->manager->getActiveReplacementMap('Winter.InvalidReplacement'));
}
}