From 450c682e7fa9a92093410644cd4835b10971b5cc Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Thu, 28 Apr 2022 17:42:41 +0200 Subject: [PATCH] try to fix github actions with new install/froxlor.sql.php; migrate update-functions into class Signed-off-by: Michael Kaufmann --- .github/workflows/build-mariadb.yml | 5 +- .github/workflows/build-mysql.yml | 8 +- .travis.yml | 64 ----------- install/lib/updateFunctions.php | 84 --------------- .../updates/froxlor/0.11/update_0.11.inc.php | 40 +++---- install/updates/preconfig.php | 9 +- install/updatesql.php | 31 +++--- lib/Froxlor/Install/Update.php | 100 ++++++++++++++++++ 8 files changed, 152 insertions(+), 189 deletions(-) delete mode 100644 .travis.yml delete mode 100644 install/lib/updateFunctions.php create mode 100644 lib/Froxlor/Install/Update.php diff --git a/.github/workflows/build-mariadb.yml b/.github/workflows/build-mariadb.yml index 2808dd6e..4c13b709 100644 --- a/.github/workflows/build-mariadb.yml +++ b/.github/workflows/build-mariadb.yml @@ -19,7 +19,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} tools: composer:v2 - extensions: mbstring, xml, ctype, pdo_mysql, mysql, curl, json, zip, session, filter, posix, openssl, fileinfo, bcmath + extensions: mbstring, xml, ctype, pdo_mysql, mysql, curl, json, zip, session, filter, posix, openssl, fileinfo, bcmath, gmp - name: Install tools run: sudo apt-get install -y ant @@ -43,7 +43,8 @@ jobs: run: | mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "CREATE USER 'froxlor010'@'%' IDENTIFIED BY 'fr0xl0r.TravisCI';" mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "GRANT ALL ON froxlor010.* TO 'froxlor010'@'%';" - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < install/froxlor.sql + php -r "echo include('install/froxlor.sql.php');" > /tmp/froxlor.sql + mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < /tmp/froxlor.sql - name: Run testing run: ant quick-build diff --git a/.github/workflows/build-mysql.yml b/.github/workflows/build-mysql.yml index 1bee12cf..7e3f4fe9 100644 --- a/.github/workflows/build-mysql.yml +++ b/.github/workflows/build-mysql.yml @@ -19,7 +19,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} tools: composer:v2 - extensions: mbstring, xml, ctype, pdo_mysql, mysql, curl, json, zip, session, filter, posix, openssl, fileinfo, bcmath + extensions: mbstring, xml, ctype, pdo_mysql, mysql, curl, json, zip, session, filter, posix, openssl, fileinfo, bcmath, gmp - name: Install tools run: sudo apt-get install -y ant @@ -44,14 +44,16 @@ jobs: run: | mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "CREATE USER 'froxlor010'@'%' IDENTIFIED WITH mysql_native_password BY 'fr0xl0r.TravisCI';" mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "GRANT ALL ON froxlor010.* TO 'froxlor010'@'%';" - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < install/froxlor.sql + php -r "echo include('install/froxlor.sql.php');" > /tmp/froxlor.sql + mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < /tmp/froxlor.sql - name: Setup database (5.7) if: matrix.mysql-version == '5.7' run: | mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "CREATE USER 'froxlor010'@'%' IDENTIFIED BY 'fr0xl0r.TravisCI';" mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "GRANT ALL ON froxlor010.* TO 'froxlor010'@'%';" - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < install/froxlor.sql + php -r "echo include('install/froxlor.sql.php');" > /tmp/froxlor.sql + mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < /tmp/froxlor.sql - name: Run testing run: ant quick-build diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e0cb1aa3..00000000 --- a/.travis.yml +++ /dev/null @@ -1,64 +0,0 @@ -language: php -dist: bionic -services: - - docker -php: - - 7.3 - -branches: - only: - - master - - namespaces - -matrix: - include: - - php: 7.3 - env: "DOCKER_MYSQL_TYPE=mysql DOCKER_MYSQL_VERSION=5.6" - - php: 7.3 - env: "DOCKER_MYSQL_TYPE=mysql DOCKER_MYSQL_VERSION=5.7" - - php: 7.3 - env: "DOCKER_MYSQL_TYPE=mysql DOCKER_MYSQL_VERSION=8.0 STARTCMD='mysqld --default-authentication-plugin=mysql_native_password'" - - php: 7.3 - env: "DOCKER_MYSQL_TYPE=mariadb DOCKER_MYSQL_VERSION=10.3" - - php: 7.3 - env: "DOCKER_MYSQL_TYPE=mariadb DOCKER_MYSQL_VERSION=10.4" - -addons: - apt: - update: true - -before_install: - - export MYSQL_DATABASE=froxlor010 - - docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=fr0xl0r.TravisCI -e MYSQL_DATABASE=$MYSQL_DATABASE -p 3306:3306 $DOCKER_MYSQL_TYPE:$DOCKER_MYSQL_VERSION $STARTCMD - - sudo apt-get install -y ant - - > - export tries=0; - export max_tries=20; - while [[ true ]]; do - tries=$((tries + 1)); - echo "waiting for database server to start up... [$tries]"; - sleep 5; - # Now see that today's table is there, which would indicate that the cron job ran. - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -s -e 'SHOW VARIABLES LIKE "%version%";' - look_exit=$?; - if [[ "$look_exit" = "0" ]]; then echo "Database server successfully started"; break; fi; - if [[ "$tries" -ge "$max_tries" ]]; then echo "Database server did not start in time"; exit 1; break; fi; - done; - -install: - - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "CREATE DATABASE IF NOT EXISTS froxlor010;" - - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "CREATE USER 'froxlor010'@'%' IDENTIFIED BY 'fr0xl0r.TravisCI';" - - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI -e "GRANT ALL ON froxlor010.* TO 'froxlor010'@'%';" - - mysql -h 127.0.0.1 --protocol=TCP -u root -pfr0xl0r.TravisCI froxlor010 < install/froxlor.sql - -script: - - ant phpunit-no-coverage - -notifications: - irc: "irc.libera.chat#froxlor" - webhooks: - urls: - - https://webhooks.gitter.im/e/bdf91d1c3f745e51f796 - on_success: always - on_failure: always - on_start: never diff --git a/install/lib/updateFunctions.php b/install/lib/updateFunctions.php deleted file mode 100644 index c5466995..00000000 --- a/install/lib/updateFunctions.php +++ /dev/null @@ -1,84 +0,0 @@ - (2010-) - * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt - * @package Functions - * - */ - -/** - * Function showUpdateStep - * - * stores and logs the current update progress - * - * @param string $task - * @param bool $needs_status (if false, a linebreak will be added) - * - * @return void - */ -function showUpdateStep($task = null, $needs_status = true) -{ - global $update_tasks, $task_counter; - - set_time_limit(30); - - // output - $update_tasks[$task_counter] = ['title' => $task, 'result' => 0]; - - if (!$needs_status) { - $task_counter++; - } - - \Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, $task); -} - -/** - * Function lastStepStatus - * - * outputs status of the last update-step - * - * @param int $status (0 = success, 1 = warning, 2 = failure) - * @param string $message - * @param string $additional_info - * - * @return string formatted output and log-entry - */ -function lastStepStatus(int $status = -1, string $message = '', string $additional_info = '') -{ - global $update_tasks, $task_counter; - - $update_tasks[$task_counter]['result_txt'] = $message ?? 'OK'; - $update_tasks[$task_counter]['result_desc'] = $additional_info ?? ''; - - switch ($status) { - - case 0: - break; - case 1: - $update_tasks[$task_counter]['result'] = 2; - break; - case 2: - $update_tasks[$task_counter]['result'] = 1; - break; - default: - $update_tasks[$task_counter]['result'] = -1; - break; - } - - $task_counter++; - - if ($status == -1 || $status == 2) { - \Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, 'Attention - last update task failed!!!'); - } elseif ($status == 0 || $status == 1) { - \Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, 'Success'); - } -} diff --git a/install/updates/froxlor/0.11/update_0.11.inc.php b/install/updates/froxlor/0.11/update_0.11.inc.php index 3ec9549d..80b7c141 100644 --- a/install/updates/froxlor/0.11/update_0.11.inc.php +++ b/install/updates/froxlor/0.11/update_0.11.inc.php @@ -23,8 +23,10 @@ * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ +use Froxlor\Froxlor; use Froxlor\Database\Database; use Froxlor\Settings; +use Froxlor\Install\Update; if (!defined('_CRON_UPDATE')) { if (!defined('AREA') || (defined('AREA') && AREA != 'admin') || !isset($userinfo['loginname']) || (isset($userinfo['loginname']) && $userinfo['loginname'] == '')) { @@ -34,21 +36,21 @@ if (!defined('_CRON_UPDATE')) { } // last 0.10.x release -if (\Froxlor\Froxlor::isFroxlorVersion('0.10.99')) { - showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false); +if (Froxlor::isFroxlorVersion('0.10.99')) { + Update::showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false); - showUpdateStep("Removing unused table"); + Update::showUpdateStep("Removing unused table"); Database::query("DROP TABLE IF EXISTS `panel_sessions`;"); Database::query("DROP TABLE IF EXISTS `panel_languages`;"); - lastStepStatus(0); + Update::lastStepStatus(0); - showUpdateStep("Updating froxlor - theme"); + Update::showUpdateStep("Updating froxlor - theme"); Database::query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `theme` = 'Froxlor' WHERE `theme` <> 'Froxlor';"); Database::query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `theme` = 'Froxlor' WHERE `theme` <> 'Froxlor';"); Settings::Set('panel.default_theme', 'Froxlor'); - lastStepStatus(0); + Update::lastStepStatus(0); - showUpdateStep("Creating new tables and fields"); + Update::showUpdateStep("Creating new tables and fields"); Database::query("DROP TABLE IF EXISTS `panel_usercolumns`;"); $sql = "CREATE TABLE `panel_usercolumns` ( `adminid` int(11) NOT NULL default '0', @@ -60,10 +62,10 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.10.99')) { KEY customerid (customerid) ) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci;"; Database::query($sql); - lastStepStatus(0); + Update::lastStepStatus(0); - showUpdateStep("Cleaning up old files"); + Update::showUpdateStep("Cleaning up old files"); $to_clean = array( "install/lib", "install/lng", @@ -93,22 +95,22 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.10.99')) { } } if ($exec_allowed) { - lastStepStatus(0); + Update::lastStepStatus(0); } else { if (empty($del_list)) { // none of the files existed - lastStepStatus(0); + Update::lastStepStatus(0); } else { - lastStepStatus(1, 'manual commands needed', 'Please run the following commands manually:
' . $del_list . '
'); + Update::lastStepStatus(1, 'manual commands needed', 'Please run the following commands manually:
' . $del_list . '
'); } } - showUpdateStep("Adding new settings"); + Update::showUpdateStep("Adding new settings"); $panel_settings_mode = isset($_POST['panel_settings_mode']) ? (int) $_POST['panel_settings_mode'] : 0; Settings::AddNew("panel.settings_mode", $panel_settings_mode); - lastStepStatus(0); + Update::lastStepStatus(0); - showUpdateStep("Adjusting existing settings"); + Update::showUpdateStep("Adjusting existing settings"); Settings::Set('system.passwordcryptfunc', PASSWORD_DEFAULT); // remap default-language $lang_map = [ @@ -122,11 +124,11 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.10.99')) { 'Česká republika' => 'cs' ]; Settings::Set('panel.standardlanguage', $lang_map[Settings::Get('panel_standardlanguage')] ?? 'en'); - lastStepStatus(0); + Update::lastStepStatus(0); - if (\Froxlor\Froxlor::isFroxlorVersion('0.10.99')) { - showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false); - \Froxlor\Froxlor::updateToVersion('0.11.0-dev1'); + if (Froxlor::isFroxlorVersion('0.10.99')) { + Update::showUpdateStep("Updating from 0.10.99 to 0.11.0-dev1", false); + Froxlor::updateToVersion('0.11.0-dev1'); } } diff --git a/install/updates/preconfig.php b/install/updates/preconfig.php index 95ea4195..50562089 100644 --- a/install/updates/preconfig.php +++ b/install/updates/preconfig.php @@ -23,6 +23,9 @@ * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ +use Froxlor\Froxlor; +use Froxlor\FileDir; + /** * Function getPreConfig * @@ -38,7 +41,7 @@ function getPreConfig($current_version, $current_db_version): array { $has_preconfig = false; - include_once \Froxlor\FileDir::makeCorrectFile(dirname(__FILE__) . '/preconfig/0.11/preconfig_0.11.inc.php'); + include_once FileDir::makeCorrectFile(dirname(__FILE__) . '/preconfig/0.11/preconfig_0.11.inc.php'); $return['section_011'] = [ 'title' => '0.11.x updates', 'fields' => [] @@ -69,9 +72,9 @@ function getPreConfig($current_version, $current_db_version): array function versionInUpdate($current_version, $version_to_check) { - if (!\Froxlor\Froxlor::isFroxlor()) { + if (!Froxlor::isFroxlor()) { return true; } - return \Froxlor\Froxlor::versionCompare2($current_version, $version_to_check) == -1; + return Froxlor::versionCompare2($current_version, $version_to_check) == -1; } diff --git a/install/updatesql.php b/install/updatesql.php index 9f3c696c..e5b72f62 100644 --- a/install/updatesql.php +++ b/install/updatesql.php @@ -23,9 +23,12 @@ * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ +use Froxlor\Froxlor; +use Froxlor\Filedir; use Froxlor\FroxlorLogger; - -require_once __DIR__ . '/lib/updateFunctions.php'; +use Froxlor\UI\Response; +use Froxlor\Database\IntegrityCheck; +use Froxlor\Install\Update; if (!defined('_CRON_UPDATE')) { if (!defined('AREA') || (defined('AREA') && AREA != 'admin') || !isset($userinfo['loginname']) || (isset($userinfo['loginname']) && $userinfo['loginname'] == '')) { @@ -41,35 +44,35 @@ $filelog = FroxlorLogger::getInstanceOf(array( // if first writing does not work we'll stop, tell the user to fix it // and then let him try again. try { - $filelog->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, '-------------- START LOG --------------'); + $filelog->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, '-------------- START LOG --------------'); } catch (Exception $e) { - \Froxlor\UI\Response::standard_error('exception', $e->getMessage()); + Response::standard_error('exception', $e->getMessage()); } -if (\Froxlor\Froxlor::isFroxlor()) { +if (Froxlor::isFroxlor()) { // will be filled and increased by the update include-files below $update_tasks = []; $task_counter = 0; - include_once(\Froxlor\FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/0.11/update_0.11.inc.php')); + include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/0.11/update_0.11.inc.php')); // Check Froxlor - database integrity (only happens after all updates are done, so we know the db-layout is okay) - showUpdateStep("Checking database integrity"); + Update::showUpdateStep("Checking database integrity"); - $integrity = new \Froxlor\Database\IntegrityCheck(); + $integrity = new IntegrityCheck(); if (!$integrity->checkAll()) { - lastStepStatus(1, 'Monkeys ate the integrity'); - showUpdateStep("Trying to remove monkeys, feeding bananas"); + Update::lastStepStatus(1, 'Monkeys ate the integrity'); + Update::showUpdateStep("Trying to remove monkeys, feeding bananas"); if (!$integrity->fixAll()) { - lastStepStatus(2, 'failed', 'Some monkeys just would not move, you should contact team@froxlor.org'); + Update::lastStepStatus(2, 'failed', 'Some monkeys just would not move, you should contact team@froxlor.org'); } else { - lastStepStatus(0, 'Integrity restored'); + Update::lastStepStatus(0, 'Integrity restored'); } } else { - lastStepStatus(0); + Update::lastStepStatus(0); } - $filelog->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, '--------------- END LOG ---------------'); + $filelog->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, '--------------- END LOG ---------------'); unset($filelog); } diff --git a/lib/Froxlor/Install/Update.php b/lib/Froxlor/Install/Update.php new file mode 100644 index 00000000..3a259835 --- /dev/null +++ b/lib/Froxlor/Install/Update.php @@ -0,0 +1,100 @@ + + * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 + */ + +namespace Froxlor\Install; + +use Froxlor\FroxlorLogger; + +class Update +{ + + /** + * Function showUpdateStep + * + * stores and logs the current update progress + * + * @param string $task + * @param bool $needs_status (if false, a linebreak will be added) + * + * @return void + */ + public static function showUpdateStep($task = null, $needs_status = true) + { + global $update_tasks, $task_counter; + + set_time_limit(30); + + // output + $update_tasks[$task_counter] = ['title' => $task, 'result' => 0]; + + if (!$needs_status) { + $task_counter++; + } + + FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, $task); + } + + /** + * Function lastStepStatus + * + * outputs status of the last update-step + * + * @param int $status (0 = success, 1 = warning, 2 = failure) + * @param string $message + * @param string $additional_info + * + * @return string formatted output and log-entry + */ + public static function lastStepStatus(int $status = -1, string $message = '', string $additional_info = '') + { + global $update_tasks, $task_counter; + + $update_tasks[$task_counter]['result_txt'] = $message ?? 'OK'; + $update_tasks[$task_counter]['result_desc'] = $additional_info ?? ''; + + switch ($status) { + + case 0: + break; + case 1: + $update_tasks[$task_counter]['result'] = 2; + break; + case 2: + $update_tasks[$task_counter]['result'] = 1; + break; + default: + $update_tasks[$task_counter]['result'] = -1; + break; + } + + $task_counter++; + + if ($status == -1 || $status == 2) { + FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, 'Attention - last update task failed!!!'); + } elseif ($status == 0 || $status == 1) { + FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, 'Success'); + } + } +}