diff --git a/application/Espo/Controllers/FieldManager.php b/application/Espo/Controllers/FieldManager.php index 66f46418c8..f6e3ceff76 100644 --- a/application/Espo/Controllers/FieldManager.php +++ b/application/Espo/Controllers/FieldManager.php @@ -55,7 +55,12 @@ class FieldManager extends \Espo\Core\Controllers\Base $fieldManager = $this->getContainer()->get('fieldManager'); $fieldManager->create($data['name'], $data, $params['scope']); - $this->getContainer()->get('dataManager')->rebuild($params['scope']); + try { + $this->getContainer()->get('dataManager')->rebuild($params['scope']); + } catch (Error $e) { + $fieldManager->delete($data['name'], $params['scope']); + throw new Error($e->getMessage()); + } return $fieldManager->read($data['name'], $params['scope']); } diff --git a/application/Espo/Core/Utils/FieldManager.php b/application/Espo/Core/Utils/FieldManager.php index aa6b6cd69e..fff763a7a7 100644 --- a/application/Espo/Core/Utils/FieldManager.php +++ b/application/Espo/Core/Utils/FieldManager.php @@ -22,7 +22,8 @@ namespace Espo\Core\Utils; -use \Espo\Core\Exceptions\Error; +use \Espo\Core\Exceptions\Error, + \Espo\Core\Exceptions\Conflict; class FieldManager { @@ -74,7 +75,7 @@ class FieldManager { $existingField = $this->getFieldDef($name, $scope); if (isset($existingField)) { - throw new Error('Field ['.$name.'] exists in '.$scope); + throw new Conflict('Field ['.$name.'] exists in '.$scope); } return $this->update($name, $fieldDef, $scope);