|
| 1 | +## Long term storage for Webform submissions |
| 2 | +This module copies Webform submissions to a separate database for Long Term Storage (LTS). The LTS database can then be used for data warehousing needs such as reporting and analysis. Optionally, Personally Identifiable Information (PII) can be redacted from Webform submissions while they are copied to the LTS database. |
| 3 | + |
| 4 | +### Setup process |
| 5 | +- Create a database which will serve as the LTS database. |
| 6 | +- Declare it in Drupal's settings.php using the **localgov_forms_lts** key. Example: |
| 7 | + ``` |
| 8 | + $databases['localgov_forms_lts']['default'] = [ |
| 9 | + 'database' => 'our-long-term-storage-database', |
| 10 | + 'username' => 'database-username-goes-here', |
| 11 | + 'password' => 'database-password-goes-here', |
| 12 | + 'host' => 'database-hostname-goes-here', |
| 13 | + 'port' => '3306', |
| 14 | + 'driver' => 'mysql', |
| 15 | + 'prefix' => '', |
| 16 | + ]; |
| 17 | + ``` |
| 18 | +- Install the localgov_forms_lts submodule. |
| 19 | +- Check the module requirement report from Drupal's status page at `admin/reports/status`. This should be under the **LocalGov Forms LTS** key. |
| 20 | +- [Optional] If all looks good in the previous step, run `drush localgov-forms-lts:copy --force` which will copy existing Webform submissions into the LTS database. |
| 21 | +- By default, periodic Webform submissions copying to the LTS database is disabled. Activate it from `/admin/structure/webform/config/submissions-lts`. |
| 22 | +- Ensure cron is running periodically. This will copy any new Webform submissions or changes to existing Webform submissions since the last cron run or the last `drush localgov-forms-lts:copy` run. |
| 23 | +- [Optional] Tell individual Webforms to purge submissions older than a chosen period. This is configured for each Webform from its `Settings > Submissions > Submission purge settings` configuration section. |
| 24 | + |
| 25 | +### Inspection |
| 26 | +To inspect Webform submissions kept in Long term storage, look for the **LTS** tab in the Webform submissions listing page. This is usually at `/admin/structure/webform/submissions/manage`. |
| 27 | + |
| 28 | +### Good to know |
| 29 | +- Each cron run copies 50 Webform submissions. If your site is getting more than that many Webform submissions between subsequent cron runs, not all Webform submissions will get copied to LTS during a certain period. If that happens, adjust cron run frequency. |
| 30 | +- Files attached to Webform submissions are *not* moved to LTS. |
| 31 | +- You can choose to redact elements with Personally Identifiable Information (PII) while they are copied to the LTS database. For that, select *Best effort PII redactor* (or another redactor) from the `PII redactor plugin` dropdown in the LTS config page at `/admin/structure/webform/config/submissions-lts`. At the moment, this plugin redacts all name, email, telephone, number, and various address type elements. Additionally, any text or radio or checkbox element whose machine name (AKA Key) contains the following also gets redacted: name, mail, phone, contact_number, date_of_birth, dob_, personal_, title, nino, passport, postcode, address, serial_number, reg_number, pcn_, and driver_. |
| 32 | +- If you are using this module in multiple instances of the same site (e.g. dev/stage/live), ensure that the database settings array points to *different* databases. Alternatively, disable copying for the non-live environments from `/admin/structure/webform/config/submissions-lts`. The relevant settings `localgov_forms_lts.settings:is_copying_enabled` can be [overridden](https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-override-system#s-global-overrides) from settings.php. The [config_split](https://www.drupal.org/project/config_split) module can be handy as well. |
| 33 | +- This module is currently in experimental stage. |
| 34 | + |
| 35 | +### Todo |
| 36 | +- Removal of Webform submissions from LTS after a predefined period e.g. 5 years. |
| 37 | + |
| 38 | +### Testing in DDEV |
| 39 | + |
| 40 | +To set up testing in ddev, we'll need to set up a second database. |
| 41 | + |
| 42 | +There are a few ways to do this, but the following seems to work. |
| 43 | + |
| 44 | +#### 1. Add a post-start hook to your .ddev/config.yml |
| 45 | + |
| 46 | +Edit `.ddev/config.yml` and add the following to create a new database on start. |
| 47 | + |
| 48 | +``` |
| 49 | +hooks: |
| 50 | + post-start: |
| 51 | + - exec: mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS localgov_forms_lts; GRANT ALL ON localgov_forms_lts.* to 'db'@'%';" |
| 52 | + service: db |
| 53 | +``` |
| 54 | + |
| 55 | +#### 2. Add the database connection string to settings.php: |
| 56 | + |
| 57 | +Edit sites/default/settings.php and add a new database connection string at the |
| 58 | +end of the file. |
| 59 | + |
| 60 | +``` |
| 61 | +// Database connection for localgov_forms_lts. |
| 62 | +$databases['localgov_forms_lts']['default'] = [ |
| 63 | + 'database' => 'localgov_forms_lts', |
| 64 | + 'username' => 'db', |
| 65 | + 'password' => 'db', |
| 66 | + 'host' => 'db', |
| 67 | + 'port' => '3306', |
| 68 | + 'driver' => 'mysql', |
| 69 | + 'prefix' => '', |
| 70 | +]; |
| 71 | +``` |
| 72 | + |
| 73 | +#### 3. Install Adminer |
| 74 | + |
| 75 | +Adminer is useful if you want to inspect databases and tables. |
| 76 | + |
| 77 | +``` |
| 78 | +ddev get ddev/ddev-adminer |
| 79 | +``` |
| 80 | + |
| 81 | +#### 4. Restart ddev |
| 82 | + |
| 83 | +``` |
| 84 | +ddev restart |
| 85 | +``` |
| 86 | + |
| 87 | +#### 5. Require and install the module. |
| 88 | + |
| 89 | +``` |
| 90 | +ddev composer require localgovdrupal/localgov_forms |
| 91 | +ddev drush si localgov_forms_lts -y |
| 92 | +``` |
| 93 | + |
| 94 | +#### 5. Make some submissions. |
| 95 | + |
| 96 | +For example, in LocalGov Drupal we tend to have a contact form at /form/contact. |
| 97 | + |
| 98 | +Make a couple of submissions there. |
| 99 | + |
| 100 | +#### 6. Run cron. |
| 101 | + |
| 102 | +ddev drush cron |
| 103 | + |
| 104 | +#### 7. Inspect the LTS tab |
| 105 | + |
| 106 | +Go to /admin/structure/webform/submissions/lts |
| 107 | + |
| 108 | +Here you should see your submissions with redacted name and email address. |
0 commit comments