123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- define('INSTALLDIR', dirname(__DIR__, 3));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $shortoptions = 'l::a::i';
- $longoptions = ['limit=', 'all', 'image'];
- $helptext = <<<END_OF_HELP
- remove_remote_media.php [options]
- Removes remote media. Thumbs will be removed as well.
- -l --limit [date] This is a timestamp, format is: yyyy-mm-dd (optional time hh:mm:ss may be provided)
- END_OF_HELP;
- require_once INSTALLDIR . '/scripts/commandline.inc';
- $quiet = have_option('q', 'quiet');
- if (!have_option('l', 'limit')) {
- echo "You must provide a limit!\n\n";
- show_help();
- exit(1);
- }
- $max_date = get_option_value('l', 'limit');
- if (empty($max_date)) {
- echo "Invalid empty limit!";
- exit(1);
- }
- $fn = new DB_DataObject();
- $fn->query(sprintf(
- <<<'END'
- SELECT file_to_post.file_id
- FROM file_to_post
- INNER JOIN file ON file_to_post.file_id = file.id
- INNER JOIN notice ON file_to_post.post_id = notice.id
- WHERE notice.is_local = 0 AND notice.modified <= '%1$s'
- GROUP BY file_to_post.file_id
- ORDER BY MAX(notice.modified)
- END,
- $fn->escape($max_date)
- ));
- while ($fn->fetch()) {
- $file = File::getByID($fn->file_id);
- $file_info_id = $file->getID();
- // Delete current file
- $file->delete();
- if (!$quiet) {
- echo "Deleted file with id: {$file_info_id}\n";
- }
- }
|