12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $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";
|