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

Added --verbose switch to delete tool.

- Resolves VUFIND-1120.
parent aa0f5db4
No related merge requests found
...@@ -307,9 +307,15 @@ class UtilController extends AbstractBase ...@@ -307,9 +307,15 @@ class UtilController extends AbstractBase
*/ */
public function deletesAction() public function deletesAction()
{ {
// Parse the command line parameters -- see if we are in "flat file" mode, // Parse the command line parameters -- check verbosity, see if we are in
// find out what file we are reading in, // "flat file" mode, find out what file we are reading in, and determine
// and determine the index we are affecting! // the index we are affecting!
$this->consoleOpts->addRules(
[
'verbose' => 'Verbose mode',
]
);
$verbose = $this->consoleOpts->getOption('verbose');
$argv = $this->consoleOpts->getRemainingArgs(); $argv = $this->consoleOpts->getRemainingArgs();
$filename = isset($argv[0]) ? $argv[0] : null; $filename = isset($argv[0]) ? $argv[0] : null;
$mode = isset($argv[1]) ? $argv[1] : 'marc'; $mode = isset($argv[1]) ? $argv[1] : 'marc';
...@@ -355,6 +361,9 @@ class UtilController extends AbstractBase ...@@ -355,6 +361,9 @@ class UtilController extends AbstractBase
$ids = []; $ids = [];
// Flat file mode: // Flat file mode:
if ($verbose) {
Console::writeLine("Loading IDs in {$mode} mode.");
}
if ($mode == 'flat') { if ($mode == 'flat') {
foreach (explode("\n", file_get_contents($filename)) as $id) { foreach (explode("\n", file_get_contents($filename)) as $id) {
$id = trim($id); $id = trim($id);
...@@ -369,17 +378,39 @@ class UtilController extends AbstractBase ...@@ -369,17 +378,39 @@ class UtilController extends AbstractBase
? new File_MARCXML($filename) : new File_MARC($filename); ? new File_MARCXML($filename) : new File_MARC($filename);
// Once the records are loaded, the rest of the logic is always the same: // Once the records are loaded, the rest of the logic is always the same:
$missingIdCount = 0;
while ($record = $collection->next()) { while ($record = $collection->next()) {
$idField = $record->getField('001'); $idField = $record->getField('001');
$ids[] = (string)$idField->getData(); if ($idField) {
$ids[] = (string)$idField->getData();
} else {
$missingIdCount++;
}
}
if ($verbose) {
Console::writeLine(
"Encountered $missingIdCount record(s) without IDs."
);
} }
} }
// Delete, Commit and Optimize if necessary: // Delete, Commit and Optimize if necessary:
if (!empty($ids)) { if (!empty($ids)) {
if ($verbose) {
Console::writeLine(
'Attempting to delete ' . count($ids) . ' record(s): '
. implode(', ', $ids)
);
}
$writer = $this->getServiceLocator()->get('VuFind\Solr\Writer'); $writer = $this->getServiceLocator()->get('VuFind\Solr\Writer');
$writer->deleteRecords($index, $ids); $writer->deleteRecords($index, $ids);
if ($verbose) {
Console::writeLine('Delete operation completed.');
}
} elseif ($verbose) {
Console::writeLine('Nothing to delete.');
} }
return $this->getSuccessResponse(); 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