diff --git a/src/CollectionService/Controller/CollectionController.php b/src/CollectionService/Controller/CollectionController.php index 71a3d49..26d13ed 100644 --- a/src/CollectionService/Controller/CollectionController.php +++ b/src/CollectionService/Controller/CollectionController.php @@ -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(), @@ -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; diff --git a/src/CollectionService/Provider/CollectionServiceProvider.php b/src/CollectionService/Provider/CollectionServiceProvider.php index 1dc54d4..4cf6c62 100644 --- a/src/CollectionService/Provider/CollectionServiceProvider.php +++ b/src/CollectionService/Provider/CollectionServiceProvider.php @@ -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( diff --git a/src/index.php b/src/index.php index 6484030..561e224 100644 --- a/src/index.php +++ b/src/index.php @@ -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', ), ));