Jump to content

Is there a way to set template and field configuration using a text file?


johnstephens
 Share

Recommended Posts

I see it's possible to Export and Import data from the Templates and Fields panels. Awesome. Is it possible to configure these settings in a text file or files that live in the site directory?

The /site/templates directory already contains PHP files for each template, but they don't cover the template and field metadata that one configures using the ProcessWire admin panels.

Link to comment
Share on other sites

Adrian's Migrator does that => https://github.com/adrianbj/ProcessMigrator

Allows automated migration and sharing of page tree content along with their templates and fields via JSON files. These JSON files can be imported into another PW installation to recreate the entire structure and content, including files and images.

Thank you, Sérgio!

I installed and tooled around with ProcessMigrator, and I don't think it does what I had in mind.

To clarify, I was wondering if there was a way—whether natively, or by module—to save the template and field settings to a text file (JSON would be perfect) somewhere in the /site directory. ProcessWire would then use that config file instead of the Templates and Fields panels. So instead of configuring Templates and Fields in ProcessWire's UI, these settings would be entirely configured in a text file, that could be kept with the template PHP files in version control.

Does that make sense?

Based on my quick look at ProcessMigrator, it lets you save your Templates and Fields settings (and a lot more) to the file system, but it doesn't read that data back into ProcessWire unless you trigger an Import using the Migrator panel. Is that right?

  • Like 1
Link to comment
Share on other sites

hi john,

that would be absolutely awesome! it would open up a lot of possibilities and could solve an often discussed problem with pw of having different live/production states of a site. see for example this post (and above example of lostkobrakai's update script): https://processwire.com/talk/topic/12383-developmentstaging-of-processwire-site/?p=115027

if we could outsource the config of all the templates and fields to files and then synch them to github or even update a site like this via github commits that would be great!!

  • Like 2
Link to comment
Share on other sites

I've played around with this a little bit and want to share some results:

manual import/export seems to work quite well (never used that before) and most of it should be possible to automate. it becomes a little tricky when you delete fields or change the fieldtype or the like. deleting fields would be the easier one because it would leave the field untouched on field import, remove the field from all the templates that have used it before (you would have to make this step manualle before you can delete the field on your "master" pw instance) and after the import see if there are fields not used by any template and delete them.

changing ckeditor field "body" to text worked. changing it back to ckeditor did not work. first, it asked for a second commit (could be hard to handle in a script?): (see the message on top of the screenshot)

post-2137-0-15341200-1460460898_thumb.pn

and even then it did not replicate the change

post-2137-0-61028700-1460460893_thumb.pn

@john

i don't want to get offtopic here. am i talking about what your intentions have been?

Link to comment
Share on other sites

Does that make sense?

Based on my quick look at ProcessMigrator, it lets you save your Templates and Fields settings (and a lot more) to the file system, but it doesn't read that data back into ProcessWire unless you trigger an Import using the Migrator panel. Is that right?

It makes sense, but I think is a bit dangerous to have this kind of feature because of the risk of data corruption. Consider how PW's could handle a field that's have other fields depending on its information, for instance, if it's missing in the .json configuration for some reason, after a commit. 

With ProcessMigrator, you can export your fields in a json, edit this file in a editor and import it again. So you have control of are going to change. 

----

But this scenario could you work, I wonder, if PW had something like Laravel's migrations, so you could rollback all the changes in the db to a previous state. 

But maybe I'm wrong and that's a way to do that like @bernhard is describing. 

Link to comment
Share on other sites

@Sergio

I thought laravel's rollback does just rollback schema changes. That one can be easily done like I described it in the post bernhard linked above. Maybe I'll try to get it out as (a bit more) polished module on the weekend. It's actually working great for me. 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...