{"record":{"id":"98497da54672e5db","repo":"passbolt/passbolt_api","slug":"the-resource-type-can-not-be-deleted-as-resources-of-this","errorCode":null,"errorMessage":"The resource type can not be deleted as resources of this type still exist.","messagePattern":"The resource type can not be deleted as resources of this type still exist\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php","lineNumber":80,"sourceCode":"        }\n\n        $highlander = new ResourceTypesIsTheLastOneCheckService();\n        if ($highlander->isLastOfTheDefaultVersion($resourceType)) {\n            throw new BadRequestException(__('You cannot delete the last resource type of the default version.'));\n        }\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","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php#L62-L98","documentation":"Safety check in ResourceTypesDeleteService::delete(): a resource type cannot be soft-deleted while resources of that type still exist. Fires when the resources table reports a non-zero count of resources referencing the type, preventing orphaned resources; admins must migrate or delete those resources first. (Related guards block deleting the last resource type of the default version or the last available type.)","triggerScenarios":"Thrown at plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php:80 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete or move resources of this type first","Bulk-edit resources to another type before retrying"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}