diff --git a/lam/lib/persistence.inc b/lam/lib/persistence.inc index b5f32782..f83079d8 100644 --- a/lam/lib/persistence.inc +++ b/lam/lib/persistence.inc @@ -6,6 +6,7 @@ use LAM\PDF\PDFStructureWriter; use LAMCfgMain; use LAMConfig; use LAMException; +use selfServiceProfile; use function LAM\PDF\getAvailableLogos; use function LAM\PDF\getPDFStructures; use function LAM\PDF\getPdfTemplateLogoBinary; @@ -74,10 +75,10 @@ class ConfigDataExporter { $jsonData['accountProfileTemplates'] = $this->_getAccountProfileTemplates(); $jsonData['pdfProfiles'] = $this->_getPdfProfiles($serverProfiles); $jsonData['pdfProfileTemplates'] = $this->_getPdfProfileTemplates(); + $jsonData['selfServiceProfiles'] = $this->_getSelfServiceProfiles(); /** * TODO * - * self service profiles * webauthn * cron job runs */ @@ -218,6 +219,26 @@ class ConfigDataExporter { return $data; } + /** + * Returns the content of the self service profiles. + * + * @return array data + */ + public function _getSelfServiceProfiles() { + $data = array(); + $profileTypes = getSelfServiceProfiles(); + foreach ($profileTypes as $profileType => $profileNames) { + foreach ($profileNames as $profileName) { + $profile = loadSelfServiceProfile($profileName, $profileType); + if ($profile === false) { + continue; + } + $data[$profileType][$profileName] = $profile->export(); + } + } + return $data; + } + } /** @@ -273,6 +294,9 @@ class ConfigDataImporter { case 'pdfProfileTemplates': $steps[] = new ImporterStep(_('PDF structures') . ' - ' . _('Global templates'), 'pdfProfileTemplates', $value); break; + case 'selfServiceProfiles': + $steps[] = new ImporterStep(_('Self service profiles'), 'selfServiceProfiles', $value); + break; default: logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); } @@ -317,6 +341,9 @@ class ConfigDataImporter { case 'pdfProfileTemplates': $this->importPdfProfileTemplates($step); break; + case 'selfServiceProfiles': + $this->importSelfServiceProfiles($step); + break; default: logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); } @@ -511,6 +538,29 @@ class ConfigDataImporter { } } + /** + * Imports the self service profiles. + * + * @param ImporterStep $step importer step + * @throws LAMException error saving profiles + */ + private function importSelfServiceProfiles($step) { + $failedNames = array(); + $data = $step->getValue(); + foreach ($data as $typeId => $profileData) { + foreach ($profileData as $profileName => $currentProfileData) { + $profile = selfServiceProfile::import($currentProfileData); + $result = saveSelfServiceProfile($profileName, $typeId, $profile); + if (!$result) { + $failedNames[] = $profileName; + } + } + } + if (!empty($failedNames)) { + throw new LAMException(_('Unable to save profile!'), implode(', ', $failedNames)); + } + } + } /** diff --git a/lam/lib/selfService.inc b/lam/lib/selfService.inc index c96e0c82..201bd536 100644 --- a/lam/lib/selfService.inc +++ b/lam/lib/selfService.inc @@ -170,7 +170,7 @@ function checkSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOn /** * Returns a list of all available self service profiles (without .conf) * -* @return array profile names (array( => array(, , ...))) +* @return array profile names (array('account type' => array('profile1', 'profile2'))) */ function getSelfServiceProfiles() { $types = LAM\TYPES\getTypes(); @@ -201,7 +201,7 @@ function getSelfServiceProfiles() { * * @param string $name profile name * @param string $scope account type -* @return selfServiceProfile true if file was readable +* @return false|selfServiceProfile profile or false if file was not readable */ function loadSelfServiceProfile($name, $scope) { if (!preg_match("/^[0-9a-z _-]+$/i", $name) || !preg_match("/^[0-9a-z _-]+$/i", $scope)) {