Пример #1
0
 /**
  * Helper function to get records from cached source-specific record data
  *
  * @param Record $cachedRecord Record data
  *
  * @return \VuFind\RecordDriver\AbstractBase
  */
 protected function getVuFindRecord($cachedRecord)
 {
     $source = $cachedRecord['source'];
     $doc = unserialize($cachedRecord['data']);
     // Solr records are loaded in special-case fashion:
     if ($source === 'VuFind' || $source === 'Solr') {
         $driver = $this->recordFactoryManager->getSolrRecord($doc);
     } else {
         $driver = $this->recordFactoryManager->get($source);
         $driver->setRawData($doc);
     }
     $driver->setSourceIdentifier($source);
     return $driver;
 }
Пример #2
0
 /**
  * Given an array of associative arrays with id and source keys (or pipe-
  * separated source|id strings), load all of the requested records in the
  * requested order.
  *
  * @param array $ids Array of associative arrays with id/source keys or
  * strings in source|id format.  In associative array formats, there is
  * also an optional "extra_fields" key which can be used to pass in data
  * formatted as if it belongs to the Solr schema; this is used to create
  * a mock driver object if the real data source is unavailable.
  *
  * @throws \Exception
  * @return array     Array of record drivers
  */
 public function loadBatch($ids)
 {
     // Sort the IDs by source -- we'll create an associative array indexed by
     // source and record ID which points to the desired position of the indexed
     // record in the final return array:
     $idBySource = [];
     foreach ($ids as $i => $details) {
         // Convert source|id string to array if necessary:
         if (!is_array($details)) {
             $parts = explode('|', $details, 2);
             $ids[$i] = $details = ['source' => $parts[0], 'id' => $parts[1]];
         }
         $idBySource[$details['source']][$details['id']] = $i;
     }
     // Retrieve the records and put them back in order:
     $retVal = [];
     foreach ($idBySource as $source => $details) {
         $records = $this->loadBatchForSource(array_keys($details), $source);
         foreach ($records as $current) {
             $id = $current->getUniqueId();
             // In theory, we should be able to assume that $details[$id] is
             // set... but in practice, we can't make that assumption. In some
             // cases, Summon IDs will change, and requests for an old ID value
             // will return a record with a different ID.
             if (isset($details[$id])) {
                 $retVal[$details[$id]] = $current;
             }
         }
     }
     // Check for missing records and fill gaps with \VuFind\RecordDriver\Missing
     // objects:
     foreach ($ids as $i => $details) {
         if (!isset($retVal[$i]) || !is_object($retVal[$i])) {
             $fields = isset($details['extra_fields']) ? $details['extra_fields'] : [];
             $fields['id'] = $details['id'];
             $retVal[$i] = $this->recordFactory->get('Missing');
             $retVal[$i]->setRawData($fields);
             $retVal[$i]->setSourceIdentifier($details['source']);
         }
     }
     // Send back the final array, with the keys in proper order:
     ksort($retVal);
     return $retVal;
 }
Пример #3
0
 /**
  * Test expected interface.
  *
  * @return void
  *
  * @expectedException        Zend\ServiceManager\Exception\RuntimeException
  * @expectedExceptionMessage Plugin ArrayObject does not belong to VuFind\RecordDriver\AbstractBase
  */
 public function testExpectedInterface()
 {
     $pm = new PluginManager(null);
     $pm->validatePlugin(new \ArrayObject());
 }