protected function _showError($message, $exit = true, $exitCode = 99) { $this->console->write('ERROR: ', ColorInterface::LIGHT_RED); $this->_showLine($message); if ($exit) { $this->_exit($exitCode); } }
/** * Save an XML file to the Solr index using the specified configuration. * * @param string $xmlFile XML file to transform. * @param string $properties Properties file. * @param string $index Solr index to use. * @param bool $testMode Are we in test-only mode? * * @throws \Exception * @return void */ public function save($xmlFile, $properties, $index = 'Solr', $testMode = false) { // Process the file: $xml = $this->generateXML($xmlFile, $properties); // Save the results (or just display them, if in test mode): if (!$testMode) { $solr = $this->getServiceLocator()->get('VuFind\\Solr\\Writer'); $solr->save($index, new RawXMLDocument($xml)); } else { Console::write($xml . "\n"); } }
/** * Save an XML file to the Solr index using the specified configuration. * * @param string $xmlFile XML file to transform. * @param string $properties Properties file. * @param string $index Solr index to use. * @param bool $testMode Are we in test-only mode? * * @throws \Exception * @return void */ public function save($xmlFile, $properties, $index = 'Solr', $testMode = false) { // Process the file: $xml = $this->generateXML($xmlFile, $properties); // Save the results (or just display them, if in test mode): if (!$testMode) { $solr = ConnectionManager::connectToIndex($index); $result = $solr->saveRecord($xml); } else { Console::write($xml . "\n"); } }
/** * Write a string to the Console. * * @param string $str String to write. * * @return void */ protected function write($str) { // Bypass output when testing: if (defined('VUFIND_PHPUNIT_RUNNING')) { return; } Console::write($str); }
/** * Load set list from the server. * * @return void */ protected function loadSetNames() { Console::write("Loading set list... "); // On the first pass through the following loop, we want to get the // first page of sets without using a resumption token: $params = array(); // Grab set information until we have it all (at which point we will // break out of this otherwise-infinite loop): while (true) { // Process current page of results: $response = $this->sendRequest('ListSets', $params); if (isset($response->ListSets->set)) { foreach ($response->ListSets->set as $current) { $spec = (string) $current->setSpec; $name = (string) $current->setName; if (!empty($spec)) { $this->setNames[$spec] = $name; } } } // Is there a resumption token? If so, continue looping; if not, // we're done! if (isset($response->ListSets->resumptionToken) && !empty($response->ListSets->resumptionToken)) { $params['resumptionToken'] = (string) $response->ListSets->resumptionToken; } else { Console::writeLine("found " . count($this->setNames)); return; } } }
/** * Merge harvested MARC records into a single <collection> * * @return \Zend\Console\Response * @author Thomas Schwaerzler <*****@*****.**> */ public function mergemarcAction() { $this->checkLocalSetting(); $argv = $this->consoleOpts->getRemainingArgs(); $dir = isset($argv[0]) ? rtrim($argv[0], '/') : ''; if (empty($dir)) { $scriptName = $this->getRequest()->getScriptName(); Console::writeLine('Merge MARC XML files into a single <collection>;'); Console::writeLine('writes to stdout.'); Console::writeLine(''); Console::writeLine('Usage: ' . $scriptName . ' <path_to_directory>'); Console::writeLine('<path_to_directory>: a directory containing MARC XML files to merge'); return $this->getFailureResponse(); } if (!($handle = opendir($dir))) { Console::writeLine("Cannot open directory: {$dir}"); return $this->getFailureResponse(); } Console::writeLine('<collection>'); while (false !== ($file = readdir($handle))) { // Only operate on XML files: if (pathinfo($file, PATHINFO_EXTENSION) === "xml") { // get file content $filePath = $dir . '/' . $file; $fileContent = file_get_contents($filePath); // output content: Console::writeLine("<!-- {$filePath} -->"); Console::write($fileContent); } } Console::writeLine('</collection>'); }