123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- $shortoptions = 'y';
- $longoptions = array('yes');
- $helptext = <<<END_OF_HELP
- clean_profiles.php [options]
- Deletes all profile table entries where the profile does not occur in the
- notice table, is not a group and is not a local user. Very MySQL specific I think.
- WARNING: This has not been tested thoroughly. Maybe we've missed a table to compare somewhere.
- -y --yes do not wait for confirmation
- END_OF_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- if (!have_option('y', 'yes')) {
- print "About to delete profiles that we think are useless to save. Are you sure? [y/N] ";
- $response = fgets(STDIN);
- if (strtolower(trim($response)) != 'y') {
- print "Aborting.\n";
- exit(0);
- }
- }
- print "Deleting";
- $profile = new Profile();
- $profile->query('SELECT * FROM profile WHERE ' .
- 'NOT (SELECT COUNT(*) FROM notice WHERE profile_id=profile.id) ' .
- 'AND NOT (SELECT COUNT(*) FROM user WHERE user.id=profile.id) ' .
- 'AND NOT (SELECT COUNT(*) FROM user_group WHERE user_group.profile_id=profile.id) ' .
- 'AND NOT (SELECT COUNT(*) FROM subscription WHERE subscriber=profile.id OR subscribed=profile.id) ');
- while ($profile->fetch()) {
- echo ' '.$profile->getID().':'.$profile->getNickname();
- $profile->delete();
- }
- print "\nDONE.\n";
|