Make demo purge independent of Elasticsearch
This commit is contained in:
@@ -94,6 +94,10 @@ class Command(BaseCommand):
|
||||
|
||||
def _purge_products(self, *, dry_run: bool, keep_only_idea_products: bool) -> int:
|
||||
from oscar.core.loading import get_model
|
||||
from oscar_elasticsearch.search.signal_handlers import (
|
||||
deregister_signal_handlers,
|
||||
register_signal_handlers,
|
||||
)
|
||||
|
||||
Product = get_model("catalogue", "Product")
|
||||
products = Product.objects.all()
|
||||
@@ -110,11 +114,20 @@ class Command(BaseCommand):
|
||||
|
||||
removed = 0
|
||||
iterable = candidates if isinstance(candidates, list) else list(candidates)
|
||||
for product in iterable:
|
||||
removed += 1
|
||||
self.stdout.write(
|
||||
f"PRODUCT {'[dry-run] ' if dry_run else ''}delete id={product.id} title={product.title}"
|
||||
)
|
||||
if not dry_run:
|
||||
if dry_run:
|
||||
for product in iterable:
|
||||
removed += 1
|
||||
self.stdout.write(
|
||||
f"PRODUCT [dry-run] delete id={product.id} title={product.title}"
|
||||
)
|
||||
return removed
|
||||
|
||||
deregister_signal_handlers()
|
||||
try:
|
||||
for product in iterable:
|
||||
removed += 1
|
||||
self.stdout.write(f"PRODUCT delete id={product.id} title={product.title}")
|
||||
product.delete()
|
||||
finally:
|
||||
register_signal_handlers()
|
||||
return removed
|
||||
|
||||
Reference in New Issue
Block a user