{"record":{"id":"1bd1e72301f5f92a","repo":"passbolt/passbolt_api","slug":"the-resource-type-could-not-be-deleted","errorCode":null,"errorMessage":"The resource type could not be deleted.","messagePattern":"The resource type could not be deleted\\.","errorType":"http","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php","lineNumber":85,"sourceCode":"        }\n        if ($highlander->isTheOnlyOne($resourceType)) {\n            throw new BadRequestException(__('You cannot delete the last resource type available.'));\n        }\n\n        /** @var \\App\\Model\\Table\\ResourcesTable $resourcesTable */\n        $resourcesTable = $this->fetchTable('Resources');\n        $count = $resourcesTable->find()->where([\n            'resource_type_id' => $resourceTypeId,\n            'deleted' => false,\n        ])->all()->count();\n        if ($count !== 0) {\n            $msg = __('The resource type can not be deleted as resources of this type still exist.');\n            throw new BadRequestException($msg);\n        }\n\n        $resourceType->deleted = DateTime::now();\n        if (!$resourcesTypesTable->save($resourceType)) {\n            throw new InternalErrorException(__('The resource type could not be deleted.'));\n        }\n    }\n\n    /**\n     * Undo soft delete a given resource type\n     *\n     * @param \\App\\Utility\\UserAccessControl $uac user access control\n     * @param string $resourceTypeId uuid\n     * @return void\n     * @throws \\Cake\\Http\\Exception\\BadRequestException if the resource type is not deleted\n     * @throws \\Cake\\Http\\Exception\\NotFoundException if resource type is not present\n     */\n    public function undoDelete(UserAccessControl $uac, string $resourceTypeId): void\n    {\n        $uac->assertIsAdmin();\n\n        if (!Validation::uuid($resourceTypeId)) {\n            throw new BadRequestException(__('The resource type identifier should be a UUID.'));","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php#L67-L103","documentation":"Thrown by ResourceTypesDeleteService::delete() when the soft-delete save of the resource type entity fails (save() returns false). It means the 'resources of this type still exist' check passed but persisting the deleted timestamp failed, typically due to model validation or database errors. The InternalErrorException maps to HTTP 500.","triggerScenarios":"Calling the resource type delete API (or the service directly) where $resourcesTypesTable->save($resourceType) returns false after $resourceType->deleted = DateTime::now() — e.g. a DB constraint violation, connection failure, or beforeSave/beforeDelete rules rejecting the save.","commonSituations":"Database down or migration missing (resource_types.deleted column absent); a behavioral rule or validation attached to ResourceTypesTable rejecting the modified entity; concurrency where another process already deleted the row; database permission issues.","solutions":["Check the storage/logs error log and the table's rules (applicationRules) for why save() failed","Run pending migrations (ddev refresh) to ensure the resource_types schema is current","Verify database connectivity and that the row still exists before save","Inspect ResourceTypesTable events (beforeSave/beforeRules) for conditions that block a soft delete"],"exampleFix":"// before\n$resourceType->deleted = DateTime::now();\nif (!$resourcesTypesTable->save($resourceType)) {\n    throw new InternalErrorException(__('The resource type could not be deleted.'));\n}\n// after\n$resourceType->deleted = DateTime::now();\n$resourceType->setDirty('deleted', true);\n$result = $resourcesTypesTable->save($resourceType, ['checkRules' => true]);\nif (!$result) {\n    Log::error('ResourceType delete failed', ['errors' => $resourceType->getErrors()]);\n    throw new InternalErrorException(__('The resource type could not be deleted.'));\n}","handlingStrategy":"try-catch","validationCode":"if (!Validation::uuid($resourceTypeId)) { throw new BadRequestException(__('The resource type identifier should be a UUID.')); }\n$inUse = $resourcesTable->find()->where(['resource_type_id' => $resourceTypeId])->count();\nif ($inUse > 0) { throw new BadRequestException(__('The resource type can not be deleted as resources of this type still exist.')); }","typeGuard":null,"tryCatchPattern":"try {\n    $service->delete($uac, $resourceTypeId);\n} catch (BadRequestException $e) {\n    // resources still exist or invalid id\n} catch (InternalErrorException $e) {\n    Log::error('Delete failed: ' . $resourceType->getErrors());\n}","preventionTips":["Pre-check that no resources reference the type before deleting","Keep resource_types schema migrated (run ddev refresh)","Log entity errors when save() returns false","Avoid disabling ORM transaction handling on the table"],"tags":["database","cakephp","save-failure"],"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"}