Harmster Posted November 16, 2012 Posted November 16, 2012 Hey all, Can anyone clearify this error message for me? Fatal error: Exception: This page may not be placed in the trash (in xxx/xxx/wire/core/Pages.php line 779) #0 [internal function]: Pages->___trash(Object(NullPage)) #1 xxx/xxx/wire/core/Wire.php(271): call_user_func_array(Array, Array) #2 xxx/xxx/wire/core/Wire.php(229): Wire->runHooks('trash', Array) #3 xxx/xxxwire/core/Page.php(895): Wire->__call('trash', Array) #4 xxx/xxx/wire/core/Page.php(895): Pages->trash(Object(NullPage)) #5 xxx/xxx/site/modules/UsersGiveToAll.module(266): Page->trash() #6 xxx/xxx/site/templates/statistics/ajax_actions/users/user_status_inactive.php(8): UsersGiveToAll->activate_user(Object(User)) #7 /xxx/xxx in xxx/xxx/index.php on line 214This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. I run this code: public function activate_user($u) { if($u->id) { if($u->user_status = 'inactive') { $transaction = wire("pages")->get("template=transaction, users=$u, transaction_type=5"); $transaction->trash(); $u->user_status = ""; $u->save(); return true; } return false; } else { return false; } } I can't get clear WHAT is going wrong here...
nik Posted November 16, 2012 Posted November 16, 2012 That line (Pages.php:779) says: if(!$this->isDeleteable($page) || $page->template->noTrash) throw new WireException("This page may not be placed in the trash"); And isDeletable() if defined like this: public function isDeleteable(Page $page) { $deleteable = true; if(!$page->id || $page->status & Page::statusSystemID || $page->status & Page::statusSystem) $deleteable = false; else if($page instanceof NullPage) $deleteable = false; return $deleteable; } So, based on the above there are a few possibilities: $transaction is a NullPage object and/or hasn't got id defined: very likely, as this would be the case if no page was found when calling get() with that selector $transaction has status flag statusSystemID or statusSystem: very unlikely, but you'd probably know if such a flag had been set transaction template has noTrash property: possible, if you've checked it from Templates -> transaction -> System -> Disable Trash Option (System tab is shown only if you've got advanced=true in your config) I hope this helps. Edit: To sum it up, try wrapping that trash() call like this: if($transaction->id) { $transaction->trash(); } Edit 2: Sorry for confusing with all that stuff... Just noticed that trash() is being called with a NullPage object as an argument, so get() has definitely found no page. [ #0 [internal function]: Pages->___trash(Object(NullPage)) ] 1
interrobang Posted November 16, 2012 Posted November 16, 2012 This line looks wrong to me: if($u->user_status = 'inactive') shouldn't it be like this: if($u->user_status == 'inactive') 2
Harmster Posted November 16, 2012 Author Posted November 16, 2012 This line looks wrong to me: if($u->user_status = 'inactive') shouldn't it be like this: if($u->user_status == 'inactive') Ok i am going to cry in a cave somewhere... \\shame 1
nik Posted November 16, 2012 Posted November 16, 2012 @interrobang: that's probably the main reason (possibly get() and trash() aren't even supposed to be run there). Once again I dived too deep.
netcarver Posted November 17, 2012 Posted November 17, 2012 Hi Harm, try to develop the habit of always putting the constant first in statements like this... if('inactive' == $u->user_status) ... Then if you miss out an '=' sign PHP will shout at you about it. 7
Martijn Geerts Posted November 17, 2012 Posted November 17, 2012 @netcarver: didn't know that, tnx...
Adam Kiss Posted December 2, 2012 Posted December 2, 2012 try to develop the habit of always putting the constant first in statements like this... Yeah, but that will also make you like Yoda sound - "if inactive is user status" 1
Martijn Geerts Posted December 2, 2012 Posted December 2, 2012 Thank you Nik, the way of explaining things shows us a route to to handle error & stuff. It's very much appreciated . @adamkiss, ask WillyC if he likes the "Yoda sound".
WillyC Posted December 3, 2012 Posted December 3, 2012 [quotamos]Yeah well, Willy is… special. [/quotamos] [Y] / n 1
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