Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added new console commands to import or export formie form to a target folder #1972

Open
wants to merge 5 commits into
base: craft-5
Choose a base branch
from

Conversation

Megafry
Copy link

@Megafry Megafry commented Jul 6, 2024

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.

@Megafry Megafry changed the title Added new console commands to import or export formie form to a taget folder Added new console commands to import or export formie form to a target folder Jul 6, 2024
@engram-design
Copy link
Member

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.

Add early returns after error
Fix typos in comments and method descriptions
Small Refactoring
@Megafry
Copy link
Author

Megafry commented Jul 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants