From 6d1cdab1006fce06bfdda38ee9e8b688f7a8cf78 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 22 May 2014 17:30:26 -0500 Subject: [PATCH] [#177] Ensure DB-Connected configuration is properly updated The Admin UI sends the entire DB-Connected resource across in every request. This raises an issue, because the `resource_class` is always sent as a `null` value (as we do not want to reference "virtual" resource classes for purposes of the source code view modal). Because this is `null`, we end up updating a null value. We can get the `resource_class` when fetching the original service data by passing a boolean `false` to the `$isAFetchOperation` flag; this forces the DB-Connected `onFetch()` listener to include it when returning the entity. However... we were not passing that flag when doing `updateService()` operations, which meant that updating a DB-Connected service always wrote the DB-Connected configuration under a blank key. This patch does two things: - It now passes the `$isAFetchOperation` flag for update operations. - It now pulls the `resource_class` from the updated REST entity prior to performing db-connected-specific update oparations. --- src/Model/DbConnectedRestServiceModel.php | 8 ++++++++ src/Model/RestServiceModel.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Model/DbConnectedRestServiceModel.php b/src/Model/DbConnectedRestServiceModel.php index 5b07b9d1..959cc586 100644 --- a/src/Model/DbConnectedRestServiceModel.php +++ b/src/Model/DbConnectedRestServiceModel.php @@ -123,6 +123,14 @@ public function createService(DbConnectedRestServiceEntity $entity) public function updateService(DbConnectedRestServiceEntity $entity) { $updatedEntity = $this->restModel->updateService($entity); + + // We need the resource class in order to update db-connected config! + if (! $entity->resourceClass && $updatedEntity->resourceClass) { + $entity->exchangeArray(array( + 'resource_class' => $updatedEntity->resourceClass, + )); + } + $updatedProps = $this->updateDbConnectedConfig($entity); $updatedEntity->exchangeArray($updatedProps); $this->updateHalConfig($entity); diff --git a/src/Model/RestServiceModel.php b/src/Model/RestServiceModel.php index 01cc0a86..d744d832 100644 --- a/src/Model/RestServiceModel.php +++ b/src/Model/RestServiceModel.php @@ -320,7 +320,7 @@ public function updateService(RestServiceEntity $update) $controllerService = $update->controllerServiceName; try { - $original = $this->fetch($controllerService); + $original = $this->fetch($controllerService, false); } catch (Exception\RuntimeException $e) { throw new Exception\RuntimeException(sprintf( 'Cannot update REST service "%s"; not found', @@ -333,7 +333,7 @@ public function updateService(RestServiceEntity $update) $this->updateContentNegotiationConfig($original, $update); $this->updateHalConfig($original, $update); - return $this->fetch($controllerService); + return $this->fetch($controllerService, false); } /**