/** * Constructor. * * @param object $logger The Logger object used for logging messages. * @param object $db Mongo database handle. * @param string $source The data source to be harvested. * @param string $basePath RecordManager main directory location * @param array $settings Settings from datasources.ini. * @param string $startToken Optional override for the initial * harvest command (to resume interrupted harvesting) * * @throws Exception */ public function __construct($logger, $db, $source, $basePath, $settings, $startToken = '') { global $configArray; $this->log = $logger; $this->db = $db; // Don't time out during harvest set_time_limit(0); // Check if we have a start date $this->source = $source; $this->loadHarvestDate(); $this->resumptionToken = $startToken; // Set up base URL: if (empty($settings['url'])) { throw new Exception("Missing base URL for {$source}"); } $this->baseURL = $settings['url']; if (isset($settings['set'])) { $this->set = $settings['set']; } if (isset($settings['metadataPrefix'])) { $this->metadata = $settings['metadataPrefix']; } if (isset($settings['idPrefix'])) { $this->idPrefix = $settings['idPrefix']; } if (isset($settings['idSearch'])) { $this->idSearch = $settings['idSearch']; } if (isset($settings['idReplace'])) { $this->idReplace = $settings['idReplace']; } if (isset($settings['dateGranularity'])) { $this->granularity = $settings['dateGranularity']; } if (isset($settings['verbose'])) { $this->verbose = $settings['verbose']; } if (isset($settings['debuglog'])) { $this->debugLog = $settings['debuglog']; } if (isset($settings['oaipmhTransformation'])) { $style = new DOMDocument(); if ($style->load("{$basePath}/transformations/" . $settings['oaipmhTransformation']) === false) { throw new Exception("Could not load {$basePath}/transformations/" . $settings['oaipmhTransformation']); } $this->transformation = new XSLTProcessor(); $this->transformation->importStylesheet($style); } if (isset($settings['ignoreNoRecordsMatch'])) { $this->ignoreNoRecordsMatch = $settings['ignoreNoRecordsMatch']; } if (isset($configArray['Harvesting']['max_tries'])) { $this->maxTries = $configArray['Harvesting']['max_tries']; } if (isset($configArray['Harvesting']['retry_wait'])) { $this->retryWait = $configArray['Harvesting']['retry_wait']; } $this->message('Identifying server'); $response = $this->sendRequest('Identify'); if ($this->granularity == 'auto') { $this->granularity = trim($this->getSingleNode($this->getSingleNode($response, 'Identify'), 'granularity')->nodeValue); $this->message("Detected date granularity: {$this->granularity}"); } $this->serverDate = $this->normalizeDate($this->getSingleNode($response, 'responseDate')->nodeValue); $this->message('Current server date: ' . date('Y-m-d\\TH:i:s\\Z', $this->serverDate)); }