From 7c2ae79c7ed3ae3d7b4cc480395972d56be3f407 Mon Sep 17 00:00:00 2001 From: Adrian Lorenc <adrian.lorenc@gmail.com> Date: Wed, 26 Mar 2025 15:10:35 +0100 Subject: [PATCH 1/4] ISAICP-9614: Disable sanitization. --- .../Commands/WebformAssessmentCommands.php | 56 +------------------ 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php index 018ffc228e..d4fa080528 100644 --- a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php +++ b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php @@ -4,36 +4,18 @@ namespace Drupal\joinup_assessment\Drush\Commands; -use Consolidation\AnnotatedCommand\CommandData; use Consolidation\AnnotatedCommand\Hooks\HookManager; -use Drupal\Core\DependencyInjection\AutowireTrait; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\mysql\Driver\Database\mysql\Connection; use Drush\Attributes as CLI; use Drush\Commands\DrushCommands; use Drush\Commands\sql\sanitize\SanitizeCommands; -use Drush\Commands\sql\sanitize\SanitizePluginInterface; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Overwrites Webform Drush sanitization plugins. * * @see \Drush\Commands\sql\sanitize\SanitizeCommands::sanitize() */ -class WebformAssessmentCommands extends DrushCommands implements SanitizePluginInterface { - - use AutowireTrait; - - public function __construct( - #[Autowire(service: 'database')] - protected readonly Connection $database, - protected readonly EntityTypeManagerInterface $entityTypeManager, - protected readonly ModuleHandlerInterface $moduleHandler, - ) { - parent::__construct(); - } +class WebformAssessmentCommands extends DrushCommands { /** * Disables default webform sanitization. @@ -49,40 +31,4 @@ public function disableDefaultWebformSanitization(InputInterface $input): void { $input->setOption('sanitize-webform-submissions', 'no'); } - /** - * {@inheritdoc} - */ - #[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: 'sql-sanitize')] - public function sanitize($result, CommandData $commandData): void { - $webformStorage = $this->entityTypeManager->getStorage('webform_submission'); - $querySubmission = $webformStorage->getQuery() - ->condition('webform_id', 'assessment', '!=') - ->accessCheck(FALSE); - - do { - $sids = $querySubmission->range(0, 50)->execute(); - - if (!empty($sids)) { - $webformStorage->delete( - $webformStorage->loadMultiple($sids) - ); - } - } while (!empty($sids)); - - if ($this->moduleHandler->moduleExists('webform_submission_log')) { - $this->database->truncate('webform_submission_log')->execute(); - } - - $this->logger() - ->success('Webform submission tables truncated except for the assessment.'); - } - - /** - * {@inheritdoc} - */ - #[CLI\Hook(type: HookManager::ON_EVENT, target: SanitizeCommands::CONFIRMS)] - public function messages(&$messages, InputInterface $input): void { - $messages[] = dt('Sanitize webform submission data except for the assessment.'); - } - } -- GitLab From 9bec20928b44bd6fb4aca3f6fdd3831c38365c89 Mon Sep 17 00:00:00 2001 From: Adrian Lorenc <adrian.lorenc@gmail.com> Date: Wed, 26 Mar 2025 15:34:41 +0100 Subject: [PATCH 2/4] Revert "ISAICP-9614: Disable sanitization." This reverts commit 7c2ae79c7ed3ae3d7b4cc480395972d56be3f407. --- .../Commands/WebformAssessmentCommands.php | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php index d4fa080528..018ffc228e 100644 --- a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php +++ b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php @@ -4,18 +4,36 @@ namespace Drupal\joinup_assessment\Drush\Commands; +use Consolidation\AnnotatedCommand\CommandData; use Consolidation\AnnotatedCommand\Hooks\HookManager; +use Drupal\Core\DependencyInjection\AutowireTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\mysql\Driver\Database\mysql\Connection; use Drush\Attributes as CLI; use Drush\Commands\DrushCommands; use Drush\Commands\sql\sanitize\SanitizeCommands; +use Drush\Commands\sql\sanitize\SanitizePluginInterface; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Overwrites Webform Drush sanitization plugins. * * @see \Drush\Commands\sql\sanitize\SanitizeCommands::sanitize() */ -class WebformAssessmentCommands extends DrushCommands { +class WebformAssessmentCommands extends DrushCommands implements SanitizePluginInterface { + + use AutowireTrait; + + public function __construct( + #[Autowire(service: 'database')] + protected readonly Connection $database, + protected readonly EntityTypeManagerInterface $entityTypeManager, + protected readonly ModuleHandlerInterface $moduleHandler, + ) { + parent::__construct(); + } /** * Disables default webform sanitization. @@ -31,4 +49,40 @@ public function disableDefaultWebformSanitization(InputInterface $input): void { $input->setOption('sanitize-webform-submissions', 'no'); } + /** + * {@inheritdoc} + */ + #[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: 'sql-sanitize')] + public function sanitize($result, CommandData $commandData): void { + $webformStorage = $this->entityTypeManager->getStorage('webform_submission'); + $querySubmission = $webformStorage->getQuery() + ->condition('webform_id', 'assessment', '!=') + ->accessCheck(FALSE); + + do { + $sids = $querySubmission->range(0, 50)->execute(); + + if (!empty($sids)) { + $webformStorage->delete( + $webformStorage->loadMultiple($sids) + ); + } + } while (!empty($sids)); + + if ($this->moduleHandler->moduleExists('webform_submission_log')) { + $this->database->truncate('webform_submission_log')->execute(); + } + + $this->logger() + ->success('Webform submission tables truncated except for the assessment.'); + } + + /** + * {@inheritdoc} + */ + #[CLI\Hook(type: HookManager::ON_EVENT, target: SanitizeCommands::CONFIRMS)] + public function messages(&$messages, InputInterface $input): void { + $messages[] = dt('Sanitize webform submission data except for the assessment.'); + } + } -- GitLab From 32cb839817d7c5ecacbb94f84d28405cf78a83bf Mon Sep 17 00:00:00 2001 From: Adrian Lorenc <adrian.lorenc@gmail.com> Date: Wed, 26 Mar 2025 15:51:53 +0100 Subject: [PATCH 3/4] ISAICP-9614: Use DB API instead of entity. --- .../Commands/WebformAssessmentCommands.php | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php index 018ffc228e..36594a4e9b 100644 --- a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php +++ b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php @@ -9,6 +9,7 @@ use Drupal\Core\DependencyInjection\AutowireTrait; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\joinup_assessment\AssessmentInterface; use Drupal\mysql\Driver\Database\mysql\Connection; use Drush\Attributes as CLI; use Drush\Commands\DrushCommands; @@ -54,25 +55,20 @@ public function disableDefaultWebformSanitization(InputInterface $input): void { */ #[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: 'sql-sanitize')] public function sanitize($result, CommandData $commandData): void { - $webformStorage = $this->entityTypeManager->getStorage('webform_submission'); - $querySubmission = $webformStorage->getQuery() - ->condition('webform_id', 'assessment', '!=') - ->accessCheck(FALSE); + $this->database->delete('webform_submission') + ->condition('webform_id', AssessmentInterface::WEBFORM_ID, '!=') + ->execute(); - do { - $sids = $querySubmission->range(0, 50)->execute(); - - if (!empty($sids)) { - $webformStorage->delete( - $webformStorage->loadMultiple($sids) - ); - } - } while (!empty($sids)); + $this->database->delete('webform_submission_data') + ->condition('webform_id', AssessmentInterface::WEBFORM_ID, '!=') + ->execute(); if ($this->moduleHandler->moduleExists('webform_submission_log')) { $this->database->truncate('webform_submission_log')->execute(); } + $this->entityTypeManager->getStorage('webform_submission')->resetCache(); + $this->logger() ->success('Webform submission tables truncated except for the assessment.'); } -- GitLab From dc89dd3eb7cbd733f8ab0cac5f8ee47ef6750789 Mon Sep 17 00:00:00 2001 From: Adrian Lorenc <adrian.lorenc@gmail.com> Date: Wed, 26 Mar 2025 16:01:21 +0100 Subject: [PATCH 4/4] ISAICP-9614: Use ANSI SQL standard --- .../src/Drush/Commands/WebformAssessmentCommands.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php index 36594a4e9b..3f59ac905b 100644 --- a/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php +++ b/web/modules/custom/joinup_assessment/src/Drush/Commands/WebformAssessmentCommands.php @@ -56,11 +56,11 @@ public function disableDefaultWebformSanitization(InputInterface $input): void { #[CLI\Hook(type: HookManager::POST_COMMAND_HOOK, target: 'sql-sanitize')] public function sanitize($result, CommandData $commandData): void { $this->database->delete('webform_submission') - ->condition('webform_id', AssessmentInterface::WEBFORM_ID, '!=') + ->condition('webform_id', AssessmentInterface::WEBFORM_ID, '<>') ->execute(); $this->database->delete('webform_submission_data') - ->condition('webform_id', AssessmentInterface::WEBFORM_ID, '!=') + ->condition('webform_id', AssessmentInterface::WEBFORM_ID, '<>') ->execute(); if ($this->moduleHandler->moduleExists('webform_submission_log')) { -- GitLab