prevent non empty category removal
This commit is contained in:
@@ -415,7 +415,9 @@
|
||||
"select2OrMoreRecords": "Select 2 or more records",
|
||||
"selectNotMoreThanNumberRecords": "Select not more than {number} records",
|
||||
"selectAtLeastOneRecord": "Select at least one record",
|
||||
"duplicateConflict": "A record already exists."
|
||||
"duplicateConflict": "A record already exists.",
|
||||
"cannotRemoveCategoryWithChildCategory": "Cannot remove a category that has a child category.",
|
||||
"cannotRemoveNotEmptyCategory": "Cannot remove a non-empty category."
|
||||
},
|
||||
"boolFilters": {
|
||||
"onlyMy": "Only My",
|
||||
|
||||
@@ -313,6 +313,33 @@ class RecordTree extends Record
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
* @throws BadRequest
|
||||
*/
|
||||
protected function beforeDeleteEntity(Entity $entity)
|
||||
{
|
||||
parent::beforeDeleteEntity($entity);
|
||||
|
||||
$childCategory = $this->entityManager
|
||||
->getRelation($entity, 'children')
|
||||
->findOne();
|
||||
|
||||
if ($childCategory) {
|
||||
throw Forbidden::createWithBody(
|
||||
'cannotRemoveCategoryWithChildCategory',
|
||||
Error\Body::create()->withMessageTranslation('cannotRemoveCategoryWithChildCategory')
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->checkItemIsEmpty($entity)) {
|
||||
throw Forbidden::createWithBody(
|
||||
'cannotRemoveNotEmptyCategory',
|
||||
Error\Body::create()->withMessageTranslation('cannotRemoveNotEmptyCategory')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(string $id, stdClass $data, UpdateParams $params): Entity
|
||||
{
|
||||
if (!empty($data->parentId) && $data->parentId === $id) {
|
||||
|
||||
Reference in New Issue
Block a user