/** * Harvest OAI-PMH records. * * @return void */ public function harvestoaiAction() { $this->checkLocalSetting(); // Read Config files $configFile = ConfigReader::getConfigPath('oai.ini', 'harvest'); $oaiSettings = @parse_ini_file($configFile, true); if (empty($oaiSettings)) { Console::writeLine("Please add OAI-PMH settings to oai.ini."); return $this->getFailureResponse(); } // If first command line parameter is set, see if we can limit to just the // specified OAI harvester: $argv = $this->consoleOpts->getRemainingArgs(); if (isset($argv[0])) { if (isset($oaiSettings[$argv[0]])) { $oaiSettings = array($argv[0] => $oaiSettings[$argv[0]]); } else { Console::writeLine("Could not load settings for {$argv[0]}."); return $this->getFailureResponse(); } } // Loop through all the settings and perform harvests: $processed = 0; foreach ($oaiSettings as $target => $settings) { if (!empty($target) && !empty($settings)) { Console::writeLine("Processing {$target}..."); try { $harvest = new OAI($target, $settings); $harvest->launch(); } catch (\Exception $e) { Console::writeLine($e->getMessage()); return $this->getFailureResponse(); } $processed++; } } // All done. Console::writeLine("Completed without errors -- {$processed} source(s) processed."); return $this->getSuccessResponse(); }
/** * Transform $xmlFile using the provided $properties configuration. * * @param string $xmlFile XML file to transform. * @param string $properties Properties file. * * @throws \Exception * @return mixed Transformed XML. */ protected function generateXML($xmlFile, $properties) { // Load properties file: $properties = ConfigReader::getConfigPath($properties, 'import'); if (!file_exists($properties)) { throw new \Exception("Cannot load properties file: {$properties}."); } $options = parse_ini_file($properties, true); // Make sure required parameter is set: if (!isset($options['General']['xslt'])) { throw new \Exception("Properties file ({$properties}) is missing General/xslt setting."); } $xslFile = ConfigReader::getConfigPath($options['General']['xslt'], 'import/xsl'); // Initialize the XSL processor: $xsl = $this->initProcessor($options); // Load up the style sheet $style = new DOMDocument(); if (!$style->load($xslFile)) { throw new \Exception("Problem loading XSL file: {$xslFile}."); } $xsl->importStyleSheet($style); // Load up the XML document $xml = new DOMDocument(); if (!$xml->load($xmlFile)) { throw new \Exception("Problem loading XML file: {$xmlFile}."); } // Process and return the XML through the style sheet $result = $xsl->transformToXML($xml); if (!$result) { throw new \Exception("Problem transforming XML."); } return $result; }
/** * Support action for config -- attempt to enable auto configuration. * * @return mixed */ public function enableautoconfigAction() { $configFile = ConfigReader::getConfigPath('config.ini'); $writer = new \VuFind\Config\Writer($configFile); $writer->set('System', 'autoConfigure', 1); if ($writer->save()) { $this->flashMessenger()->setNamespace('info')->addMessage('Auto-configuration enabled.'); // Reload config now that it has been edited (otherwise, old setting // will persist in cache): ConfigReader::getConfig(null, true); } else { $this->flashMessenger()->setNamespace('error')->addMessage('Could not enable auto-configuration; check permissions on ' . $configFile . '.'); } return $this->forwardTo('Admin', 'Config'); }
/** * Map string using a config file from the translation_maps folder. * * @param string $in string to map. * @param string $filename filename of map file * * @return string mapped text. * @access public */ public static function mapString($in, $filename) { // Load the translation map and send back the appropriate value. Note // that PHP's parse_ini_file() function is not compatible with SolrMarc's // style of properties map, so we are parsing this manually. $map = array(); $mapFile = ConfigReader::getConfigPath($filename, 'import/translation_maps'); foreach (file($mapFile) as $line) { $parts = explode('=', $line, 2); if (isset($parts[1])) { $key = trim($parts[0]); $map[$key] = trim($parts[1]); } } return isset($map[$in]) ? $map[$in] : $in; }