From 554b0bd704c7a6c0757faa2e42e77c89b3202c9c Mon Sep 17 00:00:00 2001
From: Alexander Opitz <opitz.alexander@googlemail.com>
Date: Tue, 4 Apr 2023 15:00:53 +0200
Subject: [PATCH] [BUGFIX] DatabaseUpdatedPrerequisite returns correct
 ensure-state
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The `ensure` method must return true,
if all operations were successful.

This is the case if all database
operations succeeded without returning
an error message.

The error messages are now checked
correctly and the corresponding state
is returned.

Resolves: #100428
Releases: main, 12.4, 11.5
Change-Id: I95911b065f8796d1eedf73438efde82ba01a07db
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79354
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
---
 .../Updates/DatabaseUpdatedPrerequisite.php        | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/typo3/sysext/install/Classes/Updates/DatabaseUpdatedPrerequisite.php b/typo3/sysext/install/Classes/Updates/DatabaseUpdatedPrerequisite.php
index 821ab93c07dd..4a278300e4b8 100644
--- a/typo3/sysext/install/Classes/Updates/DatabaseUpdatedPrerequisite.php
+++ b/typo3/sysext/install/Classes/Updates/DatabaseUpdatedPrerequisite.php
@@ -47,12 +47,16 @@ class DatabaseUpdatedPrerequisite implements PrerequisiteInterface, ChattyInterf
     public function ensure(): bool
     {
         $adds = $this->databaseUpgradeWizardsService->getBlockingDatabaseAdds();
-        $result = null;
-        if (count($adds) > 0) {
-            $this->output->writeln('Performing ' . count($adds) . ' database operations.');
-            $result = $this->databaseUpgradeWizardsService->addMissingTablesAndFields();
+        // Nothing to add, early return
+        if ($adds === []) {
+            return true;
         }
-        return $result === null;
+
+        $this->output->writeln('Performing ' . count($adds) . ' database operations.');
+        // remove potentially empty error messages
+        $errorMessages = array_filter($this->databaseUpgradeWizardsService->addMissingTablesAndFields());
+
+        return $errorMessages === [];
     }
 
     public function isFulfilled(): bool
-- 
GitLab