trilbymedia / grav-plugin-git-sync

Collaboratively Synchronize your Grav `user` folder hosted on GitHub, BitBucket or GitLab
Apache License 2.0
245 stars 57 forks source link

Auto sync with custom folder (generated by BlackHole plugin) [Question] #201

Closed rkyoku closed 3 years ago

rkyoku commented 3 years ago

Hi!

Is it possible for the plugin to auto-sync every time one of the (custom) folders was modified?

My current setup (new to Grav, please forgive any dumb question/setup):

But it does not sync automatically.

I guess it would need some Node app with a file watcher plugin of some sort?

Do you reckon it is feasible, or maybe it would be easier to hook into the Blackhole plugin to trigger the sync? (or ask the Blackhole plugin to offer some setting to intertwine nicely with Git-Sync plugin?)

Worst case, I will hard-code this call myself in the Blackhole plugin, but it is not clean...

Thanks for any advice!

Best,

w00fz commented 3 years ago

Both your approaches would work well.

  1. You could setup a cronjob on your machine (or via Grav Scheduler) that runs the sync command every X minutes, that way it's not really triggered but it is automated and happens frequently. If there are changes they are synched, if there aren't it skips
  2. GitSync comes with a built-in trigger event gitsync, that actually Flex Objects uses, too. This same idea could be used by the BlackHole plugin, however this is something the developer would have to implement in the plugin. I would open a ticket there and ask for it, it could be quite useful to trigger the sync after generate, 2 birds 1 stone. Here is how Flex Objects does it for every CRUD task (https://github.com/trilbymedia/grav-plugin-flex-objects/blob/develop/classes/Controllers/ObjectController.php#L133)

Hope this helps!

rkyoku commented 3 years ago

Thank you @w00fz for the idea!

I added your link to my feature request to BlackHole, hoping they will give a positive response to it.

Meanwhile, I will probably use the Scheduler that you kindly advised to me (that I didn't know about, I am 100% new to Grav, I am not used to CMS in general, and Grav in particular)

As for auto-sync everytime a custom folder is modified (can be helpful for the Flex Objects you talked about), I guess it is replaced by the cron job, then?

I did not find how to set "every five minutes" in the configuration page, but, well, "every 1 minute" would be fine too I guess :)

I let the contributors decide whether to close this feature request if they reckon the "Scheduler" is close enough to a "File Watch", it is fine by me!

Thanks again @w00fz !

w00fz commented 3 years ago

Yes scheduler is the closest thing you can do since there isn't really a way to listen to folder changes in Grav/GitSync. A true file watch would require you to create the logic at the server level but at that point it would definitely be outside the Grav/GitSync scope.