From 418c6bdd2b16dafbabd10af28d4b8c73f78af043 Mon Sep 17 00:00:00 2001 From: Mike van den Hoek Date: Thu, 5 Nov 2026 12:28:39 +0100 Subject: [PATCH 1/5] feat: migrate forms and personal data blocks from V1 to V2 supplier --- CHANGELOG.md | 226 +++++++------ README.md | 16 + .../personal-data-row/index.asset.php | 2 +- .../personal-data-row/index.js | 2 +- build/supplier-migration.asset.php | 1 + build/supplier-migration.js | 1 + config/supplier-migrations/block_options.php | 19 ++ .../supplier-migrations/sources/enable-u.php | 16 + .../sources/pink-roccade.php | 17 + .../supplier-migrations/sources/vrij-brp.php | 46 +++ config/supplier-migrations/targets.php | 16 + resources/js/admin/supplier-migration.js | 34 ++ .../config/personalDataOptions.js | 24 +- .../config/supplierOptions.js | 10 + .../personal-data-row/edit.js | 27 +- .../Console/MigrateSupplierCommand.php | 153 +++++++++ .../GravityForms/GravityFormsAddon.php | 78 +++++ .../SupplierMigrationSettings.php | 215 ++++++++++++ .../Providers/GravityFormsServiceProvider.php | 15 + .../Services/SupplierMigrationService.php | 313 ++++++++++++++++++ .../SupplierMigration/V1ToV2FieldMapping.php | 103 ++++++ webpack.config.js | 1 + 22 files changed, 1218 insertions(+), 117 deletions(-) create mode 100644 build/supplier-migration.asset.php create mode 100644 build/supplier-migration.js create mode 100644 config/supplier-migrations/block_options.php create mode 100644 config/supplier-migrations/sources/enable-u.php create mode 100644 config/supplier-migrations/sources/pink-roccade.php create mode 100644 config/supplier-migrations/sources/vrij-brp.php create mode 100644 config/supplier-migrations/targets.php create mode 100644 resources/js/admin/supplier-migration.js create mode 100644 src/PrefillGravityForms/Console/MigrateSupplierCommand.php create mode 100644 src/PrefillGravityForms/GravityForms/SupplierMigrationSettings.php create mode 100644 src/PrefillGravityForms/Services/SupplierMigrationService.php create mode 100644 src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd7479..7ed0022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,288 +1,294 @@ # Changelog +## [Unreleased] + +- Added: migrate forms and personal data blocks from a V1 supplier (EnableU, PinkRoccade, VrijBRP) to a V2 supplier (EnableU V2, PinkRoccade V2) when changing the supplier in the add-on settings, after confirmation +- Changed: personal data block only shows the options of the API version of the selected supplier +- Added: WP-CLI command `wp prefill migrate-supplier` to migrate forms and personal data blocks to a V2 supplier + ## [v2.1.3] - 2026-11-23 -- Fix: disabled form fields +- Fix: disabled form fields ## [v2.1.2] - 2026-11-17 -- Fix: use general goal binding when a form has no goal binding (V2 suppliers) +- Fix: use general goal binding when a form has no goal binding (V2 suppliers) ## [v2.1.1] - 2026-10-27 -- Added: make log directory configurable to keep log files outside the webroot +- Added: make log directory configurable to keep log files outside the webroot ## [v2.1.0] - 2026-09-16 -- Added: setting to disable outgoing requests as maintenance mode +- Added: setting to disable outgoing requests as maintenance mode ## [v2.0.1] - 2026-07-24 -- Chore: clarify HTTP headers x-doelbinding and x-verwerking +- Chore: clarify HTTP headers x-doelbinding and x-verwerking ## [v2.0.0] - 2026-06-03 -- Added: upgrade to PHP 8 -- Added: user object model class with fullName support -- Added: mTLS certificate configuration with passphrase support and improved tooltips -- Added: conditional usage of SSL certificates -- Added: Pink and EnableU v2 implementation -- Fix: prevent octal conversion from stripping leading zeros in BSN -- Fix: path traversal bypass -- Fix: validate SSL certificates and their paths -- Fix: set supplier certificate as CA to support self-signed certificates -- Fix: use general goal binding when none is used in the request -- Fix: mapping options VrijBRP -- Fix: broken cURL error handling -- Fix: separate cache for personal data service and form requests -- Fix: personal data service class, also improves V2 usage -- Fix: BSN location in response -- Fix: escape output and strip version suffix in personal data row block -- Fix: personal data row inner block -- Fix: remove some default values in GF Addon settings -- Change: VrijBRP controller uses specific cURL headers -- Change: rename doelBinding to goalBinding -- Change: update block registration and prefix to make blocks visible in editor -- Change: verify SSL peer and host when using client certificates -- Chore: update mapping options BRP V2 -- Chore: remove EnableU as supplier -- Chore: add missing information to personal data block for mijngegevens page -- Chore: improve README.md +- Added: upgrade to PHP 8 +- Added: user object model class with fullName support +- Added: mTLS certificate configuration with passphrase support and improved tooltips +- Added: conditional usage of SSL certificates +- Added: Pink and EnableU v2 implementation +- Fix: prevent octal conversion from stripping leading zeros in BSN +- Fix: path traversal bypass +- Fix: validate SSL certificates and their paths +- Fix: set supplier certificate as CA to support self-signed certificates +- Fix: use general goal binding when none is used in the request +- Fix: mapping options VrijBRP +- Fix: broken cURL error handling +- Fix: separate cache for personal data service and form requests +- Fix: personal data service class, also improves V2 usage +- Fix: BSN location in response +- Fix: escape output and strip version suffix in personal data row block +- Fix: personal data row inner block +- Fix: remove some default values in GF Addon settings +- Change: VrijBRP controller uses specific cURL headers +- Change: rename doelBinding to goalBinding +- Change: update block registration and prefix to make blocks visible in editor +- Change: verify SSL peer and host when using client certificates +- Chore: update mapping options BRP V2 +- Chore: remove EnableU as supplier +- Chore: add missing information to personal data block for mijngegevens page +- Chore: improve README.md ## v1.9.1 -- Fix: normalize malformed HaalCentraal endpoint from supplier -- Chore: add huisletter to 'Mijn gegevens' block +- Fix: normalize malformed HaalCentraal endpoint from supplier +- Chore: add huisletter to 'Mijn gegevens' block ## v1.9.0 -- Add: supplement embedded data via form setting +- Add: supplement embedded data via form setting ## v1.8.2 -- Add: housenumberaddition option to openzaak prefill +- Add: housenumberaddition option to openzaak prefill ## v1.8.1 -- Add: housenumberaddition option to pink prefill +- Add: housenumberaddition option to pink prefill ## v1.8.0 -- Add: implement transient caching for cURL responses -- Add: encrypt cached data +- Add: implement transient caching for cURL responses +- Add: encrypt cached data ## v1.7.10 -- Add: data option to personal data block +- Add: data option to personal data block ## v1.7.9 -- Change: skip prefilling when identification session is active in editor +- Change: skip prefilling when identification session is active in editor ## v1.7.8 -- Change: remove ucfirst when setting defaultValue of field when prefilled +- Change: remove ucfirst when setting defaultValue of field when prefilled ## v1.7.7 -- Fix: text domain was loaded too early +- Fix: text domain was loaded too early ## v1.7.6 -- Fix: prevent error log spam regarding null being passed to dirname because of a missing variable -- Change: add editorconfig line that reflects the currently in use code style to prevent whitespace issues +- Fix: prevent error log spam regarding null being passed to dirname because of a missing variable +- Change: add editorconfig line that reflects the currently in use code style to prevent whitespace issues ## v1.7.5 -- Change: clear values of custom fields when validations fail for conditional logic to work +- Change: clear values of custom fields when validations fail for conditional logic to work ## v1.7.4 -- Change: hide custom GF fields success views when no success message has been configured +- Change: hide custom GF fields success views when no success message has been configured ## v1.7.3 -- Fix: set field properties age check validation messages +- Fix: set field properties age check validation messages ## v1.7.2 -- Fix: prefill children information +- Fix: prefill children information ## v1.7.1 -- Add: max age check +- Add: max age check ## v1.7.0 -- Add: children to the mapping options -- Add: 'huisletter' as prefill option to supplier options WeAreFrank +- Add: children to the mapping options +- Add: 'huisletter' as prefill option to supplier options WeAreFrank ## v1.6.11 -- Change: hide empty values personal-data-row Gutenberg block +- Change: hide empty values personal-data-row Gutenberg block ## v1.6.10 -- Fix: remove typehinting on status param in logError() +- Fix: remove typehinting on status param in logError() ## v1.6.9 -- Add: configurable api-key header in GF addon settings +- Add: configurable api-key header in GF addon settings ## v1.6.8 -- Add: timeout option to CURL args +- Add: timeout option to CURL args ## v1.6.7 -- Fix: check if DigiD userdata is not null before retrieving BSN +- Fix: check if DigiD userdata is not null before retrieving BSN ## v1.6.6 -- Add: add help property to supplier select control in personal-data-row block -- Change: remove static response from controller classes +- Add: add help property to supplier select control in personal-data-row block +- Change: remove static response from controller classes ## v1.6.5 -- Fix: return null when controller class, based on selected supplier, is not found +- Fix: return null when controller class, based on selected supplier, is not found ## v1.6.4 -- Fix: personal data row block so it supports multiple suppliers -- Fix: check if multi-dimensional array contains only one array +- Fix: personal data row block so it supports multiple suppliers +- Fix: check if multi-dimensional array contains only one array ## v1.6.3 -- Add: check response of curl request and return exception when request failed +- Add: check response of curl request and return exception when request failed ## v1.6.2 -- Change: logging uses message and status code inside controllers +- Change: logging uses message and status code inside controllers ## v1.6.1 -- Change: WeAreFrank! GF fields mapping options +- Change: WeAreFrank! GF fields mapping options ## v1.6.0 -- Add: WeAreFrank! as supplier -- Change: refactor controller classes -- Change: English translatable strings to Dutch +- Add: WeAreFrank! as supplier +- Change: refactor controller classes +- Change: English translatable strings to Dutch ## v1.5.0 -- Add: implement IdpUserData for retrieving BSN +- Add: implement IdpUserData for retrieving BSN ## v1.4.1 -- Fix: check if $holder is array before using 'isSingleMultidimensionalArray' method when prefilling +- Fix: check if $holder is array before using 'isSingleMultidimensionalArray' method when prefilling ## v1.4.0 -- Add: VrijBRP as supplier -- Add: custom age check and municipality check GF fields -- Change: GF Addon fields + implement basic token usage -- Change: explode dot notated values when prefilling +- Add: VrijBRP as supplier +- Add: custom age check and municipality check GF fields +- Change: GF Addon fields + implement basic token usage +- Change: explode dot notated values when prefilling ## v1.3.0 -- Add: check for eIDAS BSN -- Change: changelog formatting +- Add: check for eIDAS BSN +- Change: changelog formatting ## v1.2.1 -- Add: README.md -- Change: update license to EUPL 1.2 +- Add: README.md +- Change: update license to EUPL 1.2 ## v1.2.0 -- Add: personal data blocks +- Add: personal data blocks ## v1.1 -- Add: prefill all advanced date fields -- Change: clean-up/refactoring & run composer format script +- Add: prefill all advanced date fields +- Change: clean-up/refactoring & run composer format script ## v1.0.17 -- Add: disable prefilled form fields when using 'Openzaak' or 'PinkRoccade' as configured supplier +- Add: disable prefilled form fields when using 'Openzaak' or 'PinkRoccade' as configured supplier ## v1.0.16 -- Add: when a field is mapped but there is no value found, set field to read-only +- Add: when a field is mapped but there is no value found, set field to read-only ## v1.0.15 -- Change: mapping field 'woonplaats' to 'woonplaatsnaam' +- Change: mapping field 'woonplaats' to 'woonplaatsnaam' ## v1.0.14 -- Add: implement API key general setting -- Change: gf-addon title and icon +- Add: implement API key general setting +- Change: gf-addon title and icon ## v1.0.13 -- Change: retrieve bsn by DigiD session instead of value of form field +- Change: retrieve bsn by DigiD session instead of value of form field ## v1.0.12 -- Add: tooltip for the 'Passphrase' form setting -- Change: clean-up code +- Add: tooltip for the 'Passphrase' form setting +- Change: clean-up code ## v1.0.11 -- Change: restore 'Passphrase' form setting, is only used when this setting has a value +- Change: restore 'Passphrase' form setting, is only used when this setting has a value ## v1.0.10 -- Fix: root path to certificates +- Fix: root path to certificates ## v1.0.9 -- Add: logging to Microsoft Teams +- Add: logging to Microsoft Teams ## v1.0.8 -- Change: supplement BSN when length is lower than required 9 +- Change: supplement BSN when length is lower than required 9 ## v1.0.7 -- Change: CURL header x-doelbinding is optional -- Change: remove 'Passphrase' form setting +- Change: CURL header x-doelbinding is optional +- Change: remove 'Passphrase' form setting ## v1.0.6 -- Change: iConnect settings, enable selection of .crt and .cer files +- Change: iConnect settings, enable selection of .crt and .cer files ## v1.0.5 -- Change: plugin name +- Change: plugin name ## v1.0.4 -- Change: Apply the right plugin version +- Change: Apply the right plugin version ## v1.0.3 -- Add: handle multidimensional arrays in response when retrieving linked values +- Add: handle multidimensional arrays in response when retrieving linked values ## v1.0.2 -- Add: expand selectable prefill fields in form field settings -- Add: return linked values with ucfirst() when form field type is 'text' -- Add: return linked values in dd-mm-yyyy notation when form field type is 'date' -- Add: expand parameters to request url -- Add: form field setting for expanding the result set +- Add: expand selectable prefill fields in form field settings +- Add: return linked values with ucfirst() when form field type is 'text' +- Add: return linked values in dd-mm-yyyy notation when form field type is 'date' +- Add: expand parameters to request url +- Add: form field setting for expanding the result set ## v1.0.1 -- Add: plugin description -- Add: retrieve BSN from DigiD session. -- Add: dependency Yard | GravityForms DigiD plugin +- Add: plugin description +- Add: retrieve BSN from DigiD session. +- Add: dependency Yard | GravityForms DigiD plugin ## v1.0.0 -- Add: prefill general settings -- Add: prefill form settings -- Add: prefill form field settings -- Add: Prefill selected form fields on pre-render of form +- Add: prefill general settings +- Add: prefill form settings +- Add: prefill form field settings +- Add: Prefill selected form fields on pre-render of form diff --git a/README.md b/README.md index c414c9f..1472217 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,22 @@ In addition, at least one of the following plug-ins must be installed to enable 2. Go to the form settings of the form you want to configure. 3. Scroll down and look for the 'OWC Prefill' panel and configure the settings. +### Migrating from a V1 to a V2 supplier + +When the supplier in the add-on settings is changed from a V1 supplier (EnableU, PinkRoccade or VrijBRP) to a V2 supplier (EnableU V2 or PinkRoccade V2), you will be asked to migrate the linked forms and personal data blocks. Every V1 supplier can be migrated to every V2 supplier, e.g. VrijBRP to EnableU V2. +After confirming, the supplier in the form settings is switched and the linked fields are mapped to their V2 counterparts, see `config/supplier-migrations/`. +Fields without a V2 counterpart and forms using a mapping file from the theme are reported after saving and need to be updated manually. +The original values are kept in the form setting `owc-form-setting-supplier-legacy` and the field property `linkedFieldValueLegacy`. + +The migration can also be run with WP-CLI, use `--dry-run` to see what will be migrated first: + +```sh +wp prefill migrate-supplier enable-u enable-u-v2 --dry-run +wp prefill migrate-supplier vrij-brp enable-u-v2 +``` + +On a multisite, add `--url=` to migrate a specific site. + ### Cache Encryption To enable secure caching of sensitive data, you **must define an encryption key** in your `wp-config.php` file. This key is used to encrypt and decrypt the cached data and should be kept secret at all times. diff --git a/build/personal-data-table/personal-data-row/index.asset.php b/build/personal-data-table/personal-data-row/index.asset.php index b231319..293d873 100644 --- a/build/personal-data-table/personal-data-row/index.asset.php +++ b/build/personal-data-table/personal-data-row/index.asset.php @@ -1 +1 @@ - ['react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'], 'version' => 'df0a722bfd18e3eb3f64']; + ['react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'], 'version' => '634ba1e632324dd12941']; diff --git a/build/personal-data-table/personal-data-row/index.js b/build/personal-data-table/personal-data-row/index.js index 78a1ced..7f915c3 100644 --- a/build/personal-data-table/personal-data-row/index.js +++ b/build/personal-data-table/personal-data-row/index.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.wp.blocks,a=(window.wp.i18n,window.wp.blockEditor),l=window.wp.components,n=window.wp.data,t=window.wp.element,i=[{value:"",label:"Selecteer persoonsgegevens",disabled:!0},{label:"Burgerservicenummer (BSN)",value:"burgerservicenummer"},{label:"Geslacht",value:"geslachtsaanduiding"},{label:"Leeftijd",value:"leeftijd"},{label:"Achternaam",value:"naam.geslachtsnaam"},{label:"Voorvoegsel (tussenvoegsel)",value:"naam.voorvoegsel"},{label:"Voorletters",value:"naam.voorletters"},{label:"Voornaam",value:"naam.voornaam"},{label:"Voornamen",value:"naam.voornamen"},{label:"Aanduiding Naamgebruik (V1)",value:"naam.aanduidingNaamgebruik"},{label:"Aanduiding Naamgebruik (V2)",value:"naam.aanduidingNaamgebruik.omschrijving"},{label:"Aanschrijfwijze",value:"naam.aanschrijfwijze"},{label:"Gebruik in lopende tekst",value:"naam.gebruikInLopendeTekst"},{label:"Geboortedatum",value:"geboorte.datum.datum"},{label:"Straat",value:"verblijfplaats.straat"},{label:"Straatnaam",value:"verblijfplaats.straatnaam"},{label:"Huisnummer",value:"verblijfplaats.huisnummer"},{label:"Huisnummertoevoeging",value:"verblijfplaats.huisletter"},{label:"Postcode",value:"verblijfplaats.postcode"},{label:"Woonplaats",value:"verblijfplaats.woonplaats"},{label:"Woonplaats naam",value:"verblijfplaats.woonplaatsnaam"}],o=[{value:"",label:"Selecteer een leverancier",disabled:!0},{label:"EnableU",value:"EnableU"},{label:"EnableU V2",value:"EnableUV2"},{label:"OpenZaak",value:"OpenZaak"},{label:"PinkRoccade",value:"PinkRoccade"},{label:"PinkRoccadeV2",value:"PinkRoccadeV2"},{label:"VrijBRP",value:"VrijBRP"},{label:"WeAreFrank",value:"WeAreFrank"}],s=window.ReactJSXRuntime,r=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"owc-prefill-gravity-forms/personal-data-row","version":"0.1.0","title":"Persoonsgegevens","icon":"id","description":"Toon persoonsgegevens van de ingelogde gebruiker.","example":{},"supports":{"html":false},"attributes":{"selectedSupplier":{"type":"object","default":{"value":"","label":""}},"goalBinding":{"type":"string","default":""},"processing":{"type":"string","default":""},"selectedOption":{"type":"object","default":{"value":"","label":""}},"isChildOfTable":{"type":"boolean","default":false},"htmlElement":{"type":"string","default":"p"}},"textdomain":"prefill-gravity-forms","editorScript":"file:./index.js","render":"file:./render.php"}');(0,e.registerBlockType)(r.name,{...r,edit:function({attributes:e,setAttributes:r,clientId:d}){const{selectedSupplier:v,goalBinding:c,processing:u,selectedOption:b,htmlElement:p,isChildOfTable:g}=e,{blockParents:m}=(0,n.useSelect)(e=>({blockParents:e("core/block-editor").getBlockNamesByClientId(e("core/block-editor").getBlockParents(d))}));(0,t.useEffect)(()=>{m.length>0&&"owc-prefill-gravity-forms/personal-data-table"===m[m.length-1]&&r({isChildOfTable:!0})},[m,r]);const h=(0,s.jsx)(l.SelectControl,{help:"Selecteer de juiste leverancier die ingesteld staat in de algemene instellingen.",label:"Leverancier",value:v.value,options:o,onChange:e=>{const a={value:e,label:o.find(a=>a.value===e).label};r({selectedSupplier:a})}}),j=(0,s.jsx)(l.TextControl,{help:"Algemene doelbinding voor verzoeken zonder specifieke doelbinding. Beschrijft waarom de persoonsgegevens worden opgevraagd en op basis van welke wettelijke taak of bevoegdheid de organisatie dit doet. De mogelijke waarden zijn implementatieafhankelijk en worden door de leverancier bepaald.",label:"Doelbinding (v2)",value:c,onChange:e=>{r({goalBinding:e})}}),k=(0,s.jsx)(l.TextControl,{help:"Beschrijft voor welk werkproces of welke processtap de BRP-gegevens worden opgevraagd. De mogelijke waarden zijn implementatieafhankelijk en dienen door de leverancier te worden aangeleverd.",label:"Verwerking (v2)",value:u,onChange:e=>{r({processing:e})}}),w=(0,s.jsx)(l.SelectControl,{label:"Automatisch invullen",value:b.value,options:i,onChange:e=>{const a={value:e,label:i.find(a=>a.value===e).label};r({selectedOption:a})}}),f=(0,s.jsx)(l.SelectControl,{label:"HTML Element",value:p,options:[{label:"
",value:"div"},{label:"

