123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $shortoptions = 'y';
- $longoptions = ['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.
- 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);
- }
- }
- echo 'Deleting';
- $user_table = common_database_tablename('user');
- $profile = new Profile();
- $profile->query(
- <<<END
- SELECT profile.*
- FROM profile
- LEFT JOIN (
- SELECT profile_id AS id FROM notice
- UNION ALL
- SELECT id FROM {$user_table}
- UNION ALL
- SELECT profile_id AS id FROM user_group
- UNION ALL
- SELECT subscriber FROM subscription
- UNION ALL
- SELECT subscribed FROM subscription
- ) AS t1 USING (id)
- WHERE t1.id IS NULL
- END
- );
- while ($profile->fetch()) {
- echo ' '.$profile->getID().':'.$profile->getNickname();
- $profile->delete();
- }
- print "\nDONE.\n";
|