Jump to content

Cannot trash a page


Harmster
 Share

Recommended Posts

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 214

This 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...

Link to comment
Share on other sites

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)) ]

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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...