From b954c423d1127a902d449f65985da81c2bacd4be Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 13 Aug 2024 13:07:39 +0200 Subject: [PATCH 1/2] 2077: Force webform_revision to be null on submissions --- composer.json | 3 +- composer.lock | 2 +- .../WebformRevisionController.patch | 12 +++++ .../os2forms_selvbetjening.install | 23 +++++++++ .../os2forms_selvbetjening.services.yml | 5 ++ .../src/Helper/InstallHelper.php | 51 +++++++++++++++++++ 6 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 patches/drupal/config_entity_revisions/WebformRevisionController.patch create mode 100644 web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install create mode 100644 web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php diff --git a/composer.json b/composer.json index 240f86d0..8e1c234a 100644 --- a/composer.json +++ b/composer.json @@ -141,7 +141,8 @@ "drupal/config_entity_revisions": { "Add check to see if entity revision actually exists(https://www.drupal.org/project/config_entity_revisions/issues/3277467)": "https://www.drupal.org/files/issues/2022-04-27/add-check-to-see-if-entity-revision-actually-exists-3277467-3.patch", "https://www.drupal.org/project/config_entity_revisions/issues/3260602": "https://www.drupal.org/files/issues/2022-03-15/content_entity_revisions-3260602-07.patch", - "webform_revisions_install called twice during site:install --existing-config": "patches/drupal/config_entity_revisions/webform_revisions.install.patch" + "webform_revisions_install called twice during site:install --existing-config": "patches/drupal/config_entity_revisions/webform_revisions.install.patch", + "Always set webform_revision to NULL on webform submissions": "patches/drupal/config_entity_revisions/WebformRevisionController.patch" }, "drupal/permissions_by_term": { "Change check for node form": "patches/drupal/permissions_by_term/changeNodeCheck.patch" diff --git a/composer.lock b/composer.lock index 0e912318..35685d09 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "07708cd52b7439c020935b1474268e09", + "content-hash": "4eafaaacc35211f07fe011b47db6388c", "packages": [ { "name": "asm89/stack-cors", diff --git a/patches/drupal/config_entity_revisions/WebformRevisionController.patch b/patches/drupal/config_entity_revisions/WebformRevisionController.patch new file mode 100644 index 00000000..eefe4cc8 --- /dev/null +++ b/patches/drupal/config_entity_revisions/WebformRevisionController.patch @@ -0,0 +1,12 @@ +diff --git a/modules/webform_revisions/src/Controller/WebformRevisionsController.php b/modules/webform_revisions/src/Controller/WebformRevisionsController.php +index f7dc1ef..273716d 100644 +--- a/modules/webform_revisions/src/Controller/WebformRevisionsController.php ++++ b/modules/webform_revisions/src/Controller/WebformRevisionsController.php +@@ -90,6 +90,6 @@ class WebformRevisionsController extends ConfigEntityRevisionsControllerBase imp + /* @var $webform \Drupal\webform_revisions\Entity\WebformRevisions */ + $webform = $entity->getWebform(); + +- $entity->set('webform_revision', $webform->getRevisionID()); ++ $entity->set('webform_revision', NULL); + } + } diff --git a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install new file mode 100644 index 00000000..e8a9b54b --- /dev/null +++ b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install @@ -0,0 +1,23 @@ +nullifyExistingWebformSubmissionRevisions($form, $form_state, $form_id); +} diff --git a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.services.yml b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.services.yml index caebc046..94b811b2 100644 --- a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.services.yml +++ b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.services.yml @@ -18,3 +18,8 @@ services: - '@router.admin_context' tags: - { name: 'event_subscriber' } + + Drupal\os2forms_selvbetjening\Helper\InstallHelper: + arguments: + - '@module_handler' + - '@database' diff --git a/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php b/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php new file mode 100644 index 00000000..ebdd254c --- /dev/null +++ b/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php @@ -0,0 +1,51 @@ +moduleInstaller->moduleExists('webform_revisions')) { + return; + } + + // Loop through all submissions setting webform_revision to null. + try { + $this->connection->update('webform_submission') + ->fields([ + 'webform_revision' => NULL, + ]) + ->execute(); + } + catch (\Exception $e) { + throw new SelvbetjeningException('Unable to update webform revisions on submissions.', $e->getCode(), $e); + } + } + +} From 9f3f4592e449fb37c354904649d5c384ead5fc8a Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 13 Aug 2024 13:14:26 +0200 Subject: [PATCH 2/2] 2077: Coding standards --- CHANGELOG.md | 1 + .../os2forms_selvbetjening/os2forms_selvbetjening.install | 7 ++++--- .../os2forms_selvbetjening/src/Helper/InstallHelper.php | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7d15eb8..5e5f0eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Nedenfor ses dato for release og beskrivelse af opgaver som er implementeret. * Tilføjede mulighed for csv eksport af alle formular konfigurationer. * Opdaterede docker-compose node setup. +* Sikrede at `webform_revision` på indsendelser altid er `NULL`. ## [2.7.14] 2024-07-02 diff --git a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install index e8a9b54b..e0d237c0 100644 --- a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install +++ b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.install @@ -15,9 +15,10 @@ use Drupal\os2forms_selvbetjening\Helper\InstallHelper; * This is done to avoid various issues we have encountered with * webform revisions e.g. stray submissions and repeated identical joins * during load of submissions. - * Future submissions is handled by a patch ensuring it is always set to NULL, - * @see patches/drupal/config_entity_revisions/WebformRevisionController.patch. + * Future submissions is handled by a patch ensuring it is always set to NULL. + * + * @see patches/drupal/config_entity_revisions/WebformRevisionController.patch */ function os2forms_selvbetjening_update_9501() { - Drupal::service(InstallHelper::class)->nullifyExistingWebformSubmissionRevisions($form, $form_state, $form_id); + Drupal::service(InstallHelper::class)->nullifyExistingWebformSubmissionRevisions(); } diff --git a/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php b/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php index ebdd254c..78bdf079 100644 --- a/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php +++ b/web/modules/custom/os2forms_selvbetjening/src/Helper/InstallHelper.php @@ -27,8 +27,6 @@ public function __construct( /** * Nullify webform revision on existing webform submissions. - * - * @throws \Drupal\os2forms_selvbetjening\Exception\SelvbetjeningException */ public function nullifyExistingWebformSubmissionRevisions() { if (!$this->moduleInstaller->moduleExists('webform_revisions')) {