diff --git a/CHANGELOG.md b/CHANGELOG.md index 22d2dca..7078752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 4.1.2 - 2024-12-02 +### Fixed +- Don't through an error on the CP Utility when an index isn't created yet ([#343](https://github.com/studioespresso/craft-scout/issues/343)) + ## 4.1.1 - 2024-07-15 ### Fixed - Removed debug log that tripped some Sentry loggers ([#312](https://github.com/studioespresso/craft-scout/issues/312)) diff --git a/composer.json b/composer.json index 0786d51..c2e985d 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "studioespresso/craft-scout", "description": "Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.", "type": "craft-plugin", - "version": "4.1.1", + "version": "4.1.2", "keywords": [ "craft", "cms", diff --git a/src/templates/utility.twig b/src/templates/utility.twig index bdbd999..6e02135 100644 --- a/src/templates/utility.twig +++ b/src/templates/utility.twig @@ -22,7 +22,11 @@ {{ "Records in Index"|t("scout") }} - {{ index.indexed }} + {% if not index.indexEmpty %} + {{ index.indexed }} + {% else %} + {{ "Index not synced yet"|t("scout") }} + {% endif %} {% endif %} diff --git a/src/utilities/ScoutUtility.php b/src/utilities/ScoutUtility.php index 75c57e6..8fd33f3 100644 --- a/src/utilities/ScoutUtility.php +++ b/src/utilities/ScoutUtility.php @@ -2,6 +2,7 @@ namespace rias\scout\utilities; +use Algolia\AlgoliaSearch\Exceptions\NotFoundException; use Craft; use craft\base\Utility; use Illuminate\Support\Arr; @@ -61,11 +62,19 @@ public static function contentHtml(): string $elementType = $engine->scoutIndex->enforceElementType ? $engine->scoutIndex->elementType : 'Mixed Element Types'; + try { + $totalRecords = $engine->getTotalRecords(); + $indexEmpty = false; + } catch (NotFoundException $e) { + $totalRecords = 0; + $indexEmpty = true; + } + $stats = array_merge($stats, [ 'elementType' => $elementType, 'sites' => $sites, - 'indexed' => $engine->getTotalRecords(), - 'elements' => $totalElements, + 'indexed' => $totalRecords, + 'indexEmpty' => $indexEmpty, 'elements' => $totalElements, ]); } return $stats;