Efficiently remove large number of users without albums

EricPeterson

Joined: 2006-02-21
Posts: 4
Posted: Fri, 2012-03-23 05:59

My site has accumulated a large number of user accounts that go nowhere (bots of course). These have failed to even create an initial album. Is there a way to delete these quickly and easily, yet at no risk to my real users?

I am no expert at website administration, but can roughly find my way around a database with command-line. Might this be the best way to go? Suggestions will be appreciated!

Thanks!

Gallery version (not just "2"): 2.3.1 core 1.3.0.1
PHP version (e.g. 5.1.6): 5.2
PHPInfo Link (see FAQ):
Webserver (e.g. Apache 1.3.33): Apache
Database (e.g. MySql 5.0.32): mysql 5.1
Activated toolkits (e.g. NetPbm, GD):
Operating system (e.g. Linux): linux
Browser (e.g. Firefox 2.0):

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Fri, 2012-03-23 12:46

create a file in your gallery2 directory "deleteUsers.php"
add the following:

<?php
require_once ('embed.php');
$ret = GalleryEmbed::init( array ('fullInit'=>'true'));
if ($ret) {
    print 'G2 init error: '.$ret->getAsHtml();
}

list ($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup($gallery->getActiveUserId());
if($ret OR !$isAdmin){
    die('You must be in the "Site Admin Group"');
}

$usersToDelete = array('tom', 'dick', 'harry');
foreach($usersToDelete as $username){
    list ($ret, $user) = GalleryCoreApi::fetchUserByUserName($username);
    if ($ret) {
        print('Error fetchUserByUserName: '.$username);
        continue;
    }
    $ret = GalleryCoreApi::deleteEntityById($user->getId(), 'GalleryUser');
    if ($ret) {
        print('Error deleteEntityById: '.$username);
        continue;
    }
}
GalleryEmbed::done();
die('Done!');

change the $usersToDelete array to the usernames you actually want to delete.
visit this page w/ your browser once - you must be logged in as an admin to perform this operation.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
EricPeterson

Joined: 2006-02-21
Posts: 4
Posted: Mon, 2012-03-26 00:43

Hmmm... I seem to be getting no response - just a blank page - not even an error. Maybe something about the api commands isn't working with my install(?)

Is there any reason I should not just get into mysql and do a DELETE FROM LP_g2_User ?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2012-03-26 01:19

embed.php is in the same directory?
you changed $usersToDelete = array('tom', 'dick', 'harry'); to contain some of your actual users?

Quote:
Is there any reason I should not just get into mysql and do a DELETE FROM LP_g2_User ?

do not do that.
When gallery creates an Entity it has many entries in many tables.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2