",value:"p"},{label:"",value:"span"}],onChange:e=>{r({htmlElement:e})}});return(0,s.jsxs)("div",{...(0,a.useBlockProps)(),children:[(0,s.jsx)(a.InspectorControls,{children:(0,s.jsx)(l.TabPanel,{activeClass:"active-tab",tabs:[{name:"settings",title:"Settings"}],children:e=>(0,s.jsx)(l.PanelBody,{initialOpen:!0,children:"settings"===e.name&&(0,s.jsxs)(s.Fragment,{children:[h,j,k,w,!g&&f]})})})}),void 0===b.value||""===b.value?(0,s.jsx)("p",{children:w}):(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"row",children:[g&&(0,s.jsx)("div",{className:"col-6 font-weight-bold",children:(0,s.jsx)("p",{children:b.label})}),(0,s.jsxs)("div",{className:"col-6",children:["[",(x=b.label,x?x.charAt(0).toLowerCase()+x.slice(1):x),"]"]})]})})]});var x},save:()=>null})})(); \ No newline at end of file +(()=>{"use strict";const e=window.wp.blocks,a=(window.wp.i18n,window.wp.blockEditor),l=window.wp.components,n=window.wp.data,i=window.wp.element,o=[{value:"",label:"Selecteer persoonsgegevens",disabled:!0},{label:"Burgerservicenummer (BSN)",value:"burgerservicenummer"},{label:"Geslacht",value:"geslachtsaanduiding"},{label:"Leeftijd",value:"leeftijd"},{label:"Achternaam",value:"naam.geslachtsnaam"},{label:"Voorvoegsel (tussenvoegsel)",value:"naam.voorvoegsel"},{label:"Voorletters",value:"naam.voorletters"},{label:"Voornaam",value:"naam.voornaam"},{label:"Voornamen",value:"naam.voornamen"},{label:"Aanduiding Naamgebruik",value:"naam.aanduidingNaamgebruik",version:"1"},{label:"Aanduiding Naamgebruik",value:"naam.aanduidingNaamgebruik.omschrijving",version:"2"},{label:"Aanschrijfwijze",value:"naam.aanschrijfwijze"},{label:"Gebruik in lopende tekst",value:"naam.gebruikInLopendeTekst"},{label:"Geboortedatum",value:"geboorte.datum.datum"},{label:"Straat",value:"verblijfplaats.straat",version:"1"},{label:"Straatnaam",value:"verblijfplaats.straatnaam",version:"1"},{label:"Straat",value:"verblijfplaats.verblijfadres.officieleStraatnaam",version:"2"},{label:"Huisnummer",value:"verblijfplaats.huisnummer"},{label:"Huisnummertoevoeging",value:"verblijfplaats.huisletter"},{label:"Postcode",value:"verblijfplaats.postcode"},{label:"Woonplaats",value:"verblijfplaats.woonplaats",version:"1"},{label:"Woonplaats naam",value:"verblijfplaats.woonplaatsnaam",version:"1"},{label:"Woonplaats",value:"verblijfplaats.verblijfadres.woonplaats",version:"2"}],t=[{value:"",label:"Selecteer een leverancier",disabled:!0},{label:"EnableU",value:"EnableU",version:"1"},{label:"EnableU V2",value:"EnableUV2",version:"2"},{label:"OpenZaak",value:"OpenZaak",version:"1"},{label:"PinkRoccade",value:"PinkRoccade",version:"1"},{label:"PinkRoccadeV2",value:"PinkRoccadeV2",version:"2"},{label:"VrijBRP",value:"VrijBRP",version:"1"},{label:"WeAreFrank",value:"WeAreFrank",version:"2"}],r=window.ReactJSXRuntime,s=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"owc-prefill-gravity-forms/personal-data-row","version":"0.1.0","title":"Persoonsgegevens","icon":"id","description":"Toon persoonsgegevens van de ingelogde gebruiker.","example":{},"supports":{"html":false},"attributes":{"selectedSupplier":{"type":"object","default":{"value":"","label":""}},"goalBinding":{"type":"string","default":""},"processing":{"type":"string","default":""},"selectedOption":{"type":"object","default":{"value":"","label":""}},"isChildOfTable":{"type":"boolean","default":false},"htmlElement":{"type":"string","default":"p"}},"textdomain":"prefill-gravity-forms","editorScript":"file:./index.js","render":"file:./render.php"}');(0,e.registerBlockType)(s.name,{...s,edit:function({attributes:e,setAttributes:s,clientId:v}){var d;const{selectedSupplier:u,goalBinding:b,processing:c,selectedOption:p,htmlElement:g,isChildOfTable:m}=e,{blockParents:f}=(0,n.useSelect)(e=>({blockParents:e("core/block-editor").getBlockNamesByClientId(e("core/block-editor").getBlockParents(v))}));(0,i.useEffect)(()=>{f.length>0&&"owc-prefill-gravity-forms/personal-data-table"===f[f.length-1]&&s({isChildOfTable:!0})},[f,s]);const j=t.find(e=>e.value===u.value)?.version,h=o.filter(e=>!e.version||!j||e.version===j||e.value===p.value).map(({label:e,value:a,disabled:l})=>({label:e,value:a,disabled:l})),w=(null!==(d=p.label)&&void 0!==d?d:"").replace(/\s*\(V\d+\)$/,""),k=(0,r.jsx)(l.SelectControl,{help:"Selecteer de juiste leverancier die ingesteld staat in de algemene instellingen.",label:"Leverancier",value:u.value,options:t,onChange:e=>{const a={value:e,label:t.find(a=>a.value===e).label};s({selectedSupplier:a})}}),x=(0,r.jsx)(l.TextControl,{help:"Algemene doelbinding voor verzoeken zonder specifieke doelbinding. Beschrijft waarom de persoonsgegevens worden opgevraagd en op basis van welke wettelijke taak of bevoegdheid de organisatie dit doet. De mogelijke waarden zijn implementatieafhankelijk en worden door de leverancier bepaald.",label:"Doelbinding (v2)",value:b,onChange:e=>{s({goalBinding:e})}}),S=(0,r.jsx)(l.TextControl,{help:"Beschrijft voor welk werkproces of welke processtap de BRP-gegevens worden opgevraagd. De mogelijke waarden zijn implementatieafhankelijk en dienen door de leverancier te worden aangeleverd.",label:"Verwerking (v2)",value:c,onChange:e=>{s({processing:e})}}),C=(0,r.jsx)(l.SelectControl,{label:"Automatisch invullen",value:p.value,options:h,onChange:e=>{const a={value:e,label:o.find(a=>a.value===e).label};s({selectedOption:a})}}),B=(0,r.jsx)(l.SelectControl,{label:"HTML Element",value:g,options:[{label:"

