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

Commit

Permalink
Missing directory separator (#4)
Browse files Browse the repository at this point in the history
* Missing directory separator

* Add registration of twig templates incase we don't register the TwigService

* Relative path from CollectionService/Provider directory

* Various fixes to CollectionService

* PSR-2 issues
  • Loading branch information
whikloj authored and ruebot committed May 26, 2016
1 parent 72a54ef commit 3505f02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/CollectionService/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public function create(Application $app, Request $request, $id)

if (201 == $responsePost->getStatusCode()) {// OK, collection created
//Lets take the location header in the response
$collection_fedora_url = $responsePost->headers->get('location');
$indirect_container_rdf = $app['twig']->render(
'createIndirectContainerfromTS.json',
array(
'resource' => $responsePost->headers->get('location'),
'resource' => $collection_fedora_url,
)
);

$subRequestPut = Request::create(
$urlRoute.$id,
$urlRoute . $id,
'PUT',
array(),
$request->cookies->all(),
Expand All @@ -123,29 +123,33 @@ public function create(Application $app, Request $request, $id)
);
$subRequestPut->query->set('tx', $tx);
$subRequestPut->headers->set('Slug', 'members');
//Can't use in middleware, but needed. Without Fedora 4 throws big java errors!
$subRequestPut->headers->set('Host', $app['config']['islandora']['fedoraHost'], true);
$subRequestPut->headers->set('Content-Type', 'application/ld+json');
$subRequestPut->headers->set('Content-Length', strlen($indirect_container_rdf));
$app['islandora.hostHeaderNormalize']($subRequestPut);
//Here is the thing. We don't know if UUID of the collection we just created is already in the triple store.
//So what to do?
//We could just try to use our routes directly, but UUID check agains triplestore we could fail!
//Let's invoke the controller method directly
// $responsePut = $app->handle($subRequestPut, HttpKernelInterface::SUB_REQUEST, false);
$responsePut = $app['islandora.resourcecontroller']->put(
$app,
$subRequestPut,
$responsePost->headers->get('location'),
$collection_fedora_url,
"members"
);
if (201 == $responsePut->getStatusCode()) {// OK, indirect container created
$islandora_collection_uri = $urlRoute.$uuid;
//Include headers from the parent one, some of the last one. Basically rewrite everything
$putHeaders = $responsePut->getHeaders();
//Guzzle psr7 response objects are inmutable. So we have to make this an array and add directly
$putHeaders['Link'] = array('<'.$responsePut->getBody().'>; rel="alternate"');
$putHeaders['Link'] = array('<'.$urlRoute.$uuid.'/members>; rel="hub"');
$putHeaders['Location'] = array($urlRoute.$uuid);
$putHeaders['Link'] = array(
'<'.$collection_fedora_url.'>; rel="alternate"',
'<'.$urlRoute.$uuid.'/members>; rel="hub"',
);
$putHeaders['Location'] = array($islandora_collection_uri);
$putHeaders['Content-Length'] = strlen($islandora_collection_uri);
//Should i care about the etag?
return new Response($putHeaders['Location'][0], 201, $putHeaders);
return new Response($islandora_collection_uri, 201, $putHeaders);
}

return $responsePut;
Expand Down
3 changes: 3 additions & 0 deletions src/CollectionService/Provider/CollectionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function (
}
)
);
} else {
# Add our templates to the existing twig instance.
$app['twig.loader']->addLoader(new \Twig_Loader_Filesystem(__DIR__ . '/../templates'));
}
if (!isset($app['api'])) {
$app['api'] = $app->share(
Expand Down
2 changes: 1 addition & 1 deletion src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// TODO: Not register all template directories right now.
$app->register(new \Silex\Provider\TwigServiceProvider(), array(
'twig.path' => array(
__DIR__ . 'CollectionService/templates',
__DIR__ . '/CollectionService/templates',
),
));

Expand Down

0 comments on commit 3505f02

Please sign in to comment.