Revert "refactor: Simplify plugin processing logic by replacing 'download_only' variable with 'download_mode'. Update related conditions for clarity and consistency in plugin installation and downloading behavior."

This reverts commit 3ac24e47af.
This commit is contained in:
Eli Bosley
2025-11-24 10:40:09 -05:00
parent f276a0c772
commit d350257753

View File

@@ -294,11 +294,7 @@ function filter_url($url) {
// is processed for any of those methods.
//
function plugin($method, $plugin_file, &$error) {
global $unraid, $logger;
$download_mode = ($method === 'download');
if ($download_mode) {
$method = 'install';
}
global $unraid, $logger, $download_only;
$methods = ['install', 'remove'];
// parse plugin definition XML file
@@ -468,7 +464,7 @@ function plugin($method, $plugin_file, &$error) {
//
if ($file->attributes()->Run) {
$command = $file->attributes()->Run;
if ($download_mode) {
if ($download_only) {
$target = $name ?: ($file->LOCAL ?: 'inline script');
my_logger("skipping run: $command $target - download-only mode", $logger);
continue;
@@ -506,6 +502,7 @@ $notify = '/usr/local/emhttp/webGui/scripts/notify';
$boot = '/boot/config/plugins';
$plugins = '/var/log/plugins';
$tmp = '/tmp/plugins';
$download_only = false;
$script = $argv[0];
$method = $argv[1];
$optional_args = array_slice($argv, 2);
@@ -611,8 +608,8 @@ if ($method == 'install' || $method == 'download') {
$argv[2] = preg_replace('#[\x00-\x1F\x80-\xFF]#', '', $argv[2]);
$plugin = basename($argv[2]);
$options = array_slice($argv, 3);
$is_download = ($method === 'download');
if (!$is_download) {
$download_only = ($method === 'download');
if (!$download_only) {
$legacy_download_flags = array_intersect($options, ['download-only', 'download']);
if (!empty($legacy_download_flags)) {
write("plugin: use 'plugin download' instead of 'plugin install ... download-only'\n");
@@ -625,16 +622,16 @@ if ($method == 'install' || $method == 'download') {
write("plugin: $plugin is not a plg file\n");
done(1);
}
if ($is_download) {
if ($download_only) {
write("plugin: download-only mode enabled, skipping install commands\n");
}
$action = $is_download ? 'downloading' : 'installing';
$action = $download_only ? 'downloading' : 'installing';
write("plugin: $action: $plugin\n");
// check for URL
if (preg_match('#^https?://#',$argv[2])) {
$pluginURL = $argv[2];
// run hook scripts for pre processing
if (!$is_download) {
if (!$download_only) {
pre_hooks();
}
$plugin_file = "$tmp/$plugin";
@@ -643,7 +640,7 @@ if ($method == 'install' || $method == 'download') {
write("plugin: $error\n");
@unlink($plugin_file);
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -659,7 +656,7 @@ if ($method == 'install' || $method == 'download') {
move($plugin_file, "$boot-error");
}
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -671,7 +668,7 @@ if ($method == 'install' || $method == 'download') {
move($plugin_file, "$boot-error");
}
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -683,7 +680,7 @@ if ($method == 'install' || $method == 'download') {
if ($plugin_file == $installed_plugin_file) {
write("plugin: not re-installing same plugin\n");
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -693,7 +690,7 @@ if ($method == 'install' || $method == 'download') {
if ($version === false) {
write("plugin: $error\n");
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -702,7 +699,7 @@ if ($method == 'install' || $method == 'download') {
if ($installed_version === false) {
write("plugin: $error\n");
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -713,7 +710,7 @@ if ($method == 'install' || $method == 'download') {
if (strcmp($version, $installed_version) < 0) {
write("plugin: not installing older version\n");
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -721,17 +718,17 @@ if ($method == 'install' || $method == 'download') {
if (strcmp($version, $installed_version) === 0) {
write("plugin: not reinstalling same version\n");
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
}
}
// run hook scripts for pre processing
if (!$is_download) {
if (!$download_only) {
pre_hooks();
}
if (plugin($method, $plugin_file, $error) === false) {
if (plugin('install', $plugin_file, $error) === false) {
write("plugin: $error\n");
if (dirname($plugin_file) == "$boot") {
move($plugin_file, "$boot-error");
@@ -741,7 +738,7 @@ if ($method == 'install' || $method == 'download') {
$description = "Plugin failed to install";
exec("$notify -e ".escapeshellarg($event)." -s ".escapeshellarg($subject)." -d ".escapeshellarg($description)." -i 'warning'");
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -750,17 +747,17 @@ if ($method == 'install' || $method == 'download') {
unlink($symlink);
} else {
// run hook scripts for pre processing
if (!$is_download) {
if (!$download_only) {
pre_hooks();
}
// fresh install
if (plugin($method, $plugin_file, $error) === false) {
if (plugin('install', $plugin_file, $error) === false) {
write("plugin: $error\n");
if (dirname($plugin_file) == "$boot") {
move($plugin_file, "$boot-error");
}
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks($error);
}
done(1);
@@ -771,16 +768,16 @@ if ($method == 'install' || $method == 'download') {
if (!plugin('noInstall', $plugin_file, $error)) {
if ($target != $plugin_file) copy($plugin_file, $target);
symlink($target, $symlink);
$status = $is_download ? 'downloaded' : 'installed';
$status = $download_only ? 'downloaded' : 'installed';
write("plugin: $plugin $status\n");
my_logger("$plugin $status", $logger);
} else {
$script_action = $is_download ? 'staged' : 'executed';
$script_action = $download_only ? 'staged' : 'executed';
write("script: $plugin $script_action\n");
my_logger("script: $plugin $script_action", $logger);
}
// run hook scripts for post processing
if (!$is_download) {
if (!$download_only) {
post_hooks();
}
done(0);