Skip to content

Commit

Permalink
cli: Require PID type for reindexing
Browse files Browse the repository at this point in the history
* Adds the required `pid-type` parameter to the reindex that specifies
  the type of PID.
  • Loading branch information
switowski authored and lnielsen committed May 25, 2017
1 parent e49b609 commit 279e303
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/app-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export FLASK_APP=app.py

# Load fixtures
flask fixtures records
flask index reindex --yes-i-know
flask index reindex --yes-i-know -t recid
flask index run
12 changes: 9 additions & 3 deletions invenio_indexer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ def run(delayed, concurrency):
@click.option('--yes-i-know', is_flag=True, callback=abort_if_false,
expose_value=False,
prompt='Do you really want to reindex all records?')
@click.option('-t', '--pid-type', multiple=True, required=True)
@with_appcontext
def reindex():
"""Reindex all records."""
def reindex(pid_type, ids=None):
"""Reindex all records.
:param pid_type: Pid type.
"""
click.secho('Sending records to indexing queue ...', fg='green')

query = (x[0] for x in PersistentIdentifier.query.filter_by(
pid_type='recid', object_type='rec', status=PIDStatus.REGISTERED
object_type='rec', status=PIDStatus.REGISTERED
).filter(
PersistentIdentifier.pid_type.in_(pid_type)
).values(
PersistentIdentifier.object_uuid
))
Expand Down
8 changes: 6 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def test_reindex(app, script_info):
obj=script_info)
assert 0 == res.exit_code

res = runner.invoke(cli.reindex, ['--yes-i-know'], obj=script_info)
res = runner.invoke(cli.reindex,
['--yes-i-know', '-t', 'recid'],
obj=script_info)
assert 0 == res.exit_code
res = runner.invoke(cli.run, [], obj=script_info)
assert 0 == res.exit_code
Expand All @@ -103,7 +105,9 @@ def test_reindex(app, script_info):
db.session.commit()
# Destroy the index and reindex
list(current_search.delete(ignore=[404]))
res = runner.invoke(cli.reindex, ['--yes-i-know'], obj=script_info)
res = runner.invoke(cli.reindex,
['--yes-i-know', '-t', 'recid'],
obj=script_info)
assert 0 == res.exit_code
res = runner.invoke(cli.run, [], obj=script_info)
assert 0 == res.exit_code
Expand Down

0 comments on commit 279e303

Please sign in to comment.