{"record":{"id":"47c59f2ef70ac6d9","repo":"passbolt/passbolt_api","slug":"could-not-validate-folder-history-data","errorCode":null,"errorMessage":"Could not validate folder history data.","messagePattern":"Could not validate folder history data\\.","errorType":"validation","errorClass":"Cake\\Web\\Exception\\ValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Folders/src/Model/Table/FoldersHistoryTable.php","lineNumber":167,"sourceCode":"\n    /**\n     * Create a new FolderHistory.\n     *\n     * @param array $data the data\n     * @return \\Passbolt\\Folders\\Model\\Entity\\FolderHistory\n     * @throws \\App\\Error\\Exception\\ValidationException\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException\n     */\n    public function create(array $data): FolderHistory\n    {\n        // Folder.Id becomes FolderHistory.FolderId\n        $data['folder_id'] = $data['id'];\n        unset($data['id']);\n\n        // Check validation rules.\n        $folderHistory = $this->buildEntity($data);\n        if ($folderHistory->getErrors()) {\n            throw new ValidationException(__('Could not validate folder history data.', true), $folderHistory, $this);\n        }\n        $folderHistory = $this->save($folderHistory);\n\n        // Check for errors while saving.\n        if (!$folderHistory) {\n            throw new InternalErrorException('Could not save the folder history.');\n        }\n\n        // Check for validation errors. (associated models too).\n        if ($folderHistory->getErrors()) {\n            throw new ValidationException(__('Could not validate folder history data.'), $folderHistory, $this);\n        }\n\n        return $folderHistory;\n    }\n}\n","sourceCodeStart":149,"sourceCodeEnd":184,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Folders/src/Model/Table/FoldersHistoryTable.php#L149-L184","documentation":"FoldersHistoryTable::create() builds a folder history entity from the supplied data and, if the entity has validation errors, throws a ValidationException with 'Could not validate folder history data.' This enforces the model's validation rules (folder_id UUID, permission/ownership rules, etc.) before persisting the history snapshot.","triggerScenarios":"Calling create() (via folder history creation flows, e.g. after folder operations) with $data['id'] not a valid folder UUID or violating FoldersHistory entity rules — buildEntity() produces getErrors() non-empty.","commonSituations":"Folder history recorded with an id that isn't a valid folder UUID, data arrays shaped differently across plugin versions (the legacy second __() argument `true` hints at older CakePHP conventions), or callers passing an already-transformed DTO missing required keys.","solutions":["Inspect $folderHistory->getErrors() (included in the ValidationException) to identify the failing field.","Ensure the input array contains a valid folder `id` (UUID) since it is copied to `folder_id`.","Run the model validation rules (validationDefault in FoldersHistoryTable) client-side or in a dry-run entity build before calling create()."],"exampleFix":"// before\n$foldersHistoryTable->create(['id' => $someInt, 'name' => $name]);\n// after\n$entity = $foldersHistoryTable->newEntity($data);\nif ($entity->getErrors()) { /* fix data */ }\n$foldersHistoryTable->create(['id' => $folder->id, 'name' => $folder->name]);","handlingStrategy":"validation","validationCode":"$errors = $foldersHistoryTable->buildEntity($data)->getErrors();\nif (!empty($errors)) {\n    // fix data before calling create()\n    error_log(json_encode($errors));\n}","typeGuard":null,"tryCatchPattern":"try {\n    $foldersHistoryTable->create($data);\n} catch (ValidationException $e) {\n    $errors = $e->getErrors(); // inspect per-field errors\n    // correct $data and retry\n}","preventionTips":["Always pass a valid folder UUID in the `id` key of the data array (it becomes folder_id).","Build a test entity via buildEntity()/newEntity() and check getErrors() in debug before production calls.","Keep entity validation rules and calling code in sync when upgrading plugin versions."],"tags":["validation","folders-history","entity"],"backgroundTag":"schema-validation-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"}