Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
[#177] Ensure DB-Connected configuration is properly updated
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weierophinney committed May 22, 2014
1 parent 4d2330d commit 6d1cdab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Model/DbConnectedRestServiceModel.php
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Model/RestServiceModel.php
Expand Up @@ -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',
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 6d1cdab

Please sign in to comment.