Added new console commands to import or export formie form to a target folder
Hi I wrote this first as a module for our project to facilitate automatic form imports post-deployment. The current workflow involves exporting complex forms as JSON to a project folder, which allows us to track changes effectively. Any team developer can import a form, modify it, and export it back to the project folder. These changes can then be committed, eliminating the need to modify forms directly on the live server.
I took the time to make a pull request to share these commands, so others can also benefit.
The following console commands have been added:
- formie/forms Manages Formie Forms.
formie/forms/export Export Formie forms as json, comma-separated list of IDs and/or handles
formie/forms/import Import a Formie form json from a path.
formie/forms/import-all Import all Formie json from a folder
formie/forms/list list all possible Formie forms to be exported or imported
By default, all exports will be placed in the folder @storage/formie-export, but via the settings, this can be changed to any other folder:
return [
'*' => [
'defaultExportFolder' => '@root/exports/formie',
How to use the commands: Export
# form id
./craft formie/forms/export 45
# handle
./craft formie/forms/export contact
# mix
./craft formie/forms/export contact,45,newsletter
Import
# relative
./craft formie/forms/import storage/formie-export/formie-newsletter.json
# absolute
./craft formie/forms/import /var/www/html/storage/formie-export/formie-newsletter.json
# relative + create a new form if duplicate
./craft formie/forms/import storage/formie-export/formie-newsletter.json --create
Import all
This will move the import to jobs, to prevent db overload or php timeouts.
./craft formie/forms/import-all
# You can also change the target folder
./craft formie/forms/import-all exports/formie
Please feel free to share your feedback. I am happy to make any necessary changes.
Thanks for putting this together. I've already cleaned up a few typos and small changes to the PR, but I'm going to give it some thought as to whether this is something we want included in the core plugin as it adds another thing for us to test and manage when it comes to import/export.
Thank you for taking the time to review my pull request and for your feedback. I took the time to make it more consistent by improving the wording and error handling. I understand your concerns about adding another feature to the core plugin, the console command calls the existing Import-Export helper class, therefore this shouldn't have too much of an impact.
I'm available to discuss any specific concerns or adjustments you'd like to see.
Sorry for letting this sit for too long, I was about to merge this but there are pending changes to get things up to date. Let me know if you're up for making those changes, and otherwise happy to merge!
Hi Josh Thanks for your reply, I resolved the conflicts. You can now merge it, if something is not yet right, just write me back.
Thanks for the update, much appreciated!