btmash / islandora_entity_bridge

Islandora Entity Bridge
MIT License
7 stars 3 forks source link

datastream validation in handlers #3

Open t4k opened 9 years ago

t4k commented 9 years ago

As an example, see: https://github.com/btmash/islandora_entity_bridge/blob/7.x-1.x/handlers/views_islandora_entity_bridge_handler_field_datastream_xml.inc#L47

My use case was the following:

  1. Create a block display of an IEB view with a contextual filter of the PID.
  2. Place that block everywhere, expecting it to only show results when they were available.
  3. Lots of errors when on a collection page, such as /islandora/object/islandora:root because there is no MODS datastream.

I think it may have crashed Fedora. I had to restart Fedora afterwards.

Hopefully there is a way to validate that the datastream supplied in the Views option exists before continuing with the code that renders it. This would be useful for all existing handlers: Image, Link, XML, and XPath.

I'm going to commit a variation on this soon for the different handlers:

  $url = "{$GLOBALS['base_url']}/islandora/object/{$entity->pid}/datastream/{$this->options['datastream']}/view";
  $handle = @fopen($url, 'r');
  if ($handle !== FALSE) {
    $xml = file_get_contents($url);
    $doc = new DOMDocument('1.0');
    $doc->preserveWhiteSpace = FALSE;
    $doc->formatOutput = TRUE;
    $doc->loadXML($xml);
    $content = htmlentities($doc->saveXML());
  }
btmash commented 9 years ago

The one other option I would suggest is instead load the islandora datastream with islandora_datastream_load ($dsid, $fedora_object_id) and check if the datastream exists that way. It would be cleaner than using the baseurl file_get_contents and fopen