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 replace history #115

Merged
merged 3 commits into from
Apr 25, 2021
Merged
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
45 changes: 44 additions & 1 deletion modules/system/classes/VersionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,38 @@ public function replacePlugin(PluginBase $plugin, string $replace)
return;
}

$code = $plugin->getPluginIdentifier();

// add history up to $currentVersion
if ($versions = $this->getOldFileVersions($code, $currentVersion)) {
foreach ($versions as $version => $details) {
list($comments, $scripts) = $this->extractScriptsAndComments($details);
$now = now()->toDateTimeString();

foreach ($scripts as $script) {
Db::table('system_plugin_history')->insert([
'code' => $code,
'type' => self::HISTORY_TYPE_SCRIPT,
'version' => $version,
'detail' => $script,
'created_at' => $now,
]);
}

foreach ($comments as $comment) {
$this->applyDatabaseComment($code, $version, $comment);
}
}
}

// delete replaced plugin history
Db::table('system_plugin_history')->where('code', $replace)->delete();

// replace installed version
Db::table('system_plugin_versions')
->where('code', '=', $replace)
->update([
mjauvin marked this conversation as resolved.
Show resolved Hide resolved
'code' => $plugin->getPluginIdentifier()
'code' => $code
]);
}

Expand Down Expand Up @@ -277,6 +305,21 @@ protected function getLatestFileVersion($code)
return trim(key(array_slice($versionInfo, -1, 1)));
}

/**
* Returns older versions up to a supplied version, ie. applied versions.
*/
protected function getOldFileVersions($code, $version = null)
{
if ($version === null) {
$version = self::NO_VERSION_VALUE;
}

$versions = $this->getFileVersions($code);
$position = array_search($version, array_keys($versions));

return array_slice($versions, 0, ++$position);
}

/**
* Returns any new versions from a supplied version, ie. unapplied versions.
*/
Expand Down