I’m trying to programmatically create or, if already there, update pages that also contains media and is referenced from within the page through a files field.
Simplified code:
$kirby->impersonate('kirby');
// CHECK UP FRONT IF PAGE EXISTS
$newPage = $page->createChild($slug, $template, $data);
// OR
$newPage = $page->update( $data );
// CHECK UP FRONT IF FILE EXISTS, OTHERWISE
$file = $newPage->createFile($source, $filename, $template, $content);
$newPage->update([ 'files_field' => $file ]);
So basically there are three scenarios: a brand new page with a brand new file, an updated page with a brand new file and an updated page that already has that particular file.
However, only in the latter scenario I can reference the file in the files field of that page. Whenever I create a new file I can’t immediately reference it in the files field, no matter if it’s a new page or an updated one. I can only assume that the page object is kinda cached, since creating a new page object from that same page immediately after the upload yields the same result.
I’m a little bit at a loss here, maybe someone knows the solution to my problem?
Wondering that this works at all, because createFile expects an array. Same for createChild() above. Did you post your actual code or just something made up? Also, the files_field expects yaml encode file id(s), not a file object.
Thanks for your help! It seems like the issue is related to the AutoID plugin, as soon as I delete the plugin everything works as expected. I’ll contact the developer / open an issue on his Github.