server profiles import

This commit is contained in:
Roland Gruber 2020-04-26 08:55:09 +02:00
parent ea72ab63a9
commit 8d50dd59b0
4 changed files with 51 additions and 3 deletions

View File

@ -1 +1 @@
7.2.RC1 7.2.DEV

View File

@ -667,6 +667,17 @@ class LAMConfig {
$data['moduleSettings'] = $this->moduleSettings; $data['moduleSettings'] = $this->moduleSettings;
$data['toolSettings'] = $this->toolSettings; $data['toolSettings'] = $this->toolSettings;
$data['jobSettings'] = $this->jobSettings; $data['jobSettings'] = $this->jobSettings;
if ($this->jobsDatabase === 'SQLite') {
$dbFileName = __DIR__ . '/../config/' . $this->getName() . '.sqlite';
if (is_file($dbFileName) && is_readable($dbFileName)) {
$file = @fopen($dbFileName, "r");
if ($file) {
$dbData = fread($file, 100000000);
fclose($file);
$data['jobSQLite'] = base64_encode($dbData);
}
}
}
return $data; return $data;
} }
@ -699,6 +710,14 @@ class LAMConfig {
$this->toolSettings = $toolSettingsData; $this->toolSettings = $toolSettingsData;
$jobSettingsData = !empty($data['jobSettings']) && is_array($data['jobSettings']) ? $data['jobSettings'] : array(); $jobSettingsData = !empty($data['jobSettings']) && is_array($data['jobSettings']) ? $data['jobSettings'] : array();
$this->jobSettings = $jobSettingsData; $this->jobSettings = $jobSettingsData;
if (!empty($data['jobSQLite'])) {
$dbFileName = __DIR__ . '/../config/' . $this->getName() . '.sqlite';
$file = @fopen($dbFileName, "wb");
if ($file) {
fputs($file, base64_decode($data['jobSQLite']));
fclose($file);
}
}
} }
/** /**
@ -811,6 +830,10 @@ class LAMConfig {
/** Saves preferences to config file */ /** Saves preferences to config file */
public function save() { public function save() {
$conffile = $this->getPath(); $conffile = $this->getPath();
if (!file_exists($conffile)) {
$newFile = fopen($conffile, 'wb');
fclose($newFile);
}
if (is_file($conffile) && is_readable($conffile)) { if (is_file($conffile) && is_readable($conffile)) {
$file = fopen($conffile, "r"); $file = fopen($conffile, "r");
$file_array = array(); $file_array = array();

View File

@ -169,6 +169,9 @@ class ConfigDataImporter {
case 'certificates': case 'certificates':
$this->importCertificates($step->getValue()); $this->importCertificates($step->getValue());
break; break;
case 'serverProfiles':
$this->importServerProfiles($step);
break;
default: default:
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
} }
@ -198,6 +201,25 @@ class ConfigDataImporter {
$cfgMain->importCertificates($data); $cfgMain->importCertificates($data);
} }
/**
* Imports the server profiles.
*
* @param ImporterStep $step step
* @throws LAMException error during import
*/
private function importServerProfiles($step) {
foreach ($step->getSubSteps() as $profileStep) {
if (!$profileStep->isActive()) {
continue;
}
$data = $profileStep->getValue();
$profileName = str_replace('serverProfile_', '', $profileStep->getKey());
$serverProfile = new LAMConfig($profileName);
$serverProfile->importData($data);
$serverProfile->save();
}
}
} }
/** /**
@ -218,10 +240,10 @@ class ImporterStep {
* @param string $key key * @param string $key key
* @param array $value value * @param array $value value
*/ */
public function __construct($label, $key, &$value) { public function __construct($label, $key, $value) {
$this->label = $label; $this->label = $label;
$this->key = $key; $this->key = $key;
$this->value = &$value; $this->value = $value;
} }
/** /**

View File

@ -251,6 +251,9 @@ printHeaderContents(_("Import and export configuration"), '../..');
$importSteps = $importer->getPossibleImportSteps($data); $importSteps = $importer->getPossibleImportSteps($data);
foreach ($importSteps as $importStep) { foreach ($importSteps as $importStep) {
$importStep->setActive(isset($_POST['step_' . $importStep->getKey()])); $importStep->setActive(isset($_POST['step_' . $importStep->getKey()]));
foreach ($importStep->getSubSteps() as $subStep) {
$subStep->setActive(isset($_POST['step_' . $subStep->getKey()]));
}
} }
$importer->runImport($importSteps); $importer->runImport($importSteps);
unlink($_SESSION['configImportFile']); unlink($_SESSION['configImportFile']);