From 39a5de462de4cc12a48a26ae7ded9a2c675ca917 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20Gro=C3=9Fberndt?= <stephan.grossberndt@typo3.org>
Date: Wed, 21 Jun 2023 13:07:39 +0200
Subject: [PATCH] [BUGFIX] Avoid exception for recent documents

Backend no longer crashes with an TableNotFoundException if a
table has been removed and an according item is in the list
of recent documents.

The patch catches the exception.

Releases: main, 12.4, 11.5
Resolves: #101139
Change-Id: I489d8cf1ee2bb10800fe2966ae4fc1cb0bcd57c5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79852
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
---
 .../Backend/ToolbarItems/OpendocsToolbarItem.php    | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php b/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php
index e5bc6e51c745..7a6113d62b2a 100644
--- a/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php
+++ b/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php
@@ -17,6 +17,7 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Opendocs\Backend\ToolbarItems;
 
+use Doctrine\DBAL\Exception\TableNotFoundException;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Domain\Model\Element\ImmediateActionElement;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
@@ -140,7 +141,17 @@ class OpendocsToolbarItem implements ToolbarItemInterface, RequestAwareToolbarIt
     {
         $table = $document[3]['table'] ?? '';
         $uid = $document[3]['uid'] ?? 0;
-        $record = BackendUtility::getRecordWSOL($table, $uid);
+
+        try {
+            $record = BackendUtility::getRecordWSOL($table, $uid);
+        } catch (TableNotFoundException) {
+            // This exception is caught in cases, when you have an recently opened document
+            // from an extension record (let's say a sys_note record) and then uninstall
+            // the extension and drop the DB table. After then, the DB table could
+            // not be found anymore and will throw an exception making the
+            // whole backend unusable.
+            $record = null;
+        }
 
         if (!is_array($record)) {
             // Record seems to be deleted
-- 
GitLab