From 4e31b968a2fb5297e0594f22a1a8cf1fc9510979 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 24 Oct 2023 11:56:35 +0200 Subject: [PATCH] oum update checks --- .../lib/UpdateManager/Client.php | 58 +++++++++++++++++++ .../required_um_versions.php | 5 ++ 2 files changed, 63 insertions(+) create mode 100644 pandora_console/update_manager_client/required_um_versions.php diff --git a/pandora_console/update_manager_client/lib/UpdateManager/Client.php b/pandora_console/update_manager_client/lib/UpdateManager/Client.php index 42d9e6367a..678c0e7320 100644 --- a/pandora_console/update_manager_client/lib/UpdateManager/Client.php +++ b/pandora_console/update_manager_client/lib/UpdateManager/Client.php @@ -1246,6 +1246,40 @@ class Client } + /** + * Compare version strings. + * + * @param string $version1 Version1. + * @param string $version2 Version2. + * + * @return array + * @throws \Exception On error. + */ + private function compareVersions(string $version1, string $version2):int + { + $v1_components = explode('.', $version1); + $v2_components = explode('.', $version2); + + $maxLength = max(count($v1_components), count($v2_components)); + + for ($i = 0; $i < $maxLength; $i++) { + $v1_part = isset($v1_components[$i]) === true ? intval($v1_components[$i]) : 0; + $v2_part = isset($v2_components[$i]) === true ? intval($v2_components[$i]) : 0; + + if ($v1_part < $v2_part) { + // $version1 is older. + return -1; + } else if ($v1_part > $v2_part) { + // $version1 is newer. + return 1; + } + } + + // Versions are identical. + return 0; + } + + /** * Update files. * @@ -1284,6 +1318,30 @@ class Client throw new \Exception('Files are not readable'); } + // External path to required versions file. + $filepath = $this->tmpDir.'/downloads/'.$version.'/required_um_versions.php'; + + if (file_exists($filepath) === true) { + include $filepath; + + $curr_php_version = phpversion(); + $curr_mysql_version = db_get_value_sql('SELECT VERSION() AS version'); + + if (isset($php_version) === true + && is_string($php_version) === true + && $this->compareVersions($curr_php_version, $php_version) < 0 + ) { + throw new \Exception('PHP version >= '.$php_version.' is required'); + } + + if (isset($mysql_version) === true + && is_string($mysql_version) === true + && $this->compareVersions($curr_mysql_version, $mysql_version) < 0 + ) { + throw new \Exception('MySQL version >= '.$mysql_version.' is required'); + } + } + $created_directories = []; while (($pf = readdir($pd)) !== false) { diff --git a/pandora_console/update_manager_client/required_um_versions.php b/pandora_console/update_manager_client/required_um_versions.php new file mode 100644 index 0000000000..52345d521b --- /dev/null +++ b/pandora_console/update_manager_client/required_um_versions.php @@ -0,0 +1,5 @@ +