migrate update/preconfig to a more OOP way and remove unnecessary file/dir complexity
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -30,6 +30,7 @@ use Froxlor\Cron\TaskId;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\FroxlorLogger;
|
||||
use Froxlor\Install\Preconfig;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\System\Cronjob;
|
||||
use Froxlor\UI\Panel\UI;
|
||||
@@ -96,15 +97,15 @@ if ($page == 'overview') {
|
||||
$new_version = Froxlor::VERSION;
|
||||
$new_db_version = Froxlor::DBVERSION;
|
||||
|
||||
$ui_text = lng('update.update_information.part_a');
|
||||
if (Froxlor::VERSION != $current_version) {
|
||||
$ui_text = str_replace('%curversion', $current_version, $ui_text);
|
||||
$ui_text = str_replace('%newversion', $new_version, $ui_text);
|
||||
$replacer_currentversion = $current_version;
|
||||
$replacer_newversion = $new_version;
|
||||
} else {
|
||||
// show db version
|
||||
$ui_text = str_replace('%curversion', $current_db_version, $ui_text);
|
||||
$ui_text = str_replace('%newversion', $new_db_version, $ui_text);
|
||||
$replacer_currentversion = $current_db_version;
|
||||
$replacer_newversion = $new_db_version;
|
||||
}
|
||||
$ui_text = lng('update.update_information.part_a', [$replacer_newversion, $replacer_currentversion]);
|
||||
$ui_text .= lng('update.update_information.part_b');
|
||||
|
||||
$upd_formfield = [
|
||||
@@ -121,8 +122,8 @@ if ($page == 'overview') {
|
||||
]
|
||||
];
|
||||
|
||||
include_once Froxlor::getInstallDir() . '/install/updates/preconfig.php';
|
||||
$preconfig = getPreConfig($current_version, $current_db_version);
|
||||
$preconfig = Preconfig::getPreConfig();
|
||||
|
||||
if (!empty($preconfig)) {
|
||||
$upd_formfield['updates']['sections'] = $preconfig;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,11 @@ if (Froxlor::isFroxlorVersion('0.10.99')) {
|
||||
$to_clean = array(
|
||||
"install/lib",
|
||||
"install/lng",
|
||||
"install/updates/froxlor/0.9",
|
||||
"install/updates/froxlor/0.10",
|
||||
"install/updates/preconfig/0.9",
|
||||
"install/updates/preconfig/0.10",
|
||||
"install/updates/preconfig.php",
|
||||
"templates/Sparkle",
|
||||
"lib/version.inc.php",
|
||||
"lng/czech.lng.php",
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\FileDir;
|
||||
|
||||
/**
|
||||
* Function getPreConfig
|
||||
*
|
||||
* outputs various form-field-arrays before the update process
|
||||
* can be continued (asks for agreement whatever is being asked)
|
||||
*
|
||||
* @param string $current_version
|
||||
* @param int $current_db_version
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getPreConfig($current_version, $current_db_version): array
|
||||
{
|
||||
$has_preconfig = false;
|
||||
|
||||
include_once FileDir::makeCorrectFile(dirname(__FILE__) . '/preconfig/0.11/preconfig_0.11.inc.php');
|
||||
$return['section_011'] = [
|
||||
'title' => '0.11.x updates',
|
||||
'fields' => []
|
||||
];
|
||||
parseAndOutputPreconfig011($has_preconfig, $return['section_011']['fields'], $current_version, $current_db_version);
|
||||
|
||||
if (empty($return['section_011']['fields'])) {
|
||||
unset($return['section_011']);
|
||||
}
|
||||
|
||||
if (!empty($return)) {
|
||||
$has_preconfig = true;
|
||||
$return['section_agree'] = [
|
||||
'title' => 'Check',
|
||||
'fields' => [
|
||||
'update_changesagreed' => ['type' => 'checkbox', 'value' => 1, 'label' => '<strong>I have read the update notifications above and I am aware of the changes made to my system.</strong>'],
|
||||
'update_preconfig' => ['type' => 'hidden', 'value' => 1]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
if ($has_preconfig) {
|
||||
return $return;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function versionInUpdate($current_version, $version_to_check)
|
||||
{
|
||||
if (!Froxlor::isFroxlor()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Froxlor::versionCompare2($current_version, $version_to_check) == -1;
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 https://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Updater
|
||||
*
|
||||
*/
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Config\ConfigParser;
|
||||
|
||||
/**
|
||||
* checks if the new-version has some updating to do
|
||||
*
|
||||
* @param boolean $has_preconfig
|
||||
* pointer to check if any preconfig has to be output
|
||||
* @param string $return
|
||||
* pointer to output string
|
||||
* @param string $current_version
|
||||
* current froxlor version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function parseAndOutputPreconfig011(&$has_preconfig, &$return, $current_version, $current_db_version)
|
||||
{
|
||||
|
||||
if (versionInUpdate($current_version, '0.10.99')) {
|
||||
$has_preconfig = true;
|
||||
$description = 'We have rearranged the settings and split them into basic and advanced categories. This makes it easier for users who do not need all the detailed or very specific settings and options and gives a better overview of the basic/mostly used settings.';
|
||||
$return['panel_settings_mode_note'] = ['type' => 'infotext', 'value' => $description];
|
||||
$question = '<strong>Chose settings mode (you can change that at any time)</strong>';
|
||||
$return['panel_settings_mode'] = [
|
||||
'type' => 'select',
|
||||
'select_var' => [
|
||||
0 => 'Basic',
|
||||
1 => 'Advanced'
|
||||
],
|
||||
'selected' => 1,
|
||||
'label' => $question
|
||||
];
|
||||
|
||||
$description = 'The configuration page now can preselect a distribution, please select your current distribution';
|
||||
$return['system_distribution_note'] = ['type' => 'infotext', 'value' => $description];
|
||||
$question = '<strong>Select distribution</strong>';
|
||||
$config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/');
|
||||
// show list of available distro's
|
||||
$distros = glob($config_dir . '*.xml');
|
||||
$distributions_select[''] = '-';
|
||||
// read in all the distros
|
||||
foreach ($distros as $_distribution) {
|
||||
// get configparser object
|
||||
$dist = new ConfigParser($_distribution);
|
||||
// store in tmp array
|
||||
$distributions_select[str_replace(".xml", "", strtolower(basename($_distribution)))] = $dist->getCompleteDistroName();
|
||||
}
|
||||
// sort by distribution name
|
||||
asort($distributions_select);
|
||||
$return['system_distribution'] = [
|
||||
'type' => 'select',
|
||||
'select_var' => $distributions_select,
|
||||
'selected' => '',
|
||||
'label' => $question
|
||||
];
|
||||
}
|
||||
}
|
||||
76
install/updates/preconfig/preconfig_0.11.inc.php
Normal file
76
install/updates/preconfig/preconfig_0.11.inc.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Config\ConfigParser;
|
||||
use Froxlor\Install\Update;
|
||||
|
||||
$preconfig = [
|
||||
'title' => '0.11.x updates',
|
||||
'fields' => []
|
||||
];
|
||||
$return = [];
|
||||
|
||||
if (Update::versionInUpdate($current_version, '0.10.99')) {
|
||||
$description = 'We have rearranged the settings and split them into basic and advanced categories. This makes it easier for users who do not need all the detailed or very specific settings and options and gives a better overview of the basic/mostly used settings.';
|
||||
$return['panel_settings_mode_note'] = ['type' => 'infotext', 'value' => $description];
|
||||
$question = '<strong>Chose settings mode (you can change that at any time)</strong>';
|
||||
$return['panel_settings_mode'] = [
|
||||
'type' => 'select',
|
||||
'select_var' => [
|
||||
0 => 'Basic',
|
||||
1 => 'Advanced'
|
||||
],
|
||||
'selected' => 1,
|
||||
'label' => $question
|
||||
];
|
||||
|
||||
$description = 'The configuration page now can preselect a distribution, please select your current distribution';
|
||||
$return['system_distribution_note'] = ['type' => 'infotext', 'value' => $description];
|
||||
$question = '<strong>Select distribution</strong>';
|
||||
$config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/');
|
||||
// show list of available distro's
|
||||
$distros = glob($config_dir . '*.xml');
|
||||
$distributions_select[''] = '-';
|
||||
// read in all the distros
|
||||
foreach ($distros as $_distribution) {
|
||||
// get configparser object
|
||||
$dist = new ConfigParser($_distribution);
|
||||
// store in tmp array
|
||||
$distributions_select[str_replace(".xml", "", strtolower(basename($_distribution)))] = $dist->getCompleteDistroName();
|
||||
}
|
||||
// sort by distribution name
|
||||
asort($distributions_select);
|
||||
$return['system_distribution'] = [
|
||||
'type' => 'select',
|
||||
'select_var' => $distributions_select,
|
||||
'selected' => '',
|
||||
'label' => $question
|
||||
];
|
||||
}
|
||||
|
||||
$preconfig['fields'] = $return;
|
||||
return $preconfig;
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\Filedir;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\FroxlorLogger;
|
||||
use Froxlor\UI\Response;
|
||||
use Froxlor\Database\IntegrityCheck;
|
||||
@@ -55,7 +55,7 @@ if (Froxlor::isFroxlor()) {
|
||||
$update_tasks = [];
|
||||
$task_counter = 0;
|
||||
|
||||
include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/0.11/update_0.11.inc.php'));
|
||||
include_once(FileDir::makeCorrectFile(dirname(__FILE__) . '/updates/froxlor/update_0.11.inc.php'));
|
||||
|
||||
// Check Froxlor - database integrity (only happens after all updates are done, so we know the db-layout is okay)
|
||||
Update::showUpdateStep("Checking database integrity");
|
||||
|
||||
114
lib/Froxlor/Install/Preconfig.php
Normal file
114
lib/Froxlor/Install/Preconfig.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Install;
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\Settings;
|
||||
|
||||
class Preconfig
|
||||
{
|
||||
private $preconfig_data = [];
|
||||
|
||||
/**
|
||||
* returns whether there are preconfig items in an update
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPreConfig(): bool
|
||||
{
|
||||
return count($this->preconfig_data) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* return all collected preconfig data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->preconfig_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds an preconfig result-array to the preconfig-data
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addToPreConfig(array $array)
|
||||
{
|
||||
$this->preconfig_data = $this->preconfig_data + $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* read in all preconfig files and build up data-array for admin_updates
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$preconfigs = glob(Froxlor::getInstallDir() . '/install/updates/preconfig/*.php');
|
||||
|
||||
if (!empty($preconfigs)) {
|
||||
$current_version = Settings::Get('panel.version');
|
||||
$current_db_version = Settings::Get('panel.db_version');
|
||||
if (empty($current_db_version)) {
|
||||
$current_db_version = "0";
|
||||
}
|
||||
foreach (array_reverse($preconfigs) as $preconfig_file) {
|
||||
$pconf = include $preconfig_file;
|
||||
$this->addToPreConfig($pconf);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Function getPreConfig
|
||||
*
|
||||
* outputs various form-field-arrays before the update process
|
||||
* can be continued (asks for agreement whatever is being asked)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPreConfig(): array
|
||||
{
|
||||
$preconfig = new self();
|
||||
|
||||
if ($preconfig->hasPreConfig()) {
|
||||
$agree = [
|
||||
'title' => 'Check',
|
||||
'fields' => [
|
||||
'update_changesagreed' => ['type' => 'checkbox', 'value' => 1, 'label' => '<strong>I have read the update notifications above and I am aware of the changes made to my system.</strong>'],
|
||||
'update_preconfig' => ['type' => 'hidden', 'value' => 1]
|
||||
]
|
||||
];
|
||||
$result = [
|
||||
$preconfig->getData(),
|
||||
$agree
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace Froxlor\Install;
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\FroxlorLogger;
|
||||
|
||||
class Update
|
||||
@@ -96,4 +97,13 @@ class Update
|
||||
FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, 'Success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function versionInUpdate($current_version, $version_to_check)
|
||||
{
|
||||
if (!Froxlor::isFroxlor()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Froxlor::versionCompare2($current_version, $version_to_check) == -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2075,7 +2075,7 @@ Vielen Dank, Ihr Administrator',
|
||||
'update' => 'Froxlor Aktualisierung',
|
||||
'proceed' => 'Ausführen',
|
||||
'update_information' => [
|
||||
'part_a' => 'Die Froxlor-Dateien wurden aktualisiert. Neue Version ist <strong>%newversion</strong>. Die bisher installierte Version ist <strong>%curversion</strong>',
|
||||
'part_a' => 'Die Froxlor-Dateien wurden aktualisiert. Neue Version ist <strong>%s</strong>. Die bisher installierte Version ist <strong>%s</strong>',
|
||||
'part_b' => '<br /><br />Ein Kunden-Login ist vor Abschluss des Aktualisierungsvorganges nicht möglich.<br /><strong>Aktualisierung ausführen?</strong>',
|
||||
],
|
||||
'noupdatesavail' => '<strong>Ihre Froxlor-Version ist aktuell.</strong>',
|
||||
|
||||
@@ -2433,7 +2433,7 @@ Yours sincerely, your administrator',
|
||||
'update' => 'Froxlor update',
|
||||
'proceed' => 'Proceed',
|
||||
'update_information' => [
|
||||
'part_a' => 'The Froxlor files have been updated to version <strong>%newversion</strong>. The installed version is <strong>%curversion</strong>.',
|
||||
'part_a' => 'The Froxlor files have been updated to version <strong>%s</strong>. The installed version is <strong>%s</strong>.',
|
||||
'part_b' => '<br /><br />Customers will not be able to log in until the update has been finished.<br /><strong>Proceed?</strong>',
|
||||
],
|
||||
'noupdatesavail' => '<strong>You already have the latest Froxlor version.</strong>',
|
||||
|
||||
@@ -1810,7 +1810,7 @@ Nota: Perfavore <b>sii sicuro</b> di usare lo stesso nome di file come per il cr
|
||||
'update' => 'Aggiorna Froxlor',
|
||||
'proceed' => 'Procedi',
|
||||
'update_information' => [
|
||||
'part_a' => 'I file di Froxlor sono stati aggiornati alla versione <strong>%newversion</strong>. La versione installata è <strong>%curversion</strong>.',
|
||||
'part_a' => 'I file di Froxlor sono stati aggiornati alla versione <strong>%s</strong>. La versione installata è <strong>%s</strong>.',
|
||||
'part_b' => '<br /><br />I clienti non potranno accedere fino a quando l\'aggiornamento non sarà completato.<br /><strong>Procedere?</strong>',
|
||||
],
|
||||
'noupdatesavail' => '<strong>È già presente l\'ultima versione di Froxlor.</strong>',
|
||||
|
||||
@@ -1150,7 +1150,7 @@ Met vriendelijke groet, uw beheerder',
|
||||
'update' => 'Froxlor Update',
|
||||
'proceed' => 'Verdergaan',
|
||||
'update_information' => [
|
||||
'part_a' => 'De bestanden van Froxlor zijn bijgewerkt naar versie <strong>%newversion</strong>. De geinstalleerde versie is <strong>%curversion</strong>.',
|
||||
'part_a' => 'De bestanden van Froxlor zijn bijgewerkt naar versie <strong>%s</strong>. De geinstalleerde versie is <strong>%s</strong>.',
|
||||
'part_b' => '<br /><br />Klanten kunnen niet inloggen totdat de update voltooid is.<br /><strong>Verdergaan?</strong>',
|
||||
],
|
||||
'noupdatesavail' => '<strong>U gebruikt reeds de meest recente versie van Froxlor.</strong>',
|
||||
|
||||
Reference in New Issue
Block a user