From 8c9abba2e282882758058ea60112c013bc26ba54 Mon Sep 17 00:00:00 2001 From: "Ernesto Serrano (aider)" Date: Sat, 19 Oct 2024 16:04:22 +0100 Subject: [PATCH 1/5] feat: Add support for installing plugins from URL with type parameter --- .../var/www/html/admin/cli/install_plugin.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/rootfs/var/www/html/admin/cli/install_plugin.php b/rootfs/var/www/html/admin/cli/install_plugin.php index ba57142..35495a3 100644 --- a/rootfs/var/www/html/admin/cli/install_plugin.php +++ b/rootfs/var/www/html/admin/cli/install_plugin.php @@ -12,6 +12,7 @@ -h --help Print this help. --plugin= The name of the plugin to install. --url= The URL to download the plugin from. + --type= The type of the plugin (e.g., mod, block, filter, theme, local). Defaults to mod. --run Execute install. If this option is not set, the script will run in dry mode. --force Force install even if plugin exists (useful for development). --showsql Show SQL queries before they are executed. @@ -32,6 +33,7 @@ 'help' => false, 'plugin' => false, 'url' => false, + 'type' => 'mod', // Default plugin type 'run' => false, 'force' => false, 'showsql' => false, @@ -96,6 +98,16 @@ cli_error('Failed to detect plugin name.'); } + $destination = detect_and_move_plugin($pluginname, "$tempdir/$rootdir", $options['type']); + if (!$destination) { + cli_error('Failed to move plugin to the correct directory.'); + } + + $destination = detect_and_move_plugin($pluginname, $pluginDir, $options['type']); + if (!$destination) { + cli_error('Failed to move plugin to the correct directory.'); + } + $plugins[] = (object)[ 'component' => $pluginname, 'zipfilepath' => $tempfile, @@ -226,9 +238,10 @@ function detect_plugin_name($dir) { * * @param string $pluginname Name of the plugin. * @param string $sourcepath Path to the extracted plugin. + * @param string $type The type of the plugin. * @return bool|string Returns the new path of the plugin if successful, or false on failure. */ -function detect_and_move_plugin($pluginname, $sourcepath) { +function detect_and_move_plugin($pluginname, $sourcepath, $type) { global $CFG; // Define the base paths for different plugin types @@ -240,10 +253,9 @@ function detect_and_move_plugin($pluginname, $sourcepath) { // Add other plugin types as needed ]; - // Attempt to detect the plugin type based on the name or folder structure - foreach ($plugin_types as $type => $path) { - if (strpos($pluginname, $type . '_') === 0) { - $destination = $path . basename($sourcepath); + // Use the provided type to determine the destination path + if (array_key_exists($type, $plugin_types)) { + $destination = $plugin_types[$type] . basename($sourcepath); // Ensure the directory is writable before moving the plugin if (!is_writable($path)) { @@ -260,8 +272,8 @@ function detect_and_move_plugin($pluginname, $sourcepath) { } } - // If the plugin type cannot be detected - cli_error("Unknown plugin type for $pluginname. Plugin was not moved."); + // If the plugin type is not recognized + cli_error("Unknown plugin type: $type. Plugin was not moved."); return false; } From ac0fa2ed8251c45bf1fb4431f3de8565f9cd4cf4 Mon Sep 17 00:00:00 2001 From: "Ernesto Serrano (aider)" Date: Sat, 19 Oct 2024 16:04:29 +0100 Subject: [PATCH 2/5] fix: Correct closing bracket for if statement in detect_and_move_plugin function --- .../var/www/html/admin/cli/install_plugin.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/rootfs/var/www/html/admin/cli/install_plugin.php b/rootfs/var/www/html/admin/cli/install_plugin.php index 35495a3..3a756ab 100644 --- a/rootfs/var/www/html/admin/cli/install_plugin.php +++ b/rootfs/var/www/html/admin/cli/install_plugin.php @@ -257,18 +257,17 @@ function detect_and_move_plugin($pluginname, $sourcepath, $type) { if (array_key_exists($type, $plugin_types)) { $destination = $plugin_types[$type] . basename($sourcepath); - // Ensure the directory is writable before moving the plugin - if (!is_writable($path)) { - cli_error("Directory $path is not writable. Check permissions."); - } - - // Move the plugin to the correct directory - if (rename($sourcepath, $destination)) { - cli_writeln("Plugin moved to $destination."); - return $destination; - } else { - return false; - } + // Ensure the directory is writable before moving the plugin + if (!is_writable($destination)) { + cli_error("Directory $destination is not writable. Check permissions."); + } + + // Move the plugin to the correct directory + if (rename($sourcepath, $destination)) { + cli_writeln("Plugin moved to $destination."); + return $destination; + } else { + return false; } } From 314d79d260ae8d93a334e81136a48d2bcf3c2557 Mon Sep 17 00:00:00 2001 From: "Ernesto Serrano (aider)" Date: Sat, 19 Oct 2024 19:04:13 +0100 Subject: [PATCH 3/5] feat: Add --debug option to enable detailed error messages in plugin manager --- rootfs/var/www/html/admin/cli/install_plugin.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rootfs/var/www/html/admin/cli/install_plugin.php b/rootfs/var/www/html/admin/cli/install_plugin.php index 3a756ab..9955fda 100644 --- a/rootfs/var/www/html/admin/cli/install_plugin.php +++ b/rootfs/var/www/html/admin/cli/install_plugin.php @@ -15,6 +15,7 @@ --type= The type of the plugin (e.g., mod, block, filter, theme, local). Defaults to mod. --run Execute install. If this option is not set, the script will run in dry mode. --force Force install even if plugin exists (useful for development). + --debug Enable debug mode to see detailed error messages. --showsql Show SQL queries before they are executed. --showdebugging Show developer level debugging information. @@ -37,6 +38,7 @@ 'run' => false, 'force' => false, 'showsql' => false, + 'debug' => false, 'showdebugging' => false, ], [ 'h' => 'help' @@ -47,6 +49,11 @@ cli_error(get_string('cliunknowoption', 'core_admin', $unrecognised)); } +if ($options['debug']) { + set_debugging(DEBUG_DEVELOPER, true); + cli_writeln('Debug mode enabled.'); +} + if ($options['help']) { cli_writeln($help); exit(0); From 047c51a909e479a57c164e33c089f11626288cf5 Mon Sep 17 00:00:00 2001 From: "Ernesto Serrano (aider)" Date: Sat, 19 Oct 2024 19:22:06 +0100 Subject: [PATCH 4/5] feat: Require URL for plugin installation and remove plugin name option --- .../var/www/html/admin/cli/install_plugin.php | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/rootfs/var/www/html/admin/cli/install_plugin.php b/rootfs/var/www/html/admin/cli/install_plugin.php index 9955fda..e24e2bc 100644 --- a/rootfs/var/www/html/admin/cli/install_plugin.php +++ b/rootfs/var/www/html/admin/cli/install_plugin.php @@ -10,7 +10,6 @@ Options: -h --help Print this help. - --plugin= The name of the plugin to install. --url= The URL to download the plugin from. --type= The type of the plugin (e.g., mod, block, filter, theme, local). Defaults to mod. --run Execute install. If this option is not set, the script will run in dry mode. @@ -67,8 +66,8 @@ $DB->set_debug(true); } -if (!$options['plugin'] && !$options['url']) { - cli_writeln('You must specify either a plugin name or a URL.'); +if (!$options['url']) { + cli_writeln('You must specify a URL to download the plugin.'); cli_writeln($help); exit(0); } @@ -119,27 +118,6 @@ 'component' => $pluginname, 'zipfilepath' => $tempfile, ]; -} else { - $pluginDir = $CFG->dirroot . '/mod/' . $options['plugin']; - - $plugininfo = get_plugin_info_from_version_file($pluginDir); - if (!$plugininfo) { - cli_error('Invalid plugin directory: ' . $pluginDir); - } - - $pluginname = $plugininfo->component; - cli_writeln("Preparing to install plugin: $pluginname"); - - // Check if the plugin is already installed, unless forced - if ($pluginman->get_plugin_info($pluginname) && !$options['force']) { - cli_error("Plugin $pluginname is already installed. Use --force to reinstall."); - } - - $plugins[] = (object)[ - 'component' => $pluginname, - 'zipfilepath' => null, - ]; -} if ($options['run']) { cli_writeln('Installing plugin...'); From 1b4fb86455ec1b55046ba0d711c96ab535d8b886 Mon Sep 17 00:00:00 2001 From: Ernesto Serrano Date: Sun, 20 Oct 2024 10:35:08 +0100 Subject: [PATCH 5/5] Fixed pipeline and improved plugin install script --- .github/workflows/check-moodle-version.yml | 3 ++- .gitignore | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-moodle-version.yml b/.github/workflows/check-moodle-version.yml index 3f93a07..199465e 100644 --- a/.github/workflows/check-moodle-version.yml +++ b/.github/workflows/check-moodle-version.yml @@ -24,7 +24,8 @@ jobs: - name: Get Current Version from Git Tags id: get_current_version run: | - CURRENT_VERSION=$(git tag | sort -V | tail -n 1) + # Get the latest stable tag (no pre-release) + CURRENT_VERSION=$(git tag | grep -vE '(-rc|-beta|-alpha)' | sort -V | tail -n 1) echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV - name: Compare Versions diff --git a/.gitignore b/.gitignore index 9b554a8..7bb5ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /Persistent .data .DS_Store +.aider*