Skip to content
Snippets Groups Projects
Commit 39408b13 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Add MARC lint utility.

parent 5d6b6a25
No related merge requests found
......@@ -127,6 +127,7 @@ class Module implements \Zend\ModuleManager\Feature\ConsoleUsageProviderInterfac
'util expire_searches' => 'Database search table cleanup',
'util expire_sessions' => 'Database session table cleanup',
'util index_reserves' => 'Solr reserves indexer',
'util lint_marc' => 'MARC validator',
'util optimize' => 'Solr optimize tool',
'util sitemap' => 'XML sitemap generator',
'util suppressed' => 'Remove ILS-suppressed records from Solr',
......
......@@ -77,6 +77,7 @@ $routes = [
'util/expire_searches' => 'util expire_searches [--help|-h] [--batch=] [--sleep=] [<daysOld>]',
'util/expire_sessions' => 'util expire_sessions [--help|-h] [--batch=] [--sleep=] [<daysOld>]',
'util/index_reserves' => 'util index_reserves [--help|-h] [-d=s] [-t=s] [-f=s]',
'util/lint_marc' => 'util lint_marc [<filename>]',
'util/optimize' => 'util optimize [<core>]',
'util/sitemap' => 'util sitemap [--verbose]',
'util/suppressed' => 'util suppressed [--help|-h] [--authorities] [--outfile=s]',
......
......@@ -1001,4 +1001,30 @@ class UtilController extends AbstractBase
Console::writeLine("\tFinished.");
return $this->getSuccessResponse();
}
/**
* Lint a file of MARC records.
*
* @return \Zend\Console\Response
*/
public function lintmarcAction()
{
$request = $this->getRequest();
$filename = $request->getParam('filename');
$marc = substr($filename, -3) !== 'xml'
? new File_MARC($filename) : new File_MARCXML($filename);
$linter = new \File_MARC_Lint();
$i = 0;
while ($record = $marc->next()) {
$i++;
$field001 = $record->getField('001');
$field001 = $field001 ? (string)$field001->getData() : 'undefined';
Console::writeLine("Checking record $i (001 = $field001)...");
$warnings = $linter->checkRecord($record);
if (count($warnings) > 0) {
Console::writeLine('Warnings: ' . implode("\n", $warnings));
}
}
return $this->getSuccessResponse();
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment