acf-agency-workflow
acf-agency-workflow copied to clipboard
Field Group gets deleted after manual editing
How to reproduce:
Create a FG. Open the JSON. Change the title. Change the modified timestamp to right now. (so it is newer and gets synced) Save. Load the dashboard or FG page.
poof
The JSON file is deleted.
Manually editing the JSON is not a primary feature but I think it should be possible. I assume it's also very similar to pulling in a changed JSON file from a coworker, which is a primary feature.
Side issue: Changing the timestamp by just 1 or a few digits doesn't trigger the sync.
It doesn't happen every time.
It happens every time if you don't skip step 1: Create a new FG.
The probably wrongful deletion gets triggered from within the hook on acf/update_field_group
where this check fails, even though its not an FGE location move.
// Skip everything if this is not a FGE location move.
if ( !isset( $field_group['json_save_path'] ) )
return $field_group;
Any plans on fixing this? Can we help anyhow? :)
Yeah it's gotta get fixed. It's just a pita to debug and no fun. 😄 I think I was getting close on sep 10th. I'll try to prioritize it.
Has it happened to you too or are you just afraid it might in the future?
Yeah, it's happening basically several times a week on a project where couple of us are working.
It's not the end of the world since we always catch it before we push, but yeah, not convenient.
I understand that this is neither commercial project nor it's super easy to debug, so no pressure 😄
I might have figured the exact case, let me know if this helps.
If the "modified" timestamp is in the future compared to the local time - the group is gone.
This can happen if the coworker and I do not have the local time/date in sync and I pull before the future arrives :)
It didn't help me, but that could also be my fault. I spent another couple of hours debugging this. The rabbit hole keeps going. I'm not sure I can nail this down.
For what it's worth, the things I've learned:
The aaw_delete_field_group_from_json()
inside the closure on acf/update_field_group
is to blame for the wrongful deletion, but if I disable it the sync msg keeps coming up and never finishes. I wrote this to achieve location moves (// Skip everything if this is not a FGE location move.
) but that's the least important right now.
When syncing JSON to the DB, the current timestamp gets written to the DB, but not to the JSON. So if we do $needs_update = ( json_date != db_date );
(pseudocode) that will trigger the sync, but it never stops. This does fix the weird behavior where bumping the timestamp by 1 to 50 is not enough to trigger a sync.
I've also tried starting over but I quickly got lost in internal functions. May try that again later. At this point studying the entire ACF PRO source code and writing a PR for the auto sync feature may be faster.
Is there any hack/workaround we could use?
Hey @Brugman - jfyi, in meantime ACF Extended plugin included really similar functionality with the plugin.
https://www.acf-extended.com/features/field-groups/force-sync
Thanks! Will check it out.