From 407ccddc2f9b8200598ca48e1e0a5d62f90550e8 Mon Sep 17 00:00:00 2001 From: Damiano Chini Date: Tue, 30 Jun 2020 18:00:39 +0200 Subject: [PATCH] Director rollback in case of existing object during live-creation --- library/Director/Cli/ObjectCommand.php | 3 ++- library/Director/Core/CoreApi.php | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/library/Director/Cli/ObjectCommand.php b/library/Director/Cli/ObjectCommand.php index c8a876d8..146a6dd0 100644 --- a/library/Director/Cli/ObjectCommand.php +++ b/library/Director/Cli/ObjectCommand.php @@ -124,7 +124,8 @@ class ObjectCommand extends Command if ($this->api()->createObjectAtRuntime($object)) { echo "Live creation for '$name' succeeded\n"; } else { - echo "Live creation for '$name' succeeded\n"; + echo "Live creation for '$name' failed\n"; + $object->delete(); exit(1); } diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index 8dd90007..9461d1b3 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -314,10 +314,11 @@ class CoreApi implements DeploymentApiInterface $key = $object->getShortTableName(); $command = sprintf( - "f = function() {\n" - . ' existing = get_%s("%s")' - . "\n if (existing) { return false }" - . "\n%s\n}\nInternal.run_with_activation_context(f)\n", + 'existing = get_%s("%s")' + . "\nf = function() {\n" + . "%s\n}\n" + . "if (existing) { false } else {\n" + . "Internal.run_with_activation_context(f)\n}\n", $key, $object->get('object_name'), (string) $object