abmcr Posted October 13, 2021 Posted October 13, 2021 public static function delete () { $response = [ 'data' => [] ]; $id = wire('input')->get('id'); $page = wire("pages")->get($id)->children(); foreach ($page as $child) { $child->delete(); } $page = wire("pages")->get($id); $page->delete(); $return = true; $response = [ 'esito' => $return, ]; } Via API i want t delete a page and his children ; the code delete only the children because after i get this error "devmessage": { "class": "ProcessWire\\WireException", "code": 0, "message": "Can't delete Page 1345 because it has one or more children.", If i recall the same route (example: https://www.sampleweb.com/api/delete?id=1345) a second time the page parent is correctly deleted But there is a way for call once the route? Thank you
zoeck Posted October 13, 2021 Posted October 13, 2021 You can use RockMigrations for such tasks ? It's a very Powerful Module Or just look at the docs ? https://processwire.com/api/ref/page/delete/ // Delete a page and recursively all of its children, grandchildren, etc. $item = $pages->get('/some-page/'); $item->delete(true); It looks like the "true" is missing: $item->delete(true); "If set to true, then this will attempt to delete all children too." 2
abmcr Posted October 13, 2021 Author Posted October 13, 2021 thank you... RockMigrations very useful module...
bernhard Posted October 14, 2021 Posted October 14, 2021 This is how RockMigrations does it: https://github.com/BernhardBaumrock/RockMigrations/blob/4f4805a3d27c64246cd15a94a16ef27a98f12ec4/RockMigrations.module.php#L1656-L1687
abmcr Posted October 14, 2021 Author Posted October 14, 2021 1 minute ago, bernhard said: This is how RockMigrations does it: https://github.com/BernhardBaumrock/RockMigrations/blob/4f4805a3d27c64246cd15a94a16ef27a98f12ec4/RockMigrations.module.php#L1656-L1687 Thank you
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