From b6f1fe4207ba8072ae62f9122b2b9d47517a3fd9 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 4 Aug 2021 10:31:22 +1200 Subject: [PATCH] NEW Add support for comma separated ids in ReindexItemJob This allows manual creation of multiple index jobs via the CMS jobs interface (i.e 1,2,3) to publish all 3 pages --- src/Jobs/AlgoliaIndexItemJob.php | 4 ++-- src/Service/AlgoliaQuerier.php | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Jobs/AlgoliaIndexItemJob.php b/src/Jobs/AlgoliaIndexItemJob.php index e0919c9..7e47aa6 100644 --- a/src/Jobs/AlgoliaIndexItemJob.php +++ b/src/Jobs/AlgoliaIndexItemJob.php @@ -26,7 +26,7 @@ public function __construct($itemClass = null, $itemIds = null) if ($itemIds) { if (!is_array($itemIds)) { - $this->itemIds = [$itemIds]; + $this->itemIds = explode(',', $itemIds); } else { $this->itemIds = $itemIds; } @@ -116,7 +116,7 @@ public function process() unset($obj); } - $this->remainingChildren = $remainingChildren; + $this->remainingIds = $remainingChildren; if (!count($remainingChildren)) { $this->isComplete = true; diff --git a/src/Service/AlgoliaQuerier.php b/src/Service/AlgoliaQuerier.php index eaab6e6..bdbf28b 100644 --- a/src/Service/AlgoliaQuerier.php +++ b/src/Service/AlgoliaQuerier.php @@ -70,12 +70,15 @@ function array_key_first(array $arr) } } - $output = PaginatedList::create($records) - ->setCurrentPage($results['page'] + 1) - ->setTotalItems($results['nbHits']) - ->setLimitItems(false) - ->setPageStart($results['page'] * $results['hitsPerPage']) - ->setPageLength($results['hitsPerPage']); + $output = PaginatedList::create($records); + + if ($results) { + $output = $output->setCurrentPage($results['page'] + 1) + ->setTotalItems($results['nbHits']) + ->setLimitItems(false) + ->setPageStart($results['page'] * $results['hitsPerPage']) + ->setPageLength($results['hitsPerPage']); + } return $output; }