config import and export
This commit is contained in:
parent
6fc259d718
commit
0a72bc9635
|
@ -4777,6 +4777,7 @@ class htmlResponsiveInputCheckbox extends htmlInputCheckbox {
|
|||
}
|
||||
// label text
|
||||
$text = new htmlSpan(new htmlOutputText($this->label));
|
||||
$text->setCSSClasses($this->cssClasses);
|
||||
$text->setOnclick('jQuery(\'#' . $this->name . '\').prop(\'checked\',!jQuery(\'#' . $this->name . '\').prop(\'checked\')); jQuery(\'#' . $this->name . '\').change();');
|
||||
// input field
|
||||
$fieldGroup = new htmlGroup();
|
||||
|
|
|
@ -118,7 +118,7 @@ function getAvailableLogos($serverProfileName) {
|
|||
* @param \LAM\TYPES\ConfiguredType $sourceType source type
|
||||
* @param string $sourceStructureName structure name
|
||||
* @param \LAM\TYPES\ConfiguredType $targetType target type
|
||||
* @throws Exception
|
||||
* @throws LAMException error during copy
|
||||
*/
|
||||
function copyStructure($sourceType, $sourceStructureName, $targetType) {
|
||||
if (!isValidPDFStructureName($sourceStructureName)) {
|
||||
|
@ -427,7 +427,7 @@ class PDFStructureWriter {
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param $serverProfileName server profile name
|
||||
* @param string $serverProfileName server profile name
|
||||
*/
|
||||
public function __construct($serverProfileName) {
|
||||
$this->serverProfileName = $serverProfileName;
|
||||
|
@ -439,6 +439,7 @@ class PDFStructureWriter {
|
|||
* @param string $typeId type ID
|
||||
* @param string $name structure name
|
||||
* @param PDFStructure $structure structure
|
||||
* @throws LAMException error during write
|
||||
*/
|
||||
public function write($typeId, $name, $structure) {
|
||||
$fileName = $this->getFileName($typeId, $name);
|
||||
|
@ -452,6 +453,7 @@ class PDFStructureWriter {
|
|||
* @param string $typeId type ID
|
||||
* @param string $name structure name
|
||||
* @return string file name
|
||||
* @throws LAMException file not valid or not writable
|
||||
*/
|
||||
protected function getFileName($typeId, $name) {
|
||||
if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
|
||||
|
@ -510,6 +512,7 @@ class PDFStructureWriter {
|
|||
*
|
||||
* @param string $xml XML
|
||||
* @param string $file file name
|
||||
* @throws LAMException error during write
|
||||
*/
|
||||
protected function writeXML($xml, $file) {
|
||||
$handle = @fopen($file,'w');
|
||||
|
@ -713,7 +716,7 @@ class PDFTextSection {
|
|||
class PDFEntrySection {
|
||||
|
||||
private $title;
|
||||
private $entries;
|
||||
private $entries = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
<?php
|
||||
namespace LAM\PERSISTENCE;
|
||||
use LAM\PDF\PDFStructure;
|
||||
use LAM\PDF\PDFStructureReader;
|
||||
use LAM\PDF\PDFStructureWriter;
|
||||
use LAMCfgMain;
|
||||
use LAMConfig;
|
||||
use LAMException;
|
||||
use function LAM\PDF\getAvailableLogos;
|
||||
use function LAM\PDF\getPDFStructures;
|
||||
use function LAM\PDF\uploadPDFLogo;
|
||||
use function LAM\PROFILES\getAccountProfiles;
|
||||
use function LAM\PROFILES\loadAccountProfile;
|
||||
use function LAM\PROFILES\saveAccountProfile;
|
||||
|
@ -65,7 +68,7 @@ class ConfigDataExporter {
|
|||
/**
|
||||
* TODO
|
||||
*
|
||||
* PDF profiles
|
||||
* pdf/account templates /config/templates
|
||||
* self service profiles
|
||||
* webauthn
|
||||
*/
|
||||
|
@ -207,7 +210,13 @@ class ConfigDataImporter {
|
|||
}
|
||||
$steps[] = $mainStep;
|
||||
break;
|
||||
// TODO PDF structures
|
||||
case 'pdfProfiles':
|
||||
$mainStep = new ImporterStep(_('PDF structures'), 'pdfProfiles', $value);
|
||||
foreach ($value as $profileName => $profileData) {
|
||||
$mainStep->addSubStep(new ImporterStep($profileName, 'pdfProfile_' . $profileName, $profileData));
|
||||
}
|
||||
$steps[] = $mainStep;
|
||||
break;
|
||||
default:
|
||||
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
|
||||
}
|
||||
|
@ -243,6 +252,9 @@ class ConfigDataImporter {
|
|||
case 'accountProfiles':
|
||||
$this->importAccountProfiles($step);
|
||||
break;
|
||||
case 'pdfProfiles':
|
||||
$this->importPdfProfiles($step);
|
||||
break;
|
||||
default:
|
||||
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
|
||||
}
|
||||
|
@ -327,6 +339,53 @@ class ConfigDataImporter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports the PDF profiles.
|
||||
*
|
||||
* @param ImporterStep $step step
|
||||
* @throws LAMException error during import
|
||||
*/
|
||||
private function importPdfProfiles($step) {
|
||||
$failedProfiles = array();
|
||||
foreach ($step->getSubSteps() as $profileStep) {
|
||||
if (!$profileStep->isActive()) {
|
||||
continue;
|
||||
}
|
||||
$data = $profileStep->getValue();
|
||||
$serverProfileName = str_replace('pdfProfile_', '', $profileStep->getKey());
|
||||
if (isset($data['structures'])) {
|
||||
$writer = new PDFStructureWriter($serverProfileName);
|
||||
foreach ($data['structures'] as $typeId => $pdfProfiles) {
|
||||
foreach ($pdfProfiles as $pdfProfileName => $pdfProfileData) {
|
||||
$structure = new PDFStructure();
|
||||
$structure->import($pdfProfileData);
|
||||
try {
|
||||
$writer->write($typeId, $pdfProfileName, $structure);
|
||||
}
|
||||
catch (LAMException $e) {
|
||||
logNewMessage('ERROR', $e->getMessage());
|
||||
$failedProfiles[] = $serverProfileName . ':' . $typeId . ':' . $pdfProfileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($data['logos'])) {
|
||||
foreach ($data['logos'] as $logoFileName => $logoData) {
|
||||
$tempFilePath = tempnam("/tmp", "lam");
|
||||
$tempFile = fopen($tempFilePath, "w");
|
||||
$logoBinary = base64_decode($logoData);
|
||||
fwrite($tempFile, $logoBinary);
|
||||
fclose($tempFile);
|
||||
uploadPDFLogo($tempFilePath, $logoFileName, $serverProfileName);
|
||||
unlink($tempFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($failedProfiles)) {
|
||||
throw new LAMException(_('Could not save PDF structure, access denied.'), implode(', ', $failedProfiles));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -189,10 +189,13 @@ printHeaderContents(_("Import and export configuration"), '../..');
|
|||
$validUpload = false;
|
||||
$importSteps = array();
|
||||
if (isset($_POST['importConfig'])) {
|
||||
$handle = fopen($_FILES['import-file']['tmp_name'], "r");
|
||||
$data = fread($handle, 100000000);
|
||||
fclose($handle);
|
||||
try {
|
||||
if (empty($_FILES['import-file']['tmp_name'])) {
|
||||
throw new LAMException('The file you uploaded is too large. Please check php.ini, upload_max_size setting');
|
||||
}
|
||||
$handle = fopen($_FILES['import-file']['tmp_name'], "r");
|
||||
$data = fread($handle, 100000000);
|
||||
fclose($handle);
|
||||
$importer = new ConfigDataImporter();
|
||||
$importSteps = $importer->getPossibleImportSteps($data);
|
||||
$tmpFile = __DIR__ . '/../../tmp/internal/import_' . getRandomNumber() . '.tmp';
|
||||
|
@ -219,13 +222,14 @@ printHeaderContents(_("Import and export configuration"), '../..');
|
|||
$stepKey = 'step_' . $importStep->getKey();
|
||||
$stepCheckbox = new htmlResponsiveInputCheckbox($stepKey, true, $importStep->getLabel());
|
||||
$stepCheckbox->setLabelAfterCheckbox();
|
||||
$stepCheckbox->setCSSClasses(array('bold'));
|
||||
$subStepIds = array();
|
||||
$content->add($stepCheckbox, 12);
|
||||
$content->addVerticalSpacer('0.3rem');
|
||||
foreach ($importStep->getSubSteps() as $subStep) {
|
||||
$subStepKey = 'step_' . $subStep->getKey();
|
||||
$subStepIds[] = $subStepKey;
|
||||
$subStepCheckbox = new htmlResponsiveInputCheckbox($subStepKey, true, ' - ' . $subStep->getLabel());
|
||||
$subStepCheckbox = new htmlResponsiveInputCheckbox($subStepKey, true, $subStep->getLabel());
|
||||
$subStepCheckbox->setLabelAfterCheckbox();
|
||||
$content->add($subStepCheckbox, 12);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue