Skip to content

Commit

Permalink
Update hook to delete webform submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 17, 2024
1 parent 3d9ef65 commit 0ed1984
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,12 @@ function su_humsci_profile_update_9715() {
/**
* Remove any existing hs_webform paragraph entities.
*/
function su_humsci_profile_update_9716($sandbox) {
function su_humsci_profile_update_9716(&$sandbox) {
$paragraph_storage = \Drupal::entityTypeManager()->getStorage('paragraph');
$paragraph_machine_name = 'hs_webform';

if (empty($sandbox['ids'])) {
$sandbox['ids'] = $paragraph_storage->getQuery()
->condition('type', $paragraph_machine_name)
->condition('type', 'hs_webform')
->accessCheck(FALSE)
->execute();
$sandbox['total'] = count($sandbox['ids']);
Expand All @@ -1062,10 +1061,30 @@ function su_humsci_profile_update_9716($sandbox) {
$sandbox['#finished'] = count($sandbox['ids']) ? 1 - count($sandbox['ids']) / $sandbox['total'] : 1;
}

/**
* Delete webform submissions.
*/
function _su_humsci_profile_update_9617(&$sandbox){
$submission_storage = \Drupal::entityTypeManager()->getStorage('webform_submission');
if (empty($sandbox['ids'])) {
$sandbox['ids'] = $submission_storage->getQuery()
->accessCheck(FALSE)
->execute();
$sandbox['total'] = count($sandbox['ids']);
}
$submission_ids = array_splice($sandbox['ids'], 0, 50);

foreach ($submission_storage->loadMultiple($submission_ids) as $submission) {
$submission->delete();
}

$sandbox['#finished'] = count($sandbox['ids']) ? 1 - count($sandbox['ids']) / $sandbox['total'] : 1;
}

/**
* Delete hs_webform paragraph type and remove webform config.
*/
function su_humsci_profile_update_9717() {
function su_humsci_profile_update_9718() {
$paragraph_machine_name = 'hs_webform';
// Delete the field_hs_webform field storage (and field instances).
FieldStorageConfig::load('field_hs_webform')?->delete();
Expand All @@ -1092,7 +1111,7 @@ function su_humsci_profile_update_9717() {
/**
* Uninstall hs_webform and webform modules.
*/
function su_humsci_profile_update_9718() {
function su_humsci_profile_update_9719() {
// Uninstalls modules after removing configs to prevent updb errors.
\Drupal::service('module_installer')->uninstall(['hs_webform', 'webform_ui', 'webform']);
}

0 comments on commit 0ed1984

Please sign in to comment.