From 44de884ee5b96327170c6fe0117655c3e366062b Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 16 Mar 2023 09:31:48 +0200 Subject: [PATCH] convert relatedOptions to options --- app/controllers/api/databases.php | 27 ++++++++++++--------------- app/workers/databases.php | 16 ++++++++-------- docker-compose.yml | 2 ++ phpunit.xml | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 1ea5e176df..e27bc87f26 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -68,7 +68,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att $formatOptions = $attribute->getAttribute('formatOptions', []); $filters = $attribute->getAttribute('filters', []); // filters are hidden from the endpoint $default = $attribute->getAttribute('default'); - $relationshipOptions = $attribute->getAttribute('relationshipOptions', []); + $options = $attribute->getAttribute('options', []); $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -98,7 +98,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } if ($type === Database::VAR_RELATIONSHIP) { - $relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $relationshipOptions['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } @@ -122,7 +122,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'format' => $format, 'formatOptions' => $formatOptions, 'filters' => $filters, - 'relationshipOptions' => $relationshipOptions, + 'options' => $options, ]); $dbForProject->checkAttribute($collection, $attribute); @@ -1394,7 +1394,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati 'default' => null, 'array' => false, 'filters' => [], - 'relationshipOptions' => [ + 'options' => [ 'relatedCollection' => $relatedCollectionId, 'relationType' => $type, 'twoWay' => $twoWay, @@ -1409,17 +1409,14 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati $events ); - $options = $attribute->getAttribute('relationshipOptions', []); - - if (!empty($options)) { - $attribute->setAttribute('relatedCollection', $options['relatedCollection']); - $attribute->setAttribute('relationType', $options['relationType']); - $attribute->setAttribute('twoWay', $options['twoWay']); - $attribute->setAttribute('twoWayKey', $options['twoWayKey']); - $attribute->setAttribute('onUpdate', $options['onUpdate']); - $attribute->setAttribute('onDelete', $options['onDelete']); - $attribute->setAttribute('side', $options['side']); - } + $options = $attribute->getAttribute('options', []); + $attribute->setAttribute('relatedCollection', $options['relatedCollection'] || null); + $attribute->setAttribute('relationType', $options['relationType'] || null); + $attribute->setAttribute('twoWay', $options['twoWay'] || null); + $attribute->setAttribute('twoWayKey', $options['twoWayKey'] || null); + $attribute->setAttribute('onUpdate', $options['onUpdate'] || null); + $attribute->setAttribute('onDelete', $options['onDelete'] || null); + $attribute->setAttribute('side', $options['side'] || null); $response ->setStatusCode(Response::STATUS_CODE_ACCEPTED) diff --git a/app/workers/databases.php b/app/workers/databases.php index 9fef6d1bc3..667bdf9aa0 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -91,22 +91,22 @@ class DatabaseV1 extends Worker $format = $attribute->getAttribute('format', ''); $formatOptions = $attribute->getAttribute('formatOptions', []); $filters = $attribute->getAttribute('filters', []); - $relationshipOptions = $attribute->getAttribute('relationshipOptions', []); + $options = $attribute->getAttribute('options', []); $project = $dbForConsole->getDocument('projects', $projectId); try { if ($type === Database::VAR_RELATIONSHIP) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $relationshipOptions['relatedCollection']); + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ( !$dbForProject->createRelationship( collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), - type: $relationshipOptions['relationType'], - twoWay: $relationshipOptions['twoWay'], - id: $relationshipOptions['id'], - twoWayKey: $relationshipOptions['twoWayKey'], - onUpdate: $relationshipOptions['onUpdate'], - onDelete: $relationshipOptions['onDelete'], + type: $options['relationType'] || null, + twoWay: $options['twoWay'] || null, + id: $options['id'] || null, + twoWayKey: $options['twoWayKey'] || null, + onUpdate: $options['onUpdate'] || null, + onDelete: $options['onDelete'] || null, ) ) { throw new Exception('Failed to create Attribute'); diff --git a/docker-compose.yml b/docker-compose.yml index 8ba1ff0566..288d77509f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,6 +83,7 @@ services: - ./docs:/usr/src/code/docs - ./public:/usr/src/code/public - ./src:/usr/src/code/src + - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework depends_on: - mariadb - redis @@ -344,6 +345,7 @@ services: - ./app:/usr/src/code/app - ./src:/usr/src/code/src #- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database + - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework depends_on: - redis - mariadb diff --git a/phpunit.xml b/phpunit.xml index 5b4bcdb99c..a448fcc8c7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" >