a-ok Posted July 25, 2019 Share Posted July 25, 2019 Does anyone know why the following doesn't work? The page would be called via a cronjob... if ($input->get->run) { // Reset submissions if ($input->get->run == "resetSubmissions") { $submissions = $pages->get("template=home")->submissions; $submissions->of(false); $submissions->removeAll(); $submissions->save(); bdb('resetSubmissions has been run'); } } Link to comment Share on other sites More sharing options...
dragan Posted July 25, 2019 Share Posted July 25, 2019 Well, does it work if you run it normally (not as cron job)? Do you get errors? What are the permissions of the page this runs in? Link to comment Share on other sites More sharing options...
a-ok Posted July 25, 2019 Author Share Posted July 25, 2019 3 minutes ago, dragan said: Well, does it work if you run it normally (not as cron job)? Do you get errors? What are the permissions of the page this runs in? No, sorry. I haven't set up the cronjob yet... just testing the code. It returns: Exception: Method RepeaterPageArray::of does not exist or is not callable in this context Link to comment Share on other sites More sharing options...
dragan Posted July 25, 2019 Share Posted July 25, 2019 Well, then just remove that line. If you're deleting, it makes no sense anyway. Link to comment Share on other sites More sharing options...
a-ok Posted July 25, 2019 Author Share Posted July 25, 2019 15 minutes ago, dragan said: Well, then just remove that line. If you're deleting, it makes no sense anyway. Sorry, I'm confused. I'd like to remove all rows but keep the repeater. Upon removing the ->of(false) it still doesn't delete all the rows. Link to comment Share on other sites More sharing options...
elabx Posted July 25, 2019 Share Posted July 25, 2019 I wonder if you should rather, delete() every page also, not use removeAll() because I think it's just removing it from the object, not from the db. foreach($pages->get("template=home")->submissions as $s){ $s->delete(); } 1 Link to comment Share on other sites More sharing options...
a-ok Posted July 25, 2019 Author Share Posted July 25, 2019 3 minutes ago, elabx said: I wonder if you should rather, delete() every page also, not use removeAll() because I think it's just removing it from the object, not from the db. foreach($pages->get("template=home")->submissions as $s){ $s->delete(); } Thanks. This doesn't seem to work either, weirdly. $submissions = $pages->get("template=home")->submissions; foreach($submissions as $s) { $s->delete(); } $submissions->save(); Link to comment Share on other sites More sharing options...
a-ok Posted July 25, 2019 Author Share Posted July 25, 2019 $submissions = $pages->get("template=home")->submissions; foreach ($submissions as $s) { $s->delete(); $s->save(); } $pages->get("template=home")->save(); This worked! But so many saves? I never know. Link to comment Share on other sites More sharing options...
Robin S Posted July 25, 2019 Share Posted July 25, 2019 5 hours ago, a-ok said: $submissions->of(false); of() is a method of Page objects, but you're trying to use it on an PageArray of Repeater pages. Try: // Get the page you want to work with $home = $pages->get("template=home"); // Turn output formatting off for the page $home->of(false); // Change the Repeater field value $home->submissions->removeAll(); // Save the page $home->save(); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now