Resources disappearing then re-appearing under a new parent

Summary

I’ve recently taken over a website built by another dev team. It has a library of documents (Static Resources) and separately a news page.

The articles on the news page are imported into the website from a third-party API using a snippet that runs on a cronjob.

Something seems to be causing some of (not all) the static resources to jump into this news page parent.

I’ve installed VersionX to gain a better insight into the history of these resources, but until it happens to a resource created after this install I don’t have the data.

I understand without the scripts it is challenging to diagnose. I was enquiring mainly if anyone had any advice on how I should go about diagnosing the problem.

There is some lines in the script that refresh the URI’s. Which to me feels like it could be related.

I think the only solution that may be available is to rewrite the import scripts for the news articles.

Step to reproduce

I can’t provide these in this case.

Observed behavior

As mentioned above, some of the static resource’s parent is being changed.

Expected behavior

They should stay in place.

Environment

Modx 2.8.4, on the new Modx cloud.

Hi @carlpiper

Have you managed to confirm that the cronjob snippet is not responsible?

If so, you could check for any custom plugins in case there’s something in there that could be changing resource parents.

The only way that could happen is if something is changing the parent field in the modx_site_content table. Maybe the cronjob snippet is calling set('parent', $someValue); with a wrong value, or not setting the parent field, but using fromArray() to set the fields using an array that holds an old value for the parent field.

Another thing to consider is that resources at the root of the tree have 0 in their parent field. Maybe the code is using some default if the parent field is empty.

Thank you @dejaya and @bobray for your replies.

I’m going to take a look into both of your responses and see if I can spot anything.

Will VersionX display changes to resources made via the API?

I think VersionX will only save a new version of a resource OnDocFormSave - that is, when the resource is saved via the Manager.

If the resource’s parent is being changed by your snippet or by a custom plugin - I don’t think VersionX will reflect that change by saving a version.

I guess your cronjob snippet remains the prime suspect! I take it you can’t share your code?

Unfortunately I can’t but i’m almost certain it’s related.

I will re-read through all the files and double confirm

A bit of a long shot, but might the CRON job be interacting with the ImportX snippet? This does have an option to set a default parent on import. https://docs.modx.com/current/en/extras/importx