",value:"div"},{label:"

",value:"p"},{label:"",value:"span"}],onChange:e=>{s({htmlElement:e})}});return(0,r.jsxs)("div",{...(0,a.useBlockProps)(),children:[(0,r.jsx)(a.InspectorControls,{children:(0,r.jsx)(l.TabPanel,{activeClass:"active-tab",tabs:[{name:"settings",title:"Settings"}],children:e=>(0,r.jsx)(l.PanelBody,{initialOpen:!0,children:"settings"===e.name&&(0,r.jsxs)(r.Fragment,{children:[k,x,S,C,!m&&B]})})})}),void 0===p.value||""===p.value?(0,r.jsx)("p",{children:C}):(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"row",children:[m&&(0,r.jsx)("div",{className:"col-6 font-weight-bold",children:(0,r.jsx)("p",{children:w})}),(0,r.jsxs)("div",{className:"col-6",children:["[",(P=w,P?P.charAt(0).toLowerCase()+P.slice(1):P),"]"]})]})})]});var P},save:()=>null})})(); \ No newline at end of file diff --git a/build/supplier-migration.asset.php b/build/supplier-migration.asset.php new file mode 100644 index 0000000..4e2a1fc --- /dev/null +++ b/build/supplier-migration.asset.php @@ -0,0 +1 @@ + [], 'version' => '7f54652d5ce551171503']; diff --git a/build/supplier-migration.js b/build/supplier-migration.js new file mode 100644 index 0000000..8883a54 --- /dev/null +++ b/build/supplier-migration.js @@ -0,0 +1 @@ +!function(e){if(!e)return;const n=document.getElementById("gform-settings");if(!n)return;const t=n.querySelector(`[name="${e.supplierInput}"]`),r=n.querySelector(`[name="${e.confirmedInput}"]`);t&&r&&n.addEventListener("submit",()=>{const n=e.targets.includes(t.value);r.value=n&&window.confirm(e.message.replace("%s",t.value))?"1":""})}(window.owcPrefillSupplierMigration); \ No newline at end of file diff --git a/config/supplier-migrations/block_options.php b/config/supplier-migrations/block_options.php new file mode 100644 index 0000000..2970cf5 --- /dev/null +++ b/config/supplier-migrations/block_options.php @@ -0,0 +1,19 @@ + ['value' => 'verblijfplaats.verblijfadres.officieleStraatnaam', 'label' => 'Straat'], + 'verblijfplaats.straatnaam' => ['value' => 'verblijfplaats.verblijfadres.officieleStraatnaam', 'label' => 'Straat'], + 'verblijfplaats.woonplaats' => ['value' => 'verblijfplaats.verblijfadres.woonplaats', 'label' => 'Woonplaats'], + 'verblijfplaats.woonplaatsnaam' => ['value' => 'verblijfplaats.verblijfadres.woonplaats', 'label' => 'Woonplaats'], + 'naam.aanduidingNaamgebruik' => ['value' => 'naam.aanduidingNaamgebruik.omschrijving', 'label' => 'Aanduiding Naamgebruik'], +]; diff --git a/config/supplier-migrations/sources/enable-u.php b/config/supplier-migrations/sources/enable-u.php new file mode 100644 index 0000000..101e632 --- /dev/null +++ b/config/supplier-migrations/sources/enable-u.php @@ -0,0 +1,16 @@ + 'verblijfplaats.verblijfadres.officieleStraatnaam', + 'verblijfplaats.woonplaatsnaam' => 'verblijfplaats.verblijfadres.woonplaats', +]); diff --git a/config/supplier-migrations/sources/pink-roccade.php b/config/supplier-migrations/sources/pink-roccade.php new file mode 100644 index 0000000..10712f4 --- /dev/null +++ b/config/supplier-migrations/sources/pink-roccade.php @@ -0,0 +1,17 @@ + 'verblijfplaats.verblijfadres.officieleStraatnaam', + 'verblijfplaats.woonplaats' => 'verblijfplaats.verblijfadres.woonplaats', + 'verblijfplaats.huisnummertoevoeging' => null, +]); diff --git a/config/supplier-migrations/sources/vrij-brp.php b/config/supplier-migrations/sources/vrij-brp.php new file mode 100644 index 0000000..ef60b97 --- /dev/null +++ b/config/supplier-migrations/sources/vrij-brp.php @@ -0,0 +1,46 @@ + null, + 'soortVerbintenis' => 'soortVerbintenis.omschrijving', + 'aangaanHuwelijkPartnerschap.datum.datum' => 'aangaanHuwelijkPartnerschap.datum.datum', + 'aangaanHuwelijkPartnerschap.datum.dag' => null, + 'aangaanHuwelijkPartnerschap.datum.maand' => null, + 'aangaanHuwelijkPartnerschap.datum.jaar' => null, + 'aangaanHuwelijkPartnerschap.land.code' => null, + 'aangaanHuwelijkPartnerschap.land.omschrijving' => 'aangaanHuwelijkPartnerschap.land.omschrijving', + 'aangaanHuwelijkPartnerschap.plaats.code' => null, + 'aangaanHuwelijkPartnerschap.plaats.omschrijving' => 'aangaanHuwelijkPartnerschap.plaats.omschrijving', +] + V1ToV2FieldMapping::relative(); + +return array_merge( + V1ToV2FieldMapping::base(), + [ + 'naam.gebruikInLopendeTekst' => null, + 'naam.aanduidingNaamgebruik.code' => 'naam.aanduidingNaamgebruik.code', + 'naam.aanduidingNaamgebruik.omschrijving' => 'naam.aanduidingNaamgebruik.omschrijving', + 'nationaliteiten.0.nationaliteit.omschrijving' => 'nationaliteiten.0.nationaliteit.omschrijving', + 'nationaliteiten.0.nationaliteit.code' => 'nationaliteiten.0.nationaliteit.code', + 'geboorte.datum.dag' => null, + 'geboorte.datum.maand' => null, + 'geboorte.plaats.code' => null, + 'geboorte.land.code' => null, + 'verblijfplaats.straat' => 'verblijfplaats.verblijfadres.officieleStraatnaam', + 'verblijfplaats.straatnaam' => 'verblijfplaats.verblijfadres.officieleStraatnaam', + 'verblijfplaats.woonplaats' => 'verblijfplaats.verblijfadres.woonplaats', + 'verblijfplaats.woonplaatsnaam' => 'verblijfplaats.verblijfadres.woonplaats', + ], + V1ToV2FieldMapping::prefix($partner, '_embedded.partners.0', 'partners.0') +); diff --git a/config/supplier-migrations/targets.php b/config/supplier-migrations/targets.php new file mode 100644 index 0000000..c0fdac4 --- /dev/null +++ b/config/supplier-migrations/targets.php @@ -0,0 +1,16 @@ + ['block_supplier_label' => 'EnableU V2'], + 'pink-roccade-v2' => ['block_supplier_label' => 'PinkRoccadeV2'], +]; diff --git a/resources/js/admin/supplier-migration.js b/resources/js/admin/supplier-migration.js new file mode 100644 index 0000000..5cd750b --- /dev/null +++ b/resources/js/admin/supplier-migration.js @@ -0,0 +1,34 @@ +/** + * Asks for confirmation on the add-on settings page when the supplier is changed from a V1 supplier to a V2 + * supplier, e.g. from VrijBRP to EnableU V2. The answer is stored in a hidden input and handled when saving. + * + * The config is provided by SupplierMigrationSettings::enqueueConfirmScript() as window.owcPrefillSupplierMigration. + */ +( function ( config ) { + if ( ! config ) { + return; + } + + const form = document.getElementById( 'gform-settings' ); + + if ( ! form ) { + return; + } + + const supplier = form.querySelector( `[name="${ config.supplierInput }"]` ); + const confirmed = form.querySelector( `[name="${ config.confirmedInput }"]` ); + + if ( ! supplier || ! confirmed ) { + return; + } + + form.addEventListener( 'submit', () => { + const isTarget = config.targets.includes( supplier.value ); + + confirmed.value = + isTarget && + window.confirm( config.message.replace( '%s', supplier.value ) ) + ? '1' + : ''; + } ); +} )( window.owcPrefillSupplierMigration ); diff --git a/resources/js/blocks/personal-data-table/personal-data-row/config/personalDataOptions.js b/resources/js/blocks/personal-data-table/personal-data-row/config/personalDataOptions.js index 0ac5977..fd8ab28 100644 --- a/resources/js/blocks/personal-data-table/personal-data-row/config/personalDataOptions.js +++ b/resources/js/blocks/personal-data-table/personal-data-row/config/personalDataOptions.js @@ -1,3 +1,7 @@ +/** + * Options without a version are available for every supplier, these are translated on runtime for V2 suppliers + * by the PersonalDataService. Options with a version are only available for suppliers of that API version. + */ const personalDataOptions = [ { value: '', @@ -37,12 +41,14 @@ const personalDataOptions = [ value: 'naam.voornamen', }, { - label: 'Aanduiding Naamgebruik (V1)', + label: 'Aanduiding Naamgebruik', value: 'naam.aanduidingNaamgebruik', + version: '1', }, { - label: 'Aanduiding Naamgebruik (V2)', + label: 'Aanduiding Naamgebruik', value: 'naam.aanduidingNaamgebruik.omschrijving', + version: '2', }, { label: 'Aanschrijfwijze', @@ -59,10 +65,17 @@ const personalDataOptions = [ { label: 'Straat', value: 'verblijfplaats.straat', + version: '1', }, { label: 'Straatnaam', value: 'verblijfplaats.straatnaam', + version: '1', + }, + { + label: 'Straat', + value: 'verblijfplaats.verblijfadres.officieleStraatnaam', + version: '2', }, { label: 'Huisnummer', @@ -79,10 +92,17 @@ const personalDataOptions = [ { label: 'Woonplaats', value: 'verblijfplaats.woonplaats', + version: '1', }, { label: 'Woonplaats naam', value: 'verblijfplaats.woonplaatsnaam', + version: '1', + }, + { + label: 'Woonplaats', + value: 'verblijfplaats.verblijfadres.woonplaats', + version: '2', }, ]; diff --git a/resources/js/blocks/personal-data-table/personal-data-row/config/supplierOptions.js b/resources/js/blocks/personal-data-table/personal-data-row/config/supplierOptions.js index 0a78334..560fa2e 100644 --- a/resources/js/blocks/personal-data-table/personal-data-row/config/supplierOptions.js +++ b/resources/js/blocks/personal-data-table/personal-data-row/config/supplierOptions.js @@ -1,3 +1,6 @@ +/** + * The version is the HaalCentraal BRP API version of the supplier, used to filter the personal data options. + */ const supplierOptions = [ { value: '', @@ -7,30 +10,37 @@ const supplierOptions = [ { label: 'EnableU', value: 'EnableU', + version: '1', }, { label: 'EnableU V2', value: 'EnableUV2', + version: '2', }, { label: 'OpenZaak', value: 'OpenZaak', + version: '1', }, { label: 'PinkRoccade', value: 'PinkRoccade', + version: '1', }, { label: 'PinkRoccadeV2', value: 'PinkRoccadeV2', + version: '2', }, { label: 'VrijBRP', value: 'VrijBRP', + version: '1', }, { label: 'WeAreFrank', value: 'WeAreFrank', + version: '2', }, ]; diff --git a/resources/js/blocks/personal-data-table/personal-data-row/edit.js b/resources/js/blocks/personal-data-table/personal-data-row/edit.js index 6edeaf8..68f07c0 100644 --- a/resources/js/blocks/personal-data-table/personal-data-row/edit.js +++ b/resources/js/blocks/personal-data-table/personal-data-row/edit.js @@ -38,6 +38,27 @@ export default function Edit( { attributes, setAttributes, clientId } ) { } }, [ blockParents, setAttributes ] ); + const supplierVersion = supplierOptions.find( + ( option ) => option.value === selectedSupplier.value + )?.version; + + // Only show the options of the API version of the supplier, the selected option is kept to avoid an empty select. + const availablePersonalDataOptions = personalDataOptions + .filter( + ( option ) => + ! option.version || + ! supplierVersion || + option.version === supplierVersion || + option.value === selectedOption.value + ) + .map( ( { label, value, disabled } ) => ( { label, value, disabled } ) ); + + // Labels saved by previous versions could contain a version suffix, e.g. 'Straat (V2)'. + const selectedOptionLabel = ( selectedOption.label ?? '' ).replace( + /\s*\(V\d+\)$/, + '' + ); + const handleSupplierChange = ( value ) => { const selectedSupplierData = { value, @@ -102,7 +123,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) { ); @@ -165,11 +186,11 @@ export default function Edit( { attributes, setAttributes, clientId } ) {

