From 9468c238de25d169eba6507789a050eab71a5ef2 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 30 Mar 2023 13:01:58 +1300 Subject: [PATCH] Remove conflicts --- app/controllers/api/databases.php | 2 +- app/workers/databases.php | 48 ++++--------------- composer.json | 2 +- phpunit.xml | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 2 - 5 files changed, 11 insertions(+), 45 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index dfb6afea91..3449896ad6 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -153,7 +153,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'collectionInternalId' => $relatedCollection->getInternalId(), 'collectionId' => $relatedCollection->getId(), 'type' => $type, - 'status' => 'available', // processing, available, failed, deleting, stuck + 'status' => 'processing', // processing, available, failed, deleting, stuck 'size' => $size, 'required' => $required, 'signed' => $signed, diff --git a/app/workers/databases.php b/app/workers/databases.php index dc2046e00c..7e004d31a4 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -94,7 +94,6 @@ class DatabaseV1 extends Worker $options = $attribute->getAttribute('options', []); $project = $dbForConsole->getDocument('projects', $projectId); - $related = null; try { switch ($type) { case Database::VAR_RELATIONSHIP: @@ -102,6 +101,7 @@ class DatabaseV1 extends Worker if ($relatedCollection->isEmpty()) { throw new Exception('Collection not found'); } + if ( !$dbForProject->createRelationship( collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), @@ -116,41 +116,10 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } - $metadata = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId()); - - $related = \array_filter($metadata->getAttribute('attributes', []), function ($a) use ($options) { - return $a['$id'] === $options['twoWayKey']; - }); - - /** - * @var Document $related - */ - $related = end($related); - $options = $related->getAttribute('options', []); - $options['relatedCollection'] = $collection->getId(); - - $related = new Document([ - '$id' => ID::custom($database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $related->getId()), - 'key' => $related->getId(), - 'databaseInternalId' => $database->getInternalId(), - 'databaseId' => $database->getId(), - 'collectionInternalId' => $relatedCollection->getInternalId(), - 'collectionId' => $relatedCollection->getId(), - 'status' => 'available', - 'type' => Database::VAR_RELATIONSHIP, - 'size' => 0, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - 'signed' => false, - 'format' => '', - 'formatOptions' => [], - 'options' => $options, - ]); - - $related = $dbForProject->createDocument('attributes', $related); - + if ($options['twoWay']) { + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'available')); + } break; default: if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { @@ -159,14 +128,13 @@ class DatabaseV1 extends Worker } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - // todo: needs to clean cache for related colllection? - } catch (\Throwable $th) { Console::error($th->getMessage()); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); - if (Database::VAR_RELATIONSHIP === $type) { - $dbForProject->updateDocument('attributes', $related->getId(), $related->setAttribute('status', 'failed')); + if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { + $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'failed')); } } finally { $target = Realtime::fromPayload( diff --git a/composer.json b/composer.json index 175c422f21..89c37a1275 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,7 @@ "utopia-php/swoole": "0.5.*", "utopia-php/websocket": "0.1.*", "resque/php-resque": "1.3.6", - "matomo/device-detector": "6.0.0", + "matomo/device-detector": "6.0.*", "dragonmantank/cron-expression": "3.3.1", "influxdb/influxdb-php": "1.15.2", "phpmailer/phpmailer": "6.6.0", diff --git a/phpunit.xml b/phpunit.xml index a448fcc8c7..5b4bcdb99c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 6829e8d3f1..701eebb777 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -3439,8 +3439,6 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ])); -var_dump($libraryAttributesResponse); -die; $this->assertIsArray($libraryAttributesResponse['body']['attributes']); $this->assertEquals(2, $libraryAttributesResponse['body']['total']); // currently = 1