{"record":{"id":"23d1db169e3882d0","repo":"passbolt/passbolt_api","slug":"new-directory-settings-could-not-be-saved","errorCode":null,"errorMessage":"New directory settings could not be saved.","messagePattern":"New directory settings could not be saved\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Service/DirectorySettings/UpdateDirectorySettingsService.php","lineNumber":75,"sourceCode":"            foreach ($value['ldap']['domains'] as $domain => $config) {\n                if (array_key_exists('servers', $config)) {\n                    $value['ldap']['domains'][$domain]['hosts'] = $config['servers'];\n                    unset($value['ldap']['domains'][$domain]['servers']);\n                }\n            }\n        }\n\n        // keep compatibility with old library default class value\n        if (empty($value['groupObjectClass'])) {\n            $value['groupObjectClass'] = 'groupOfNames';\n        }\n        $value['enabled'] = false;\n\n        $directorySyncSettings->set('value', json_encode($value));\n        $result = $OrganizationSettings\n            ->save($directorySyncSettings);\n        if (!$result) {\n            throw new RuntimeException(__('New directory settings could not be saved.'));\n        }\n    }\n}\n","sourceCodeStart":57,"sourceCodeEnd":79,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Service/DirectorySettings/UpdateDirectorySettingsService.php#L57-L79","documentation":"Thrown by UpdateDirectorySettingsService::updateSettings when the CakePHP save() of the directorySync organization settings entity fails. It wraps the persistence failure (validation errors, DB write failure) into a RuntimeException so the caller knows the new LDAP/directory settings were not persisted.","triggerScenarios":"Calling updateSettings with a settings entity whose value fails entity validation, or when the underlying database write fails (connection issue, lock, constraint).","commonSituations":"Admin saves directory sync settings via the EE DirectorySync settings endpoint while the database is unavailable or the payload produces an invalid OrganizationSettings entity; MySQL/Postgres connection drops mid-save.","solutions":["Check the save() result's entity errors first (log $directorySyncSettings->getErrors()) to find the validation rule that failed","Verify database connectivity and run `ddev refresh` or migrations to ensure the organization_settings table is intact","Validate the incoming settings payload (fields like domains, usersParentGroup, customFilters) before calling save()","Retry after clearing cache if a stale OrganizationSettings cache entry is interfering"],"exampleFix":"// before\n$result = $OrganizationSettings->save($directorySyncSettings);\nif (!$result) {\n    throw new RuntimeException(__('New directory settings could not be saved.'));\n}\n// after\n$result = $OrganizationSettings->save($directorySyncSettings);\nif (!$result) {\n    $errors = $directorySyncSettings->getErrors();\n    Log::error('Directory settings save failed: ' . json_encode($errors));\n    throw new RuntimeException(__('New directory settings could not be saved.') . ' ' . json_encode($errors));\n}","handlingStrategy":"try-catch","validationCode":"$table = $this->fetchTable('OrganizationSettings');\n$entity = $table->newEntity($data);\nif ($entity->getErrors()) { /* reject before save */ }","typeGuard":null,"tryCatchPattern":"try {\n    $service->updateSettings($payload);\n} catch (RuntimeException $e) {\n    $this->log($e->getMessage());\n    return $this->respondWithError('500', __('Directory settings could not be saved. Check server logs and database connectivity.'));\n}","preventionTips":["Validate the settings payload before saving (schema/DTO validation)","Monitor database health; the save depends on the organization_settings table","Log entity errors on save failure for diagnosability"],"tags":["database","persistence","ldap","cakephp"],"backgroundTag":"database-write-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}