{ isChildOfTable && (
-

{ selectedOption.label }

+

{ selectedOptionLabel }

) }
- [{ uncapitalize( selectedOption.label ) }] + [{ uncapitalize( selectedOptionLabel ) }]
diff --git a/src/PrefillGravityForms/Console/MigrateSupplierCommand.php b/src/PrefillGravityForms/Console/MigrateSupplierCommand.php new file mode 100644 index 0000000..e24e831 --- /dev/null +++ b/src/PrefillGravityForms/Console/MigrateSupplierCommand.php @@ -0,0 +1,153 @@ + + * : The V1 supplier to migrate from. + * --- + * options: + * - enable-u + * - pink-roccade + * - vrij-brp + * --- + * + * + * : The V2 supplier to migrate to. + * --- + * options: + * - enable-u-v2 + * - pink-roccade-v2 + * --- + * + * [--dry-run] + * : Only report what would be migrated. + * + * [--yes] + * : Do not ask for confirmation. + * + * ## EXAMPLES + * + * wp prefill migrate-supplier enable-u enable-u-v2 --dry-run + * wp prefill migrate-supplier vrij-brp enable-u-v2 --yes + */ + public function __invoke(array $args, array $assocArgs): void + { + $from = (string) ($args[0] ?? ''); + $to = (string) ($args[1] ?? ''); + $dryRun = (bool) \WP_CLI\Utils\get_flag_value($assocArgs, 'dry-run', false); + $service = new SupplierMigrationService(); + + if (! $service->canMigrate($from, $to)) { + WP_CLI::error(sprintf('There is no migration available from supplier "%s" to "%s".', $from, $to)); + } + + try { + $report = $service->migrate($from, $to, true); + } catch (Throwable $e) { + WP_CLI::error($e->getMessage()); + + return; // Unreachable: WP_CLI::error() exits; keeps static analysis happy. + } + + $this->printReport($report); + + if (0 === count($report['forms']) + count($report['posts'])) { + $this->warnSkippedForms($report); + WP_CLI::success(sprintf('Nothing to migrate for supplier "%s".', $from)); + + return; + } + + if ($dryRun) { + WP_CLI::success('Dry run, nothing has been changed.'); + + return; + } + + WP_CLI::confirm(sprintf('Migrate the forms and blocks above from "%s" to "%s"?', $report['from'], $report['to']), $assocArgs); + + try { + $report = $service->migrate($from, $to); + } catch (Throwable $e) { + WP_CLI::error($e->getMessage()); + } + + WP_CLI::success(sprintf( + 'Migrated %d form(s) and %d post(s) from "%s" to "%s".', + count($report['forms']), + count($report['posts']), + $report['from'], + $report['to'] + )); + + $this->warnSkippedForms($report); + } + + private function warnSkippedForms(array $report): void + { + if (count($report['skipped_forms'])) { + WP_CLI::warning(sprintf('%d form(s) have been skipped, these need to be migrated manually.', count($report['skipped_forms']))); + } + } + + private function printReport(array $report): void + { + $items = []; + + foreach ($report['forms'] as $id => $form) { + $items[] = [ + 'type' => 'form', + 'id' => $id, + 'title' => $form['title'], + 'migrated' => $form['migrated'], + 'unmapped' => count($form['unmapped']), + 'note' => '', + ]; + } + + foreach ($report['skipped_forms'] as $id => $form) { + $items[] = ['type' => 'form', 'id' => $id, 'title' => $form['title'], 'migrated' => 0, 'unmapped' => 0, 'note' => 'skipped: ' . $form['reason']]; + } + + foreach ($report['posts'] as $id => $post) { + $items[] = ['type' => 'post', 'id' => $id, 'title' => $post['title'], 'migrated' => $post['migrated'], 'unmapped' => 0, 'note' => '']; + } + + if (count($items)) { + \WP_CLI\Utils\format_items('table', $items, ['type', 'id', 'title', 'migrated', 'unmapped', 'note']); + } + + $unmapped = []; + + foreach ($report['forms'] as $id => $form) { + foreach ($form['unmapped'] as $fieldId => $field) { + $unmapped[] = ['form' => $id, 'field' => $fieldId, 'label' => $field['label'], 'value' => $field['value']]; + } + } + + if (count($unmapped)) { + WP_CLI::log(''); + WP_CLI::log('Fields without a V2 counterpart, these need to be linked manually:'); + \WP_CLI\Utils\format_items('table', $unmapped, ['form', 'field', 'label', 'value']); + } + } +} diff --git a/src/PrefillGravityForms/GravityForms/GravityFormsAddon.php b/src/PrefillGravityForms/GravityForms/GravityFormsAddon.php index 5ca2ba9..0826cb1 100644 --- a/src/PrefillGravityForms/GravityForms/GravityFormsAddon.php +++ b/src/PrefillGravityForms/GravityForms/GravityFormsAddon.php @@ -58,6 +58,11 @@ public static function get_instance(): self return self::$_instance; } + /** + * HTML message about the supplier migration, shown with the settings saved message. + */ + private string $supplierMigrationMessage = ''; + /** * Return the plugin's icon for the plugin/form settings menu. * @@ -140,6 +145,12 @@ public function plugin_settings_fields(): array ]; }, array_values(config('suppliers.mapping', [])))), ], + [ + // Set by JavaScript when the user confirms the migration of forms and blocks to the V2 supplier. + 'type' => 'hidden', + 'name' => SupplierMigrationSettings::SETTING_CONFIRMED, + 'default_value' => '', + ], [ 'label' => esc_html__('Gebruik API authenticatie', 'prefill-gravity-forms'), 'description' => esc_html__('Deze authenticatie zal gebruikt worden naast de gebruikelijke authenticatie middels certificaten.', 'prefill-gravity-forms'), @@ -303,6 +314,73 @@ public function plugin_settings_fields(): array ]; } + /** + * @since NEXT + */ + public function init_admin() + { + parent::init_admin(); + + add_action('admin_enqueue_scripts', $this->enqueueSupplierMigrationScript(...)); + } + + /** + * @since NEXT + */ + public function plugin_settings_init() + { + parent::plugin_settings_init(); + + $renderer = $this->get_settings_renderer(); + + if (! is_object($renderer) || ! method_exists($renderer, 'set_postback_message_callback')) { + return; + } + + $renderer->set_postback_message_callback(function ($message) { + return $message . $this->supplierMigrationMessage; + }); + } + + /** + * Migrates the forms and blocks when the supplier is changed from V1 to V2 and the user confirmed this. + * + * @param array $settings + * @since NEXT + */ + public function update_plugin_settings($settings) + { + $confirmed = '1' === (string) ($settings[SupplierMigrationSettings::SETTING_CONFIRMED] ?? ''); + unset($settings[SupplierMigrationSettings::SETTING_CONFIRMED]); + + $previousSettings = $this->get_plugin_settings(); + $previousSupplier = is_array($previousSettings) ? (string) ($previousSettings[SupplierMigrationSettings::SETTING_SUPPLIER] ?? '') : ''; + + parent::update_plugin_settings($settings); + + $this->supplierMigrationMessage = (new SupplierMigrationSettings())->handleSupplierChange( + $previousSupplier, + (string) ($settings[SupplierMigrationSettings::SETTING_SUPPLIER] ?? ''), + $confirmed + ); + } + + /** + * @since NEXT + */ + private function enqueueSupplierMigrationScript(): void + { + if (! $this->is_plugin_settings($this->get_slug())) { + return; + } + + $settings = $this->get_plugin_settings(); + + (new SupplierMigrationSettings())->enqueueConfirmScript( + is_array($settings) ? (string) ($settings[SupplierMigrationSettings::SETTING_SUPPLIER] ?? '') : '' + ); + } + /** * Format the list of certificates for the selectbox. */ diff --git a/src/PrefillGravityForms/GravityForms/SupplierMigrationSettings.php b/src/PrefillGravityForms/GravityForms/SupplierMigrationSettings.php new file mode 100644 index 0000000..bf4633d --- /dev/null +++ b/src/PrefillGravityForms/GravityForms/SupplierMigrationSettings.php @@ -0,0 +1,215 @@ +service = $service ?? new SupplierMigrationService(); + } + + /** + * Migrates the forms and blocks when the supplier changed and the user confirmed the migration. + * Without confirmation the user is informed about the forms and blocks that are still linked to the V1 supplier. + * + * Returns a HTML message which is shown with the settings saved message. + */ + public function handleSupplierChange(string $from, string $to, bool $confirmed): string + { + if ($from === $to) { + return ''; + } + + $migration = $this->service->findMigrationForGlobalSupplierChange($from, $to); + + if (null === $migration) { + return ''; + } + + try { + $report = $this->service->migrate($migration[0], $migration[1], ! $confirmed); + } catch (Throwable $e) { + $this->logException(new \Exception(sprintf('Supplier migration failed: %s', $e->getMessage()), 500, $e)); + + return $this->paragraph(sprintf( + esc_html__('Het omzetten van de formulieren en blokken naar %s is mislukt: %s', 'prefill-gravity-forms'), + esc_html($to), + esc_html($e->getMessage()) + )); + } + + return $confirmed ? $this->formatMigrated($report) : $this->formatNotMigrated($report); + } + + /** + * Enqueues the script which asks for confirmation when the supplier is changed from the current V1 supplier + * to a V2 supplier, see resources/js/admin/supplier-migration.js. + * + * The linked forms and blocks are not counted here, as that requires loading all forms and searching all posts + * on every load of the settings page. When nothing is linked, confirming the migration simply changes nothing. + */ + public function enqueueConfirmScript(string $currentSupplier): void + { + $from = $this->service->supplierByLabel($currentSupplier, $this->service->sourceSuppliers()); + $targets = $this->service->targetSuppliers(); + + if (null === $from || ! count($targets)) { + return; + } + + $assetPath = PG_ROOT_PATH . '/build/supplier-migration.asset.php'; + $asset = file_exists($assetPath) ? require $assetPath : ['dependencies' => [], 'version' => PG_VERSION]; + + wp_enqueue_script( + self::SCRIPT_HANDLE, + plugins_url('build/supplier-migration.js', PG_ROOT_PATH . '/prefill-gravity-forms.php'), + $asset['dependencies'], + $asset['version'], + true + ); + + $message = sprintf( + // The %s placeholder (escaped as %%s) is replaced by the selected V2 supplier in JavaScript. + __("Wil je de formulieren en pagina's met persoonsgegevens die gekoppeld zijn aan %1\$s automatisch omzetten naar %%s? De gekoppelde velden worden dan vervangen door de V2-velden. Velden zonder V2-tegenhanger worden ontkoppeld en na het opslaan getoond.\n\nOK: omzetten en instellingen opslaan.\nAnnuleren: alleen de instellingen opslaan.", 'prefill-gravity-forms'), + $currentSupplier + ); + + wp_add_inline_script( + self::SCRIPT_HANDLE, + sprintf('window.owcPrefillSupplierMigration = %s;', wp_json_encode([ + 'supplierInput' => self::INPUT_PREFIX . self::SETTING_SUPPLIER, + 'confirmedInput' => self::INPUT_PREFIX . self::SETTING_CONFIRMED, + 'targets' => array_map($this->service->supplierLabel(...), $targets), + 'message' => $message, + ])), + 'before' + ); + } + + private function formatMigrated(array $report): string + { + $from = $this->service->supplierLabel($report['from']); + $to = $this->service->supplierLabel($report['to']); + + $parts = array_filter([ + count($report['forms']) ? sprintf( + esc_html__('%1$d formulier(en) met %2$d gekoppelde velden', 'prefill-gravity-forms'), + count($report['forms']), + array_sum(array_column($report['forms'], 'migrated')) + ) : '', + count($report['posts']) ? sprintf( + esc_html__('%1$d pagina(\'s) met %2$d persoonsgegevens-blokken', 'prefill-gravity-forms'), + count($report['posts']), + array_sum(array_column($report['posts'], 'migrated')) + ) : '', + ]); + + $html = count($parts) ? $this->paragraph(sprintf( + esc_html__('%1$s zijn omgezet van %2$s naar %3$s.', 'prefill-gravity-forms'), + implode(esc_html__(' en ', 'prefill-gravity-forms'), $parts), + esc_html($from), + esc_html($to) + )) : ''; + + return $html . $this->formatUnmapped($report) . $this->formatSkipped($report); + } + + private function formatNotMigrated(array $report): string + { + $forms = count($report['forms']) + count($report['skipped_forms']); + $posts = count($report['posts']); + + if (0 === $forms + $posts) { + return ''; + } + + return $this->paragraph(sprintf( + esc_html__('Let op: %1$d formulier(en) en %2$d pagina(\'s) met persoonsgegevens zijn nog gekoppeld aan %3$s en zijn niet omgezet. Pas deze handmatig aan of gebruik het WP-CLI commando %4$s.', 'prefill-gravity-forms'), + $forms, + $posts, + esc_html($this->service->supplierLabel($report['from'])), + sprintf('wp prefill migrate-supplier %s %s', esc_html($report['from']), esc_html($report['to'])) + )); + } + + private function formatUnmapped(array $report): string + { + $items = []; + + foreach ($report['forms'] as $formId => $form) { + foreach ($form['unmapped'] as $fieldId => $field) { + $items[] = sprintf( + '%s – %s %s', + $this->formLink((int) $formId, $form['title']), + esc_html('' !== $field['label'] ? $field['label'] : sprintf(__('Veld %d', 'prefill-gravity-forms'), $fieldId)), + esc_html($field['value']) + ); + } + } + + if (! count($items)) { + return ''; + } + + return $this->paragraph(esc_html__('De volgende velden hebben geen tegenhanger in V2 en moeten handmatig opnieuw gekoppeld worden:', 'prefill-gravity-forms')) + . $this->list($items); + } + + private function formatSkipped(array $report): string + { + $items = []; + + foreach ($report['skipped_forms'] as $formId => $form) { + $items[] = sprintf('%s – %s', $this->formLink((int) $formId, $form['title']), esc_html($form['reason'])); + } + + if (! count($items)) { + return ''; + } + + return $this->paragraph(esc_html__('De volgende formulieren zijn overgeslagen en moeten handmatig aangepast worden:', 'prefill-gravity-forms')) + . $this->list($items); + } + + private function formLink(int $formId, string $title): string + { + return sprintf( + '%s (ID %d)', + esc_url(admin_url(sprintf('admin.php?page=gf_edit_forms&id=%d', $formId))), + esc_html($title), + $formId + ); + } + + private function paragraph(string $html): string + { + return sprintf('

%s

', $html); + } + + private function list(array $items): string + { + return sprintf('
  • %s
', implode('
  • ', $items)); + } +} diff --git a/src/PrefillGravityForms/Providers/GravityFormsServiceProvider.php b/src/PrefillGravityForms/Providers/GravityFormsServiceProvider.php index ee98530..05caf38 100644 --- a/src/PrefillGravityForms/Providers/GravityFormsServiceProvider.php +++ b/src/PrefillGravityForms/Providers/GravityFormsServiceProvider.php @@ -5,6 +5,7 @@ use GF_Fields; use GFAddOn; use GFForms; +use OWC\PrefillGravityForms\Console\MigrateSupplierCommand; use function OWC\PrefillGravityForms\Foundation\Helpers\config; use function OWC\PrefillGravityForms\Foundation\Helpers\view; use OWC\PrefillGravityForms\Foundation\ServiceProvider; @@ -13,6 +14,7 @@ use OWC\PrefillGravityForms\GravityForms\GravityFormsFieldSettings; use OWC\PrefillGravityForms\GravityForms\GravityFormsFormSettings; use OWC\PrefillGravityForms\GravityForms\GravityFormsPrefilledFields; +use WP_CLI; class GravityFormsServiceProvider extends ServiceProvider { @@ -21,6 +23,19 @@ public function register(): void $this->registerHooks(); $this->registerFieldsWithTabs(); $this->registerSettingsAddon(); + $this->registerCommands(); + } + + /** + * @since NEXT + */ + protected function registerCommands(): void + { + if (! defined('WP_CLI') || ! WP_CLI) { + return; + } + + WP_CLI::add_command('prefill migrate-supplier', MigrateSupplierCommand::class); } protected function registerHooks(): void diff --git a/src/PrefillGravityForms/Services/SupplierMigrationService.php b/src/PrefillGravityForms/Services/SupplierMigrationService.php new file mode 100644 index 0000000..d6ad768 --- /dev/null +++ b/src/PrefillGravityForms/Services/SupplierMigrationService.php @@ -0,0 +1,313 @@ +sources()); + } + + /** + * Returns the keys of the V2 suppliers that can be migrated to, e.g. 'enable-u-v2'. + */ + public function targetSuppliers(): array + { + return array_keys($this->targets()); + } + + public function canMigrate(string $from, string $to): bool + { + return isset($this->sources()[$from], $this->targets()[$to]); + } + + /** + * Find the migration for a change of the global supplier setting, which uses the controller names, e.g. + * 'VrijBRP' to 'EnableUV2'. Returns the supplier keys, e.g. ['vrij-brp', 'enable-u-v2'], or null when there is none. + * + * @return array{0: string, 1: string}|null + */ + public function findMigrationForGlobalSupplierChange(string $from, string $to): ?array + { + $from = $this->supplierByLabel($from, $this->sourceSuppliers()); + $to = $this->supplierByLabel($to, $this->targetSuppliers()); + + return null === $from || null === $to ? null : [$from, $to]; + } + + /** + * Returns the key of a supplier by its controller name, e.g. 'EnableU' becomes 'enable-u'. + */ + public function supplierByLabel(string $label, ?array $suppliers = null): ?string + { + foreach ($suppliers ?? array_keys((array) config('suppliers.mapping', [])) as $supplier) { + if ('' !== $label && $this->supplierLabel($supplier) === $label) { + return $supplier; + } + } + + return null; + } + + /** + * Returns the controller name of a supplier key, e.g. 'enable-u' becomes 'EnableU'. + */ + public function supplierLabel(string $supplier): string + { + $mapping = config('suppliers.mapping', []); + + return is_array($mapping) ? (string) ($mapping[$supplier] ?? '') : ''; + } + + /** + * Migrate (or with $dryRun only report) all forms and blocks linked to the V1 supplier $from to the V2 supplier $to. + * + * @return array{ + * from: string, + * to: string, + * forms: array}>, + * skipped_forms: array, + * posts: array + * } + */ + public function migrate(string $from, string $to, bool $dryRun = false): array + { + if (! $this->canMigrate($from, $to)) { + throw new \InvalidArgumentException(sprintf('There is no migration available from supplier "%s" to "%s".', $from, $to)); + } + + return [ + 'from' => $from, + 'to' => $to, + ...$this->migrateForms($from, $to, $dryRun), + 'posts' => $this->migrateBlocks($from, $to, $dryRun), + ]; + } + + private function sources(): array + { + $sources = config('supplier-migrations.sources', []); + + return is_array($sources) ? $sources : []; + } + + private function targets(): array + { + $targets = config('supplier-migrations.targets', []); + + return is_array($targets) ? $targets : []; + } + + private function migrateForms(string $supplier, string $to, bool $dryRun): array + { + $report = ['forms' => [], 'skipped_forms' => []]; + + if (! class_exists('GFAPI')) { + return $report; + } + + // Include inactive and trashed forms, these could be restored later on. + foreach (GFAPI::get_forms(null, null) as $form) { + if (($form[self::FORM_SETTING_SUPPLIER] ?? '') !== $supplier) { + continue; + } + + $formId = (int) $form['id']; + $title = (string) ($form['title'] ?? ''); + + // Theme mapping files contain custom options which can not be mapped automatically. + $themeMapping = (string) ($form[self::FORM_SETTING_THEME_MAPPING] ?? '0'); + + if ('0' !== $themeMapping && '' !== $themeMapping) { + $report['skipped_forms'][$formId] = [ + 'title' => $title, + 'reason' => sprintf(__('gebruikt mappingbestand "%s" uit het thema', 'prefill-gravity-forms'), basename($themeMapping)), + ]; + + continue; + } + + $result = $this->migrateFormFields($form, $this->sources()[$supplier], ! $dryRun); + $report['forms'][$formId] = ['title' => $title] + $result; + + if ($dryRun) { + continue; + } + + $form[self::FORM_SETTING_SUPPLIER_LEGACY] = $supplier; + $form[self::FORM_SETTING_SUPPLIER] = $to; + + $updated = GFAPI::update_form($form); + + if (is_wp_error($updated)) { + unset($report['forms'][$formId]); + $report['skipped_forms'][$formId] = ['title' => $title, 'reason' => $updated->get_error_message()]; + } + } + + return $report; + } + + /** + * Maps the linked field values of the form fields, the fields are objects so the form is modified by reference. + * When $apply is false the fields are left untouched, so a dry run does not alter forms cached by Gravity Forms. + */ + private function migrateFormFields(array $form, array $fieldMapping, bool $apply): array + { + $result = ['migrated' => 0, 'unmapped' => []]; + + foreach ($form['fields'] ?? [] as $field) { + $value = $field->linkedFieldValue ?? ''; + + if (! is_string($value) || '' === $value) { + continue; + } + + $newValue = $fieldMapping[$value] ?? null; + + $isMapped = is_string($newValue) && '' !== $newValue; + + if ($isMapped) { + $result['migrated']++; + } else { + $result['unmapped'][(int) $field->id] = [ + 'label' => (string) ($field->label ?? ''), + 'value' => $value, + ]; + } + + if (! $apply) { + continue; + } + + /** + * Keep the original value so it is clear what the field was linked to. Fields without a V2 counterpart + * are unlinked, the V1 value does not exist in V2 and would otherwise be used to prefill the field. + */ + $field->{self::FIELD_LEGACY_PROPERTY} = $value; + $field->linkedFieldValue = $isMapped ? $newValue : ''; + } + + return $result; + } + + private function migrateBlocks(string $supplier, string $target, bool $dryRun): array + { + global $wpdb; + + $from = $this->supplierLabel($supplier); + $to = $this->supplierLabel($target); + + if ('' === $from || '' === $to) { + return []; + } + + $posts = $wpdb->get_results($wpdb->prepare( + "SELECT ID, post_title, post_content FROM {$wpdb->posts} WHERE post_type != 'revision' AND post_content LIKE %s", + '%' . $wpdb->esc_like('/s', preg_quote(self::BLOCK_NAME, '/')); + $optionMapping = config('supplier-migrations.block_options', []); + + return (string) preg_replace_callback($pattern, function (array $matches) use ($from, $to, $optionMapping, &$migrated): string { + // Decode as objects to preserve empty objects when encoding again. + $attributes = json_decode($matches[1]); + + if (! $attributes instanceof stdClass) { + return $matches[0]; + } + + $supplier = $attributes->selectedSupplier->value ?? ''; + $option = $attributes->selectedOption->value ?? ''; + $mappedOption = is_string($option) ? ($optionMapping[$option] ?? null) : null; + + // Blocks already linked to the V2 supplier only need their option mapped, e.g. after an earlier migration. + if ($supplier !== $from && ($supplier !== $to['value'] || ! is_array($mappedOption))) { + return $matches[0]; + } + + $attributes->selectedSupplier = (object) $to; + + if (is_array($mappedOption)) { + $attributes->selectedOption = (object) $mappedOption; + } + + $migrated++; + + return sprintf( + '', + self::BLOCK_NAME, + serialize_block_attributes((array) $attributes), + empty($matches[2]) ? '' : '/' + ); + }, $content); + } +} diff --git a/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php b/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php new file mode 100644 index 0000000..09aaad8 --- /dev/null +++ b/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php @@ -0,0 +1,103 @@ + 'burgerservicenummer', + 'aNummer' => 'aNummer', + 'geslachtsaanduiding' => 'geslacht.omschrijving', + 'leeftijd' => 'leeftijd', + + 'naam.geslachtsnaam' => 'naam.geslachtsnaam', + 'naam.voorletters' => 'naam.voorletters', + 'naam.voornamen' => 'naam.voornamen', + 'naam.voorvoegsel' => 'naam.voorvoegsel', + 'naam.aanschrijfwijze' => 'naam.aanschrijfwijze', + 'naam.aanduidingNaamgebruik' => 'naam.aanduidingNaamgebruik.omschrijving', + + 'nationaliteiten.datumIngangGeldigheid.datum' => 'nationaliteiten.0.datumIngangGeldigheid.datum', + 'nationaliteiten.datumIngangGeldigheid.jaar' => null, + 'nationaliteiten.datumIngangGeldigheid.maand' => null, + 'nationaliteiten.datumIngangGeldigheid.dag' => null, + 'nationaliteiten.nationaliteit.omschrijving' => 'nationaliteiten.0.nationaliteit.omschrijving', + 'nationaliteiten.nationaliteit.code' => 'nationaliteiten.0.nationaliteit.code', + + 'geboorte.datum.datum' => 'geboorte.datum.datum', + 'geboorte.land.omschrijving' => 'geboorte.land.omschrijving', + 'geboorte.plaats.omschrijving' => 'geboorte.plaats.omschrijving', + + 'verblijfplaats.huisnummer' => 'verblijfplaats.verblijfadres.huisnummer', + 'verblijfplaats.huisletter' => 'verblijfplaats.verblijfadres.huisletter', + 'verblijfplaats.postcode' => 'verblijfplaats.verblijfadres.postcode', + 'verblijfplaats.adresregel1' => 'adressering.adresregel1', + 'verblijfplaats.adresregel2' => 'adressering.adresregel2', + 'verblijfplaats.gemeenteVanInschrijving.omschrijving' => 'gemeenteVanInschrijving.omschrijving', + 'verblijfplaats.gemeenteVanInschrijving.code' => 'gemeenteVanInschrijving.code', + + '_embedded.partners.soortVerbintenis' => 'partners.0.soortVerbintenis.omschrijving', + '_embedded.partners.naam.geslachtsnaam' => 'partners.0.naam.geslachtsnaam', + '_embedded.partners.naam.voornamen' => 'partners.0.naam.voornamen', + ]; + + foreach (['ouders.0', 'ouders.1', 'kinderen.*'] as $relative) { + $fields += self::prefix(self::relative(), "_embedded.{$relative}", $relative); + + // Children do not have a gender attribute in the V2 mapping options. + $fields["_embedded.{$relative}.geslachtsaanduiding"] = 'kinderen.*' === $relative ? null : "{$relative}.geslacht.omschrijving"; + } + + return $fields; + } + + /** + * Attributes of an embedded relative (parent, child or partner), which share the same structure in V1. + */ + public static function relative(): array + { + return [ + 'burgerservicenummer' => null, + 'naam.geslachtsnaam' => 'naam.geslachtsnaam', + 'naam.voorletters' => 'naam.voorletters', + 'naam.voornamen' => 'naam.voornamen', + 'naam.voorvoegsel' => 'naam.voorvoegsel', + 'geboorte.datum.datum' => 'geboorte.datum.datum', + 'geboorte.datum.dag' => null, + 'geboorte.datum.maand' => null, + 'geboorte.plaats.code' => null, + 'geboorte.plaats.omschrijving' => 'geboorte.plaats.omschrijving', + 'geboorte.land.code' => null, + 'geboorte.land.omschrijving' => 'geboorte.land.omschrijving', + ]; + } + + /** + * Prefix the V1 keys and the V2 values of a mapping, values without a V2 counterpart remain null. + */ + public static function prefix(array $mapping, string $v1Prefix, string $v2Prefix): array + { + $prefixed = []; + + foreach ($mapping as $v1 => $v2) { + $prefixed["{$v1Prefix}.{$v1}"] = null === $v2 ? null : "{$v2Prefix}.{$v2}"; + } + + return $prefixed; + } +} diff --git a/webpack.config.js b/webpack.config.js index f79f692..7283414 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,6 +9,7 @@ module.exports = { ...entries, icons: './resources/scss/icons.scss', style: './resources/scss/index.scss', + 'supplier-migration': './resources/js/admin/supplier-migration.js', }; }, }; From 3fa2428b02d3d76131ad6cf80ff22cb266513c18 Mon Sep 17 00:00:00 2001 From: Mike van den Hoek Date: Tue, 24 Nov 2026 09:27:12 +0100 Subject: [PATCH 2/5] chore: align markdown formatting with Prettier and keep changelog style --- .editorconfig | 6 +- .gitignore | 3 + .prettierignore | 1 + CHANGELOG.md | 226 ++++++++++++++++++++++++------------------------ README.md | 10 +-- 5 files changed, 127 insertions(+), 119 deletions(-) create mode 100644 .prettierignore diff --git a/.editorconfig b/.editorconfig index 5053de4..e919d14 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,4 +23,8 @@ indent_style = space indent_size = 2 [{*.txt,wp-config-sample.php}] -end_of_line = crlf \ No newline at end of file +end_of_line = crlf + +[*.md] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index 367b326..3988082 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,9 @@ !.eslintrc !.eslintignore +# Prettier +!.prettierignore + # track .editorconfig file (i.e. do NOT ignore it) !.editorconfig diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1b763b1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed0022..19c87aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,293 +2,293 @@ ## [Unreleased] -- Added: migrate forms and personal data blocks from a V1 supplier (EnableU, PinkRoccade, VrijBRP) to a V2 supplier (EnableU V2, PinkRoccade V2) when changing the supplier in the add-on settings, after confirmation -- Changed: personal data block only shows the options of the API version of the selected supplier -- Added: WP-CLI command `wp prefill migrate-supplier` to migrate forms and personal data blocks to a V2 supplier +- Added: migrate forms and personal data blocks from a V1 supplier (EnableU, PinkRoccade, VrijBRP) to a V2 supplier (EnableU V2, PinkRoccade V2) when changing the supplier in the add-on settings, after confirmation +- Changed: personal data block only shows the options of the API version of the selected supplier +- Added: WP-CLI command `wp prefill migrate-supplier` to migrate forms and personal data blocks to a V2 supplier ## [v2.1.3] - 2026-11-23 -- Fix: disabled form fields +- Fix: disabled form fields ## [v2.1.2] - 2026-11-17 -- Fix: use general goal binding when a form has no goal binding (V2 suppliers) +- Fix: use general goal binding when a form has no goal binding (V2 suppliers) ## [v2.1.1] - 2026-10-27 -- Added: make log directory configurable to keep log files outside the webroot +- Added: make log directory configurable to keep log files outside the webroot ## [v2.1.0] - 2026-09-16 -- Added: setting to disable outgoing requests as maintenance mode +- Added: setting to disable outgoing requests as maintenance mode ## [v2.0.1] - 2026-07-24 -- Chore: clarify HTTP headers x-doelbinding and x-verwerking +- Chore: clarify HTTP headers x-doelbinding and x-verwerking ## [v2.0.0] - 2026-06-03 -- Added: upgrade to PHP 8 -- Added: user object model class with fullName support -- Added: mTLS certificate configuration with passphrase support and improved tooltips -- Added: conditional usage of SSL certificates -- Added: Pink and EnableU v2 implementation -- Fix: prevent octal conversion from stripping leading zeros in BSN -- Fix: path traversal bypass -- Fix: validate SSL certificates and their paths -- Fix: set supplier certificate as CA to support self-signed certificates -- Fix: use general goal binding when none is used in the request -- Fix: mapping options VrijBRP -- Fix: broken cURL error handling -- Fix: separate cache for personal data service and form requests -- Fix: personal data service class, also improves V2 usage -- Fix: BSN location in response -- Fix: escape output and strip version suffix in personal data row block -- Fix: personal data row inner block -- Fix: remove some default values in GF Addon settings -- Change: VrijBRP controller uses specific cURL headers -- Change: rename doelBinding to goalBinding -- Change: update block registration and prefix to make blocks visible in editor -- Change: verify SSL peer and host when using client certificates -- Chore: update mapping options BRP V2 -- Chore: remove EnableU as supplier -- Chore: add missing information to personal data block for mijngegevens page -- Chore: improve README.md +- Added: upgrade to PHP 8 +- Added: user object model class with fullName support +- Added: mTLS certificate configuration with passphrase support and improved tooltips +- Added: conditional usage of SSL certificates +- Added: Pink and EnableU v2 implementation +- Fix: prevent octal conversion from stripping leading zeros in BSN +- Fix: path traversal bypass +- Fix: validate SSL certificates and their paths +- Fix: set supplier certificate as CA to support self-signed certificates +- Fix: use general goal binding when none is used in the request +- Fix: mapping options VrijBRP +- Fix: broken cURL error handling +- Fix: separate cache for personal data service and form requests +- Fix: personal data service class, also improves V2 usage +- Fix: BSN location in response +- Fix: escape output and strip version suffix in personal data row block +- Fix: personal data row inner block +- Fix: remove some default values in GF Addon settings +- Change: VrijBRP controller uses specific cURL headers +- Change: rename doelBinding to goalBinding +- Change: update block registration and prefix to make blocks visible in editor +- Change: verify SSL peer and host when using client certificates +- Chore: update mapping options BRP V2 +- Chore: remove EnableU as supplier +- Chore: add missing information to personal data block for mijngegevens page +- Chore: improve README.md ## v1.9.1 -- Fix: normalize malformed HaalCentraal endpoint from supplier -- Chore: add huisletter to 'Mijn gegevens' block +- Fix: normalize malformed HaalCentraal endpoint from supplier +- Chore: add huisletter to 'Mijn gegevens' block ## v1.9.0 -- Add: supplement embedded data via form setting +- Add: supplement embedded data via form setting ## v1.8.2 -- Add: housenumberaddition option to openzaak prefill +- Add: housenumberaddition option to openzaak prefill ## v1.8.1 -- Add: housenumberaddition option to pink prefill +- Add: housenumberaddition option to pink prefill ## v1.8.0 -- Add: implement transient caching for cURL responses -- Add: encrypt cached data +- Add: implement transient caching for cURL responses +- Add: encrypt cached data ## v1.7.10 -- Add: data option to personal data block +- Add: data option to personal data block ## v1.7.9 -- Change: skip prefilling when identification session is active in editor +- Change: skip prefilling when identification session is active in editor ## v1.7.8 -- Change: remove ucfirst when setting defaultValue of field when prefilled +- Change: remove ucfirst when setting defaultValue of field when prefilled ## v1.7.7 -- Fix: text domain was loaded too early +- Fix: text domain was loaded too early ## v1.7.6 -- Fix: prevent error log spam regarding null being passed to dirname because of a missing variable -- Change: add editorconfig line that reflects the currently in use code style to prevent whitespace issues +- Fix: prevent error log spam regarding null being passed to dirname because of a missing variable +- Change: add editorconfig line that reflects the currently in use code style to prevent whitespace issues ## v1.7.5 -- Change: clear values of custom fields when validations fail for conditional logic to work +- Change: clear values of custom fields when validations fail for conditional logic to work ## v1.7.4 -- Change: hide custom GF fields success views when no success message has been configured +- Change: hide custom GF fields success views when no success message has been configured ## v1.7.3 -- Fix: set field properties age check validation messages +- Fix: set field properties age check validation messages ## v1.7.2 -- Fix: prefill children information +- Fix: prefill children information ## v1.7.1 -- Add: max age check +- Add: max age check ## v1.7.0 -- Add: children to the mapping options -- Add: 'huisletter' as prefill option to supplier options WeAreFrank +- Add: children to the mapping options +- Add: 'huisletter' as prefill option to supplier options WeAreFrank ## v1.6.11 -- Change: hide empty values personal-data-row Gutenberg block +- Change: hide empty values personal-data-row Gutenberg block ## v1.6.10 -- Fix: remove typehinting on status param in logError() +- Fix: remove typehinting on status param in logError() ## v1.6.9 -- Add: configurable api-key header in GF addon settings +- Add: configurable api-key header in GF addon settings ## v1.6.8 -- Add: timeout option to CURL args +- Add: timeout option to CURL args ## v1.6.7 -- Fix: check if DigiD userdata is not null before retrieving BSN +- Fix: check if DigiD userdata is not null before retrieving BSN ## v1.6.6 -- Add: add help property to supplier select control in personal-data-row block -- Change: remove static response from controller classes +- Add: add help property to supplier select control in personal-data-row block +- Change: remove static response from controller classes ## v1.6.5 -- Fix: return null when controller class, based on selected supplier, is not found +- Fix: return null when controller class, based on selected supplier, is not found ## v1.6.4 -- Fix: personal data row block so it supports multiple suppliers -- Fix: check if multi-dimensional array contains only one array +- Fix: personal data row block so it supports multiple suppliers +- Fix: check if multi-dimensional array contains only one array ## v1.6.3 -- Add: check response of curl request and return exception when request failed +- Add: check response of curl request and return exception when request failed ## v1.6.2 -- Change: logging uses message and status code inside controllers +- Change: logging uses message and status code inside controllers ## v1.6.1 -- Change: WeAreFrank! GF fields mapping options +- Change: WeAreFrank! GF fields mapping options ## v1.6.0 -- Add: WeAreFrank! as supplier -- Change: refactor controller classes -- Change: English translatable strings to Dutch +- Add: WeAreFrank! as supplier +- Change: refactor controller classes +- Change: English translatable strings to Dutch ## v1.5.0 -- Add: implement IdpUserData for retrieving BSN +- Add: implement IdpUserData for retrieving BSN ## v1.4.1 -- Fix: check if $holder is array before using 'isSingleMultidimensionalArray' method when prefilling +- Fix: check if $holder is array before using 'isSingleMultidimensionalArray' method when prefilling ## v1.4.0 -- Add: VrijBRP as supplier -- Add: custom age check and municipality check GF fields -- Change: GF Addon fields + implement basic token usage -- Change: explode dot notated values when prefilling +- Add: VrijBRP as supplier +- Add: custom age check and municipality check GF fields +- Change: GF Addon fields + implement basic token usage +- Change: explode dot notated values when prefilling ## v1.3.0 -- Add: check for eIDAS BSN -- Change: changelog formatting +- Add: check for eIDAS BSN +- Change: changelog formatting ## v1.2.1 -- Add: README.md -- Change: update license to EUPL 1.2 +- Add: README.md +- Change: update license to EUPL 1.2 ## v1.2.0 -- Add: personal data blocks +- Add: personal data blocks ## v1.1 -- Add: prefill all advanced date fields -- Change: clean-up/refactoring & run composer format script +- Add: prefill all advanced date fields +- Change: clean-up/refactoring & run composer format script ## v1.0.17 -- Add: disable prefilled form fields when using 'Openzaak' or 'PinkRoccade' as configured supplier +- Add: disable prefilled form fields when using 'Openzaak' or 'PinkRoccade' as configured supplier ## v1.0.16 -- Add: when a field is mapped but there is no value found, set field to read-only +- Add: when a field is mapped but there is no value found, set field to read-only ## v1.0.15 -- Change: mapping field 'woonplaats' to 'woonplaatsnaam' +- Change: mapping field 'woonplaats' to 'woonplaatsnaam' ## v1.0.14 -- Add: implement API key general setting -- Change: gf-addon title and icon +- Add: implement API key general setting +- Change: gf-addon title and icon ## v1.0.13 -- Change: retrieve bsn by DigiD session instead of value of form field +- Change: retrieve bsn by DigiD session instead of value of form field ## v1.0.12 -- Add: tooltip for the 'Passphrase' form setting -- Change: clean-up code +- Add: tooltip for the 'Passphrase' form setting +- Change: clean-up code ## v1.0.11 -- Change: restore 'Passphrase' form setting, is only used when this setting has a value +- Change: restore 'Passphrase' form setting, is only used when this setting has a value ## v1.0.10 -- Fix: root path to certificates +- Fix: root path to certificates ## v1.0.9 -- Add: logging to Microsoft Teams +- Add: logging to Microsoft Teams ## v1.0.8 -- Change: supplement BSN when length is lower than required 9 +- Change: supplement BSN when length is lower than required 9 ## v1.0.7 -- Change: CURL header x-doelbinding is optional -- Change: remove 'Passphrase' form setting +- Change: CURL header x-doelbinding is optional +- Change: remove 'Passphrase' form setting ## v1.0.6 -- Change: iConnect settings, enable selection of .crt and .cer files +- Change: iConnect settings, enable selection of .crt and .cer files ## v1.0.5 -- Change: plugin name +- Change: plugin name ## v1.0.4 -- Change: Apply the right plugin version +- Change: Apply the right plugin version ## v1.0.3 -- Add: handle multidimensional arrays in response when retrieving linked values +- Add: handle multidimensional arrays in response when retrieving linked values ## v1.0.2 -- Add: expand selectable prefill fields in form field settings -- Add: return linked values with ucfirst() when form field type is 'text' -- Add: return linked values in dd-mm-yyyy notation when form field type is 'date' -- Add: expand parameters to request url -- Add: form field setting for expanding the result set +- Add: expand selectable prefill fields in form field settings +- Add: return linked values with ucfirst() when form field type is 'text' +- Add: return linked values in dd-mm-yyyy notation when form field type is 'date' +- Add: expand parameters to request url +- Add: form field setting for expanding the result set ## v1.0.1 -- Add: plugin description -- Add: retrieve BSN from DigiD session. -- Add: dependency Yard | GravityForms DigiD plugin +- Add: plugin description +- Add: retrieve BSN from DigiD session. +- Add: dependency Yard | GravityForms DigiD plugin ## v1.0.0 -- Add: prefill general settings -- Add: prefill form settings -- Add: prefill form field settings -- Add: Prefill selected form fields on pre-render of form +- Add: prefill general settings +- Add: prefill form settings +- Add: prefill form field settings +- Add: Prefill selected form fields on pre-render of form diff --git a/README.md b/README.md index 1472217..1ee34ab 100644 --- a/README.md +++ b/README.md @@ -118,12 +118,12 @@ This plugin ships with two Gutenberg blocks for displaying personal data of the Each Personal Data Row block must be configured in the block sidebar: -| Setting | Description | -|---|---| -| Supplier | Must match the supplier configured in the plugin settings. | +| Setting | Description | +| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Supplier | Must match the supplier configured in the plugin settings. | | Goal binding (Doelbinding) | Required for HaalCentraal API v2 — determines which fields are returned. Describes why the personal data is being requested and under which legal task or authority the organization does so. | -| Processing (Verwerking) | Optional for HaalCentraal API v2. Describes for which work process or process step the BRP data is being requested. | -| Personal data field | The specific BRP attribute to display (e.g. name, date of birth). | +| Processing (Verwerking) | Optional for HaalCentraal API v2. Describes for which work process or process step the BRP data is being requested. | +| Personal data field | The specific BRP attribute to display (e.g. name, date of birth). | ## Logging From 52d78a92ed222bed875f2b628fce321a2c2ecbbe Mon Sep 17 00:00:00 2001 From: Mike van den Hoek Date: Tue, 24 Nov 2026 09:27:25 +0100 Subject: [PATCH 3/5] chore: remove TODO.md --- TODO.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 TODO.md diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 733c330..0000000 --- a/TODO.md +++ /dev/null @@ -1,4 +0,0 @@ -# TODO - -- Remove deceased related entity by form setting. -- Refactor to PHP8 branch. From 3f5eb35c96d2b2d557b827c51b008541c25c45cf Mon Sep 17 00:00:00 2001 From: Mike van den Hoek Date: Thu, 26 Nov 2026 08:34:05 +0100 Subject: [PATCH 4/5] feat: add burgerservicenummer of relatives to V2 supplier options --- config/supplier-migrations/sources/vrij-brp.php | 1 - resources/views/partials/gf-field-options-enable-u-v2.php | 4 ++++ resources/views/partials/gf-field-options-pink-roccade-v2.php | 4 ++++ .../SupplierMigration/V1ToV2FieldMapping.php | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config/supplier-migrations/sources/vrij-brp.php b/config/supplier-migrations/sources/vrij-brp.php index ef60b97..16cca70 100644 --- a/config/supplier-migrations/sources/vrij-brp.php +++ b/config/supplier-migrations/sources/vrij-brp.php @@ -13,7 +13,6 @@ // VrijBRP has a single partner, which is available with most of its attributes in V2 as well. $partner = [ - 'burgerservicenummer' => null, 'soortVerbintenis' => 'soortVerbintenis.omschrijving', 'aangaanHuwelijkPartnerschap.datum.datum' => 'aangaanHuwelijkPartnerschap.datum.datum', 'aangaanHuwelijkPartnerschap.datum.dag' => null, diff --git a/resources/views/partials/gf-field-options-enable-u-v2.php b/resources/views/partials/gf-field-options-enable-u-v2.php index 1ea614e..48dc4cb 100644 --- a/resources/views/partials/gf-field-options-enable-u-v2.php +++ b/resources/views/partials/gf-field-options-enable-u-v2.php @@ -44,6 +44,7 @@ + @@ -60,6 +61,7 @@ + @@ -73,6 +75,7 @@ + @@ -86,6 +89,7 @@ + diff --git a/resources/views/partials/gf-field-options-pink-roccade-v2.php b/resources/views/partials/gf-field-options-pink-roccade-v2.php index 1ea614e..48dc4cb 100644 --- a/resources/views/partials/gf-field-options-pink-roccade-v2.php +++ b/resources/views/partials/gf-field-options-pink-roccade-v2.php @@ -44,6 +44,7 @@ + @@ -60,6 +61,7 @@ + @@ -73,6 +75,7 @@ + @@ -86,6 +89,7 @@ + diff --git a/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php b/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php index 09aaad8..2c40e79 100644 --- a/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php +++ b/src/PrefillGravityForms/SupplierMigration/V1ToV2FieldMapping.php @@ -72,7 +72,7 @@ public static function base(): array public static function relative(): array { return [ - 'burgerservicenummer' => null, + 'burgerservicenummer' => 'burgerservicenummer', 'naam.geslachtsnaam' => 'naam.geslachtsnaam', 'naam.voorletters' => 'naam.voorletters', 'naam.voornamen' => 'naam.voornamen', From 2052b74d5912df4d677db529a927fc30f8cc8091 Mon Sep 17 00:00:00 2001 From: Mike van den Hoek Date: Thu, 26 Nov 2026 13:22:04 +0100 Subject: [PATCH 5/5] feat: add --check flag to the supplier migration command --- CHANGELOG.md | 2 +- README.md | 6 ++ .../Console/MigrateSupplierCommand.php | 71 ++++++++++++++++ .../Services/SupplierMigrationService.php | 80 +++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c87aa..65d413b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Added: migrate forms and personal data blocks from a V1 supplier (EnableU, PinkRoccade, VrijBRP) to a V2 supplier (EnableU V2, PinkRoccade V2) when changing the supplier in the add-on settings, after confirmation - Changed: personal data block only shows the options of the API version of the selected supplier -- Added: WP-CLI command `wp prefill migrate-supplier` to migrate forms and personal data blocks to a V2 supplier +- Added: WP-CLI command `wp prefill migrate-supplier` to migrate forms and personal data blocks to a V2 supplier, use `--check` to verify migrated forms afterwards ## [v2.1.3] - 2026-11-23 diff --git a/README.md b/README.md index 1ee34ab..fbb8b21 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ wp prefill migrate-supplier enable-u enable-u-v2 --dry-run wp prefill migrate-supplier vrij-brp enable-u-v2 ``` +After linking the reported fields manually, use `--check` to verify the migrated forms. It lists fields that are still unlinked or linked to an unknown V2 option, and forms or blocks that are not migrated yet. Nothing is changed and the command exits with an error when issues are found: + +```sh +wp prefill migrate-supplier vrij-brp enable-u-v2 --check +``` + On a multisite, add `--url=` to migrate a specific site. ### Cache Encryption diff --git a/src/PrefillGravityForms/Console/MigrateSupplierCommand.php b/src/PrefillGravityForms/Console/MigrateSupplierCommand.php index e24e831..eb7b499 100644 --- a/src/PrefillGravityForms/Console/MigrateSupplierCommand.php +++ b/src/PrefillGravityForms/Console/MigrateSupplierCommand.php @@ -44,10 +44,16 @@ class MigrateSupplierCommand * [--yes] * : Do not ask for confirmation. * + * [--check] + * : Check the forms that have already been migrated, e.g. after linking the reported fields manually. + * Reports fields that are still unlinked or linked to an unknown V2 option, and anything not migrated yet. + * Exits with an error when issues are found. Nothing is changed. + * * ## EXAMPLES * * wp prefill migrate-supplier enable-u enable-u-v2 --dry-run * wp prefill migrate-supplier vrij-brp enable-u-v2 --yes + * wp prefill migrate-supplier vrij-brp enable-u-v2 --check */ public function __invoke(array $args, array $assocArgs): void { @@ -60,6 +66,12 @@ public function __invoke(array $args, array $assocArgs): void WP_CLI::error(sprintf('There is no migration available from supplier "%s" to "%s".', $from, $to)); } + if ((bool) \WP_CLI\Utils\get_flag_value($assocArgs, 'check', false)) { + $this->check($service, $from, $to); + + return; + } + try { $report = $service->migrate($from, $to, true); } catch (Throwable $e) { @@ -102,6 +114,65 @@ public function __invoke(array $args, array $assocArgs): void $this->warnSkippedForms($report); } + private function check(SupplierMigrationService $service, string $from, string $to): void + { + try { + $report = $service->check($from, $to); + $pending = $service->migrate($from, $to, true); + } catch (Throwable $e) { + WP_CLI::error($e->getMessage()); + + return; // Unreachable: WP_CLI::error() exits; keeps static analysis happy. + } + + if (0 === count($service->targetOptions($to))) { + WP_CLI::warning(sprintf('No options found for supplier "%s", linked values have not been validated.', $to)); + } + + $issues = []; + + foreach ($report['forms'] as $id => $form) { + foreach ($form['issues'] as $fieldId => $field) { + $issues[] = [ + 'form' => $id, + 'title' => $form['title'], + 'field' => $fieldId, + 'label' => $field['label'], + 'problem' => $field['problem'], + 'value' => $field['value'], + 'legacy' => $field['legacy'], + ]; + } + } + + if (count($issues)) { + WP_CLI::log('Fields that need to be linked manually:'); + \WP_CLI\Utils\format_items('table', $issues, ['form', 'title', 'field', 'label', 'problem', 'value', 'legacy']); + } + + $notMigrated = count($pending['forms']) + count($pending['posts']) + count($pending['skipped_forms']); + + if ($notMigrated) { + WP_CLI::log(''); + WP_CLI::log(sprintf('Forms and blocks still linked to "%s":', $from)); + $this->printReport($pending); + } + + WP_CLI::log(''); + WP_CLI::log(sprintf('Checked %d migrated form(s) from "%s" to "%s".', $report['checked'], $from, $to)); + + if (count($issues) || $notMigrated) { + WP_CLI::error(sprintf( + '%d field(s) in %d form(s) need attention, %d form(s)/post(s) are not migrated yet.', + count($issues), + count($report['forms']), + $notMigrated + )); + } + + WP_CLI::success('All migrated forms are linked to valid V2 options.'); + } + private function warnSkippedForms(array $report): void { if (count($report['skipped_forms'])) { diff --git a/src/PrefillGravityForms/Services/SupplierMigrationService.php b/src/PrefillGravityForms/Services/SupplierMigrationService.php index d6ad768..9aaf1cc 100644 --- a/src/PrefillGravityForms/Services/SupplierMigrationService.php +++ b/src/PrefillGravityForms/Services/SupplierMigrationService.php @@ -6,6 +6,7 @@ use GFAPI; use function OWC\PrefillGravityForms\Foundation\Helpers\config; +use function OWC\PrefillGravityForms\Foundation\Helpers\view; use stdClass; @@ -113,6 +114,85 @@ public function migrate(string $from, string $to, bool $dryRun = false): array ]; } + /** + * Check the forms migrated from the V1 supplier $from to the V2 supplier $to, e.g. after the fields reported by + * the migration have been linked manually. Reports the fields that are still unlinked since the migration and + * the fields linked to a value that is not an option of the V2 supplier. + * + * @return array{ + * from: string, + * to: string, + * checked: int, + * forms: array}> + * } + */ + public function check(string $from, string $to): array + { + if (! $this->canMigrate($from, $to)) { + throw new \InvalidArgumentException(sprintf('There is no migration available from supplier "%s" to "%s".', $from, $to)); + } + + $report = ['from' => $from, 'to' => $to, 'checked' => 0, 'forms' => []]; + + if (! class_exists('GFAPI')) { + return $report; + } + + $options = $this->targetOptions($to); + + foreach (GFAPI::get_forms(null, null) as $form) { + if (($form[self::FORM_SETTING_SUPPLIER_LEGACY] ?? '') !== $from || ($form[self::FORM_SETTING_SUPPLIER] ?? '') !== $to) { + continue; + } + + $report['checked']++; + $issues = []; + + foreach ($form['fields'] ?? [] as $field) { + $value = $field->linkedFieldValue ?? ''; + $legacy = $field->{self::FIELD_LEGACY_PROPERTY} ?? ''; + $value = is_string($value) ? $value : ''; + $legacy = is_string($legacy) ? $legacy : ''; + + if ('' === $value && '' !== $legacy) { + $problem = 'not linked'; + } elseif ('' !== $value && count($options) && ! in_array($value, $options, true)) { + $problem = 'unknown option'; + } else { + continue; + } + + $issues[(int) $field->id] = [ + 'label' => (string) ($field->label ?? ''), + 'value' => $value, + 'legacy' => $legacy, + 'problem' => $problem, + ]; + } + + if (count($issues)) { + $report['forms'][(int) $form['id']] = ['title' => (string) ($form['title'] ?? ''), 'issues' => $issues]; + } + } + + return $report; + } + + /** + * Returns the option values of the field mapping partial of a V2 supplier, e.g. 'naam.geslachtsnaam'. + * The partial is the source of the options shown in the field settings, so it is parsed instead of duplicated. + */ + public function targetOptions(string $to): array + { + $html = view(sprintf('partials/gf-field-options-%s.php', $to)); + + if (! preg_match_all('/