Skip to content

Commit

Permalink
Add a "remove prefix" option to record deletes
Browse files Browse the repository at this point in the history
Adds a `--rm-prefix` option that will remove a prefix from identifiers. For example, given an identifier of `KOHA-OAI-TEST:2752849` then using `--rm-prefix KOHA-OAI-TEST:` will result in `2752849` as an identifier passed to Solr to be removed.
  • Loading branch information
dltj committed Jan 23, 2025
1 parent fa781c1 commit 430dc24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion harvest/batch-delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ do
id-prefix=*)
PREFIX=${OPTARG#*=}
;;
rm-prefix)
RMPREFIX="${!OPTIND}";
OPTIND=$(( $OPTIND + 1 ))
;;
rm-prefix=*)
RMPREFIX=${OPTARG#*=}
;;
*)
echo "Unknown option -- ${OPTARG}" >&2
;;
Expand Down Expand Up @@ -60,6 +67,7 @@ then
echo "Options:"
echo "-s: Skip optimize operation after importing."
echo "--id-prefix [prefix]: Specify a prefix to prepend to all IDs."
echo "--rm-prefix [prefix]: Specify a prefix to remove from the beginning of all IDs."
exit 1
fi

Expand Down Expand Up @@ -93,7 +101,7 @@ do
FOUNDSOME=1
fi
echo "Processing $file ..."
php deletes.php $file flat $2 --id-prefix=$PREFIX
php deletes.php $file flat $2 --id-prefix=$PREFIX --rm-prefix=$RMPREFIX
mv $file $BASEPATH/processed/`basename $file`
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ protected function configure()
InputOption::VALUE_REQUIRED,
'Prefix to prepend to all IDs',
''
)->addOption(
'rm-prefix',
null,
InputOption::VALUE_REQUIRED,
'Prefix to remove from all IDs',
''
);
}

Expand Down Expand Up @@ -164,6 +170,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mode = $input->getArgument('format');
$index = $input->getArgument('index');
$prefix = $input->getOption('id-prefix');
$rmprefix = $input->getOption('rm-prefix');

// File doesn't exist?
if (!file_exists($filename)) {
Expand Down Expand Up @@ -194,6 +201,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
};
$ids = array_map($callback, $ids);
}
if (!empty($rmprefix)) {
$callback = function($id) use ($rmprefix) {
return str_starts_with($id, $rmprefix) ? substr($id, strlen($rmprefix)) : $id;
};
$ids = array_map($callback, $ids);
}
$this->solr->deleteRecords($index, $ids);
$output->writeln(
'Delete operation completed.',
Expand Down

0 comments on commit 430dc24

Please sign in to comment.