Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "remove prefix" option to record deletes #4204

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading