123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- $shortoptions = 'y';
- $longoptions = array('yes');
- $helptext = <<<END_OF_HELP
- clean_file_table.php [options]
- Deletes all local files where the filename cannot be found in the filesystem.
- -y --yes do not wait for confirmation
- Will print '.' for each file, except for deleted ones which are marked as 'x'.
- END_OF_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- if (!have_option('y', 'yes')) {
- print "About to delete local file entries where the file cannot be found. Are you sure? [y/N] ";
- $response = fgets(STDIN);
- if (strtolower(trim($response)) != 'y') {
- print "Aborting.\n";
- exit(0);
- }
- }
- print "Deleting";
- $file = new File();
- $file->whereAdd('filename IS NOT NULL');
- $file->whereAdd('filehash IS NULL', 'AND');
- if ($file->find()) {
- while ($file->fetch()) {
- try {
- $file->getPath();
- print '.';
- } catch (FileNotFoundException $e) {
- $file->delete();
- print 'x';
- }
- }
- }
- print "\nDONE.\n";
|