Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2077: Force webform_revision to be null on submissions #325

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @file
* Install file for OS2Forms Selvbetjening module.
*/

use Drupal\os2forms_selvbetjening\Helper\InstallHelper;

/**
* Implements hook_update_N().
*
* Set webform_revision to NULL on all existing submissions.
*
* 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

*/
function os2forms_selvbetjening_update_9501() {
Drupal::service(InstallHelper::class)->nullifyExistingWebformSubmissionRevisions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ services:
- '@router.admin_context'
tags:
- { name: 'event_subscriber' }

Drupal\os2forms_selvbetjening\Helper\InstallHelper:
arguments:
- '@module_handler'
- '@database'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Drupal\os2forms_selvbetjening\Helper;

use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\os2forms_selvbetjening\Exception\SelvbetjeningException;

/**
* Helper for install.
*/
class InstallHelper {

/**
* Constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleInstaller
* Module handler.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(
private readonly ModuleHandlerInterface $moduleInstaller,
private readonly Connection $connection
) {
}

/**
* Nullify webform revision on existing webform submissions.
*/
public function nullifyExistingWebformSubmissionRevisions() {
if (!$this->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);
}
}

}
Loading