From 10233799b619c088041a022d444c11f091f96c19 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Mon, 2 Dec 2024 20:14:04 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Catch=20error=20when=20index=20doesn?= =?UTF-8?q?=E2=80=99t=20exist=20yet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/templates/utility.twig | 6 +++++- src/utilities/ScoutUtility.php | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) 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; From 96cf49099903ccfb749520d70914940c0ac4d2a1 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Mon, 2 Dec 2024 20:15:13 +0100 Subject: [PATCH 2/2] Changelog for 4.1.2 --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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",