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