Skip to content

Commit

Permalink
Backport code from drush-ops#5928.
Browse files Browse the repository at this point in the history
  • Loading branch information
brummbar committed Jun 19, 2024
1 parent a0cbfb6 commit 968f6c6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Drupal/Commands/sql/SanitizeSessionsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 968f6c6

Please sign in to comment.