Jump to content

Bootstrap and user generation


FuturShoc
 Share

Recommended Posts

$u = $users->get($username);
$users->delete($u);

I'm trying to delete users in a batch process as I perfect my import script. 

However, I'm getting this error on the above code.

Error Call to a member function get() on a non-object

Cany anyone see a reason this might fail?

Link to comment
Share on other sites

Ah, I see.

I've revised my code to this:

$u = wire('users')->get($username);
wire('users')->delete($u);

... and I get this:

Error Uncaught exception 'WireException' with message 'Unable to delete pages of type '''

Thoughts?

Link to comment
Share on other sites

Ok, it appears my problem was trying to delete a user that was already deleted.

See, I'm reading all this user data from a CSV file and I'm mapping various bits of text from each row to the different fields I've added to the user template. If I get the mapping wrong or I need to revise it, I needed some way to delete all of those users so I can retry the import again.

In the process of going back and forth, I got my unique usernames mixed up a bit (generated by concatenation of row data).

This fixed me up:

try 
{
$u = wire("users")->get($username);
        wire("users")->delete($u);
} catch (Exception $e)  {
	// fires when no user exists by that username				
}
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...