emApp, howto delete user with all his/her items?
chilll
![]()
Joined: 2006-05-23
Posts: 15 |
![]() |
Quote:
FAQ: What function (or API method) should I use if I want all user items to be deleted with user? Thanks, |
|
Oldiesmann
![]()
Joined: 2005-05-18
Posts: 151 |
![]() |
After calling GalleryEmbed::init, before you call GalleryEmbed::deleteUser(), use this code: list($ret, $user) = GalleryCoreApi::loadEntityByExternalId('user_id', 'GalleryUser'); GalleryEmbed::checkActiveUser('your_user_id'); GalleryCoreApi::deleteUserItems($user->getid());
'user_id' = ID of the user being deleted You can expand that to your liking (adding error handling, etc.). The Oldiesmann |
|
chilll
![]()
Joined: 2006-05-23
Posts: 15 |
![]() |
Hi again, Somewhy my code does not delete the user - can you tell me why? <?php error_reporting(E_ALL); ini_set('display_errors', 1); $conf['gallery2_embed_path'] = dirname(__FILE__).'/../g2/embed.php'; $conf['gallery2_uri'] = 'http://_g2/'; $conf['gallery2_embed_app_uri'] = 'http://_g2_myapi/entry.php'; $conf['gallery2_login_redirect'] = 'http://_emapp/'; $conf['gallery2_lang'] = 'en'; $conf['gallery2_active_user_name'] = 'admin'; $conf['gallery2_active_user_id'] = 6; require_once($conf['gallery2_embed_path']); $username = 'testxyz'; $ret = GalleryEmbed::init(array('g2Uri' => $conf['gallery2_uri'], 'embedUri' => $conf['gallery2_embed_app_uri'], 'loginRedirect' => $conf['gallery2_login_redirect'], 'activeUserId' => $conf['gallery2_active_user_name'])); list($ret, $user) = GalleryCoreApi::loadEntityByExternalId($username, 'GalleryUser'); GalleryEmbed::checkActiveUser($conf['gallery2_active_user_id']); GalleryCoreApi::deleteUserItems($user->getid()); GalleryEmbed::deleteUser($user->getid()); echo $user->getid(); // returns valid user id ?> Because $user->getid(); returns valid user id (number) that should be deleted, I suspect that the GalleryCoreApi::deleteUserItems($user->getid()); and GalleryEmbed::deleteUser($user->getid()); are not working. Or... do I have to execute or commit the changes somehow? Thanks, |
|
chilll
![]()
Joined: 2006-05-23
Posts: 15 |
![]() |
problem solved. |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
just FYI: the default policy of g2 is to reassign all items of the user to a new owner instead of deleting them. the admin UI of g2 allows to specify another new owner. it also allows to specify that all items should be deleted. so if you do an integration, decide what behavior you want and implement the code appropriately. be sure to communicate this to your users. |
|
chilll
![]()
Joined: 2006-05-23
Posts: 15 |
![]() |
Hi again, I don't fully understand how to deal with $ret errors? For example, the code below gives me PHP error: <?php // embed.php error_reporting(E_ALL); ini_set('display_errors', 1); $conf['gallery2_embed_path'] = dirname(__FILE__).'/../g2b/embed.php'; $conf['gallery2_uri'] = 'http://_g2/'; $conf['gallery2_embed_app_uri'] = 'http://_g2_myapi/entry.php'; $conf['gallery2_login_redirect'] = 'http://_emapp/'; $conf['gallery2_lang'] = 'en'; $conf['gallery2_active_user_name'] = 'admin'; $conf['gallery2_active_user_id'] = 6; require_once($conf['gallery2_embed_path']); $username = 'test'; $ret = GalleryEmbed::init(array('g2Uri' => $conf['gallery2_uri'], 'embedUri' => $conf['gallery2_embed_app_uri'], 'loginRedirect' => $conf['gallery2_login_redirect'], 'activeUserId' => $conf['gallery2_active_user_name'])); list ($ret, $value) = GalleryCoreApi::loadEntityByExternalId($username, 'GalleryUser'); if ($ret->isError()) { print $ret->getAsHtml(); } ?> Thanks, |
|
geddes
Joined: 2006-05-31
Posts: 7 |
![]() |
As far as I know (I am no expert) $ret is an instance of a gallery return object, which has a few methods, such as getAsHtml. One method it does not have is isError(). $ret itself acts as a sort of boolean, so all you need to do in your code is: if ($ret) print $ret->getAsHtml(); The return object will return true if there has been an error of some sort. Then you can deal with it. I've been subscribing to this thread because I have written a little script with this exact same functionality in my G2 integration. Here it is, perhaps it will be helpful: if($_POST['task']=='gogogoDelete') { if($_POST['reallyReally']!='true') print "<p>You didn't say 'really really' Press your back button and try again</p>"; else { // THE DELETION CODE //parse the accounts into an array $accountsToDelete = explode(',',$_POST['deletionBlock']); array_walk($accountsToDelete, 'trim_value'); for($x=0; $x < count($accountsToDelete); $x++) { print ("<p> Processing " . $accountsToDelete[$x] . "...<ul>"); list($ret, $user) = GalleryCoreApi::loadEntityByExternalId($accountsToDelete[$x], 'GalleryUser'); if ($ret && $ret->getErrorCode='ERROR_MISSING_OBJECT') { print('<li><em>FAILED:</em> Unknown User ID!</li></ul>'); } elseif($ret) { print('<li>real problem trying to find user</li></ul>'); print('<p>' . $ret->getAsHtml() . '</p>'); } else { //delete the stuff if neccessary if(isset($_POST['deleteStuff']) && $_POST['deleteStuff']=='true') { print('<li>Attempting to delete all photos and albums...'); $ret = GalleryCoreApi::deleteUserItems($user->getid()); if($ret) print('<em>FAILED</em><br> ' . $ret->getAsHtml() . '</li>'); else print('<u>success!</u></li>'); } //delete the accounts print('<li>Attempting to delete account...'); $ret = GalleryEmbed::deleteUser($accountsToDelete[$x]); if($ret) print(' <em>FAILED</em><br> ' . $ret->getAsHtml() . '</li>'); else print(' <u>success!</u></li>'); } print('</ul></p>'); } } } I have an administration script which has a couple text entries. The first is a big textarea that the admin is supposed to paste the account names into, seperated by commas (name=deletionBlock). Then there are two checkboxes, one that says "Really do this? This will DELETE THE USERS" (name="reallyReally") and another that says "Also delete user's items"(name="deleteStuff"). The script works like a charm, all that stuff really does get deleted. Good luck with your G2 integration, |
|
valiant
Joined: 2003-01-04
Posts: 32509 |
![]() |
$ret is null unless there was an error. |
|