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'); } }