The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 92a1e399 authored by Demian Katz's avatar Demian Katz
Browse files

Resolving VUFIND-459 -- adding utility to merge harvested MARC XML records...

Resolving VUFIND-459 -- adding utility to merge harvested MARC XML records (adapted from the work of Thomas Schwaerzler).
parent 51d027cf
No related merge requests found
<?php
/**
* Merge harvested MARC records into a single <collection>
*
* PHP version 5
*
* Copyright (c) Demian Katz 2010.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Harvest_Tools
* @author Thomas Schwaerzler <thomas.schwaerzler@uibk.ac.at>
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/authority_control Wiki
*/
// Load the Zend framework -- this will automatically trigger the appropriate
// controller action based on directory and file names
define('CLI_DIR', __DIR__); // save directory name of current script
require_once __DIR__ . '/../public/index.php';
\ No newline at end of file
......@@ -43,7 +43,7 @@ class HarvestController extends AbstractBase
/**
* Harvest the LC Name Authority File.
*
* @return void
* @return \Zend\Console\Response
*/
public function harvestnafAction()
{
......@@ -70,7 +70,7 @@ class HarvestController extends AbstractBase
/**
* Harvest OAI-PMH records.
*
* @return void
* @return \Zend\Console\Response
*/
public function harvestoaiAction()
{
......@@ -120,4 +120,49 @@ class HarvestController extends AbstractBase
);
return $this->getSuccessResponse();
}
/**
* Merge harvested MARC records into a single <collection>
*
* @return \Zend\Console\Response
* @author Thomas Schwaerzler <thomas.schwaerzler@uibk.ac.at>
*/
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>');
}
}
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