FuturShoc Posted February 3, 2013 Share Posted February 3, 2013 $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 More sharing options...
Soma Posted February 3, 2013 Share Posted February 3, 2013 You have to use wire in bootstrap. wire('users')->get(). Link to comment Share on other sites More sharing options...
apeisa Posted February 3, 2013 Share Posted February 3, 2013 wire("users") instead of $users when bootstrapping. Link to comment Share on other sites More sharing options...
Soma Posted February 3, 2013 Share Posted February 3, 2013 Was that an echo? 1 Link to comment Share on other sites More sharing options...
apeisa Posted February 3, 2013 Share Posted February 3, 2013 No comments. Link to comment Share on other sites More sharing options...
FuturShoc Posted February 3, 2013 Author Share Posted February 3, 2013 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 More sharing options...
FuturShoc Posted February 3, 2013 Author Share Posted February 3, 2013 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 More sharing options...
apeisa Posted February 3, 2013 Share Posted February 3, 2013 You can also do this: $users = wire("users"); $u = $users->get($username); if($u->id) $users->delete($u); 1 Link to comment Share on other sites More sharing options...
FuturShoc Posted February 3, 2013 Author Share Posted February 3, 2013 You can also do this: $users = wire("users"); $u = $users->get($username); if($u->id) $users->delete($u); Ah, yes. Definitely a cleaner soluton. Thanks, apeisa. 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