From e6099546597ef5e915fcdc240c8d1b173d766c42 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Sun, 8 Aug 2021 18:07:59 -0400 Subject: [PATCH] Fix logic for finding matching attribute --- app/controllers/api/database.php | 24 ++++++++++++------------ bin/worker-database | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 1ebb857da..939265c27 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -717,21 +717,21 @@ App::delete('/v1/database/collections/:collectionId/attributes/:attributeId') throw new Exception('Collection not found', 404); } - $attributes = $collection->getAttributes(); + /** @var Document[] $attributes */ + $attributes = $collection->getAttribute('attributes'); - // Search for attribute - $attributeIndex = array_search($attributeId, array_column($attributes, '$id')); - - if ($attributeIndex === false) { - throw new Exception('Attribute not found', 404); + // find attribute in collection + $attribute = null; + foreach ($attributes as $a) { + if ($a->getId() === $attributeId) { + $attribute = $a->setAttribute('$collection', $collectionId); // set the collectionId + break; // break once attribute is found + } } - $attribute = new Document([\array_merge($attributes[$attributeIndex], [ - 'collectionId' => $collectionId, - ])]); - - $type = $attribute->getAttribute('type', ''); - $format = $attribute->getAttribute('format', ''); + if (\is_null($attribute)) { + throw new Exception('Attribute not found', 404); + } $database ->setParam('type', DELETE_TYPE_ATTRIBUTE) diff --git a/bin/worker-database b/bin/worker-database index 97e067d0d..3dfbeaaad 100644 --- a/bin/worker-database +++ b/bin/worker-database @@ -7,4 +7,4 @@ else REDIS_BACKEND="redis://${_APP_REDIS_USER}:${_APP_REDIS_PASS}@${_APP_REDIS_HOST}:${_APP_REDIS_PORT}" fi -QUEUE='v1-database' APP_INCLUDE='/usr/src/code/app/workers/database.php' php /usr/src/code/vendor/bin/resque -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php \ No newline at end of file +INTERVAL=0.1 QUEUE='v1-database' APP_INCLUDE='/usr/src/code/app/workers/database.php' php /usr/src/code/vendor/bin/resque -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php \ No newline at end of file