From 1cbb21fbcde56edf7a935500e1b90991b49b8cd0 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 19 Jun 2024 15:58:56 +0200 Subject: [PATCH] Backport code from #5928. (#6042) --- .../Commands/sql/SanitizeSessionsCommands.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Drupal/Commands/sql/SanitizeSessionsCommands.php b/src/Drupal/Commands/sql/SanitizeSessionsCommands.php index b514760131..f748e2732b 100644 --- a/src/Drupal/Commands/sql/SanitizeSessionsCommands.php +++ b/src/Drupal/Commands/sql/SanitizeSessionsCommands.php @@ -35,13 +35,22 @@ public function getDatabase() #[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: SanitizeCommands::SANITIZE)] public function sanitize($result, CommandData $commandData): void { - $this->getDatabase()->truncate('sessions')->execute(); - $this->logger()->success(dt('Sessions table truncated.')); + if ($this->applies()) { + $this->database->truncate('sessions')->execute(); + $this->logger()->success(dt('Sessions table truncated.')); + } } #[CLI\Hook(type: HookManager::ON_EVENT, target: SanitizeCommands::CONFIRMS)] public function messages(&$messages, InputInterface $input): void { - $messages[] = dt('Truncate sessions table.'); + if ($this->applies()) { + $messages[] = dt('Truncate sessions table.'); + } + } + + private function applies(): bool + { + return $this->database->schema()->tableExists('sessions'); } }