class WebformSanitizeSubmissionsCommands in Webform 8.5
Same name and namespace in other branches
- 6.x src/Commands/WebformSanitizeSubmissionsCommands.php \Drupal\webform\Commands\WebformSanitizeSubmissionsCommands
Drush sql-sanitize plugin for sanitizing (truncating) webform submissions.
Hierarchy
- class \Drupal\webform\Commands\WebformSanitizeSubmissionsCommands extends \Drush\Commands\DrushCommands implements \Drush\Drupal\Commands\sql\SanitizePluginInterface
Expanded class hierarchy of WebformSanitizeSubmissionsCommands
See also
\Drush\Drupal\Commands\sql\SanitizeSessionsCommands
1 string reference to 'WebformSanitizeSubmissionsCommands'
1 service uses WebformSanitizeSubmissionsCommands
File
- src/
Commands/ WebformSanitizeSubmissionsCommands.php, line 18
Namespace
Drupal\webform\CommandsView source
class WebformSanitizeSubmissionsCommands extends DrushCommands implements SanitizePluginInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* WebformSanitizeSubmissionsCommands constructor.
*
* @param \Drupal\Core\Database\Connection $database
* The database.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct();
$this->database = $database;
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
}
/**
* Sanitize webform submissions from the DB.
*
* @hook post-command sql-sanitize
*
* {@inheritdoc}
*/
public function sanitize($result, CommandData $command_data) {
$options = $command_data
->options();
if ($this
->isEnabled($options['sanitize-webform-submissions'])) {
$this->database
->truncate('webform_submission')
->execute();
$this->database
->truncate('webform_submission_data')
->execute();
if ($this->moduleHandler
->moduleExists('webform_submission_log')) {
$this->database
->truncate('webform_submission_log')
->execute();
}
$this->entityTypeManager
->getStorage('webform_submission')
->resetCache();
$this
->logger()
->notice(dt('Webform submission tables truncated.'));
}
}
/**
* @hook option sql-sanitize
* @option sanitize-webform-submissions
* By default, submissions are truncated. Specify 'no' to disable that.
*/
public function options($options = [
'sanitize-webform-submissions' => NULL,
]) {
}
/**
* @hook on-event sql-sanitize-confirms
*
* {@inheritdoc}
*/
public function messages(&$messages, InputInterface $input) {
$options = $input
->getOptions();
if ($this
->isEnabled($options['sanitize-webform-submissions'])) {
$messages[] = dt('Truncate webform submission tables.');
}
}
/**
* Test an option value to see if it is disabled.
*
* @param string $value
* The enabled options value.
*
* @return bool
* TRUE if santize websubmission is enabled.
*/
protected function isEnabled($value) {
return $value !== 'no';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WebformSanitizeSubmissionsCommands:: |
protected | property | The database connection. | |
WebformSanitizeSubmissionsCommands:: |
protected | property | The entity type manager. | |
WebformSanitizeSubmissionsCommands:: |
protected | property | The module handler. | |
WebformSanitizeSubmissionsCommands:: |
protected | function | Test an option value to see if it is disabled. | |
WebformSanitizeSubmissionsCommands:: |
public | function | @hook on-event sql-sanitize-confirms | |
WebformSanitizeSubmissionsCommands:: |
public | function | @hook option sql-sanitize @option sanitize-webform-submissions By default, submissions are truncated. Specify 'no' to disable that. | |
WebformSanitizeSubmissionsCommands:: |
public | function | Sanitize webform submissions from the DB. | |
WebformSanitizeSubmissionsCommands:: |
public | function | WebformSanitizeSubmissionsCommands constructor. |