From dbd7ff04fe2e6e973c52f95ee6eb010498b8c2d8 Mon Sep 17 00:00:00 2001 From: silver Date: Mon, 7 Sep 2026 13:22:33 +0200 Subject: [PATCH 1/2] fix(import): avoid crash when table or view is deleted before import job runs Signed-off-by: silver Assisted-by: ClaudeCode:claude-sonnet-5 --- lib/BackgroundJob/ImportTableJob.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/BackgroundJob/ImportTableJob.php b/lib/BackgroundJob/ImportTableJob.php index 83f0ea2d11..47cce82cfe 100644 --- a/lib/BackgroundJob/ImportTableJob.php +++ b/lib/BackgroundJob/ImportTableJob.php @@ -12,6 +12,7 @@ use OCA\Tables\Db\ViewMapper; use OCA\Tables\Notification\NotificationHelper; use OCA\Tables\Service\ImportService; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\QueuedJob; use OCP\IUserManager; @@ -74,14 +75,20 @@ public function run($argument): void { $this->userSession->setUser($oldUser); } - if (!$tableId && $viewId) { - $tableId = $this->viewMapper->find($viewId)->getTableId(); + try { + if (!$tableId && $viewId) { + $tableId = $this->viewMapper->find($viewId)->getTableId(); + } + $table = $this->tableMapper->find($tableId); + } catch (DoesNotExistException $e) { + $this->logger->warning('Could not trigger import-finished activity, table or view no longer exists: ' . $e->getMessage(), ['exception' => $e]); + return; } if ($importSuccess) { $this->activityManager->triggerEvent( objectType: ActivityManager::TABLES_OBJECT_TABLE, - object: $this->tableMapper->find($tableId), + object: $table, subject: ActivityManager::SUBJECT_IMPORT_FINISHED, additionalParams: [ 'importStats' => $importStats, From d41b6db07f327f3005487b675df0831d8a307d84 Mon Sep 17 00:00:00 2001 From: silver Date: Thu, 10 Sep 2026 14:51:00 +0200 Subject: [PATCH 2/2] fix(import): skip import job when target table or view is gone Signed-off-by: silver Assisted-by:ClaudeCode:claude-opus-5 --- lib/BackgroundJob/ImportTableJob.php | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/BackgroundJob/ImportTableJob.php b/lib/BackgroundJob/ImportTableJob.php index 47cce82cfe..cd868c5354 100644 --- a/lib/BackgroundJob/ImportTableJob.php +++ b/lib/BackgroundJob/ImportTableJob.php @@ -48,6 +48,20 @@ public function run($argument): void { $userId = $argument['user_id']; $tableId = $argument['table_id']; $viewId = $argument['view_id']; + + try { + $view = $viewId ? $this->viewMapper->find($viewId) : null; + $targetTableId = $view?->getTableId() ?? $tableId; + if ($targetTableId === null) { + $this->logger->error('Import job was scheduled without a table or view id, skipping.'); + return; + } + $table = $this->tableMapper->find($targetTableId); + } catch (DoesNotExistException $e) { + $this->logger->warning('Import skipped, table or view no longer exists: ' . $e->getMessage(), ['exception' => $e]); + return; + } + $oldUser = $this->userSession->getUser(); $importSuccess = false; @@ -75,16 +89,6 @@ public function run($argument): void { $this->userSession->setUser($oldUser); } - try { - if (!$tableId && $viewId) { - $tableId = $this->viewMapper->find($viewId)->getTableId(); - } - $table = $this->tableMapper->find($tableId); - } catch (DoesNotExistException $e) { - $this->logger->warning('Could not trigger import-finished activity, table or view no longer exists: ' . $e->getMessage(), ['exception' => $e]); - return; - } - if ($importSuccess) { $this->activityManager->triggerEvent( objectType: ActivityManager::TABLES_OBJECT_TABLE, @@ -100,17 +104,17 @@ public function run($argument): void { $notifySubject = ActivityManager::SUBJECT_IMPORT_FAILED; } - if ($viewId) { + if ($view !== null) { $this->notificationHelper->sendNotification( objectType: ActivityManager::TABLES_OBJECT_VIEW, - object: $this->viewMapper->find($viewId), + object: $view, subject: $notifySubject, author: $userId ); } else { $this->notificationHelper->sendNotification( objectType: ActivityManager::TABLES_OBJECT_TABLE, - object: $this->tableMapper->find($tableId), + object: $table, subject: $notifySubject, author: $userId );