From 3fdcd279254e41e323d64b95e7efafe5b9bab19f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 11:06:03 +0100 Subject: [PATCH] Combine Duplicate/Limit catches in createField Same shape as the row-flush combine: multi-type catch with a small ternary for the per-type message. Two pairs collapsed: the single attribute path and the relationship two-way path (which differ only in 'Attribute limit exceeded' vs 'Column limit exceeded'). --- src/Migration/Destinations/Appwrite.php | 36 ++++++------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 67a20a15c7..22fc0efe61 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -691,23 +691,14 @@ class Appwrite extends Destination $this->dbForProject->checkAttribute($table, $column); $column = $this->dbForProject->createDocument('attributes', $column); - } catch (DuplicateException $e) { - $resource->setStatus(Resource::STATUS_ERROR, 'Attribute already exists'); + } catch (DuplicateException | LimitException $e) { + $message = $e instanceof DuplicateException ? 'Attribute already exists' : 'Attribute limit exceeded'; + $resource->setStatus(Resource::STATUS_ERROR, $message); $this->addError(new Exception( resourceName: $resource->getName(), resourceGroup: $resource->getGroup(), resourceId: $resource->getId(), - message: 'Attribute already exists', - previous: $e, - )); - return false; - } catch (LimitException $e) { - $resource->setStatus(Resource::STATUS_ERROR, 'Attribute limit exceeded'); - $this->addError(new Exception( - resourceName: $resource->getName(), - resourceGroup: $resource->getGroup(), - resourceId: $resource->getId(), - message: 'Attribute limit exceeded', + message: $message, previous: $e, )); return false; @@ -753,27 +744,16 @@ class Appwrite extends Destination ]); $this->dbForProject->createDocument('attributes', $twoWayAttribute); - } catch (DuplicateException $e) { + } catch (DuplicateException | LimitException $e) { $this->dbForProject->deleteDocument('attributes', $column->getId()); - $resource->setStatus(Resource::STATUS_ERROR, 'Attribute already exists'); + $message = $e instanceof DuplicateException ? 'Attribute already exists' : 'Column limit exceeded'; + $resource->setStatus(Resource::STATUS_ERROR, $message); $this->addError(new Exception( resourceName: $resource->getName(), resourceGroup: $resource->getGroup(), resourceId: $resource->getId(), - message: 'Attribute already exists', - previous: $e, - )); - return false; - } catch (LimitException $e) { - $this->dbForProject->deleteDocument('attributes', $column->getId()); - - $resource->setStatus(Resource::STATUS_ERROR, 'Column limit exceeded'); - $this->addError(new Exception( - resourceName: $resource->getName(), - resourceGroup: $resource->getGroup(), - resourceId: $resource->getId(), - message: 'Column limit exceeded', + message: $message, previous: $e, )); return false;