Jump to content

[SOLVED-ish] Saving the homepage from guest session removes image references


monollonom
 Share

Recommended Posts

(I edited the title to reflect my findings down below, I'm leaving the original post as is though)

Hi,

This is the first time I'm using LazyCron so maybe I did something wrong but basically when the hook function is triggered and does its thing to the homepage, all images within that page disappear from the database, while remaining in the file system. When I try to re-upload the same image it tells me "Refused file X because it is already on the file system and owned by a different field" (couldn't find that other field though). Has anybody encountered something like this before ?

Here is my hook, from ready.php:

$wire->addHook("LazyCron::everyHour", function() {
	$home = wire("pages")->get(1);
	$home->of(false);
	$nextMonth = strtotime("next month");
	$newEvents = wire("pages")->find("template=event, end_date>=today, start_date<$nextMonth, limit=10, sort=start_date, sort=end_date, sort=title");
	foreach($home->events as $event) {
		if (!$newEvents->has($event)) {
			$home->events->remove($event);
		}
	}
	foreach($newEvents as $new) {
		if (!$home->events->has($new)) {
			$home->events->add($new);
		}
	}
	$home->save();
});

$home->events is a Page Reference field. The idea is to update the field with the ten closest events and allow the editor to sort them in the admin.

Thank you !

Edited by monollonom
Changed title of the topic
Link to comment
Share on other sites

Yes at first I did set the output formatting to "false" but wanted to try and see how it goes without it, with no luck. I'll edit my post though, thanks.

(also for completeness, I'll try again with of(false) just to be 100% sure)

Link to comment
Share on other sites

After some more testing, it looks like it's not because of the hook or the LazyCron but because of the code being executed by a guest.

Edit: it's actually just the fact that I save the homepage (from a guest session) that makes the images disappear.

I have access control toggled on for the homepage template but I thought API calls would be respected, am I wrong ?

Edited by monollonom
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...