acf-agency-workflow icon indicating copy to clipboard operation
acf-agency-workflow copied to clipboard

Field Group gets deleted after manual editing

Open Brugman opened this issue 4 years ago • 11 comments

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

screenshot

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.

Brugman avatar Sep 10 '20 15:09 Brugman

Side issue: Changing the timestamp by just 1 or a few digits doesn't trigger the sync.

Brugman avatar Sep 10 '20 15:09 Brugman

It doesn't happen every time.

Brugman avatar Sep 10 '20 17:09 Brugman

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;

Brugman avatar Sep 10 '20 17:09 Brugman

Any plans on fixing this? Can we help anyhow? :)

ermincelikovic avatar Sep 30 '20 16:09 ermincelikovic

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?

Brugman avatar Sep 30 '20 19:09 Brugman

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 😄

ermincelikovic avatar Oct 01 '20 06:10 ermincelikovic

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 :)

ermincelikovic avatar Oct 11 '20 15:10 ermincelikovic

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.

Brugman avatar Oct 14 '20 16:10 Brugman

Is there any hack/workaround we could use?

ermincelikovic avatar Oct 18 '20 08:10 ermincelikovic

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

ermincelikovic avatar May 09 '21 18:05 ermincelikovic

Thanks! Will check it out.

Brugman avatar May 09 '21 18:05 Brugman