1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $shortoptions = 'i::yv';
- $longoptions = array('id=', 'yes', 'verbose');
- $helptext = <<<END_OF_HELP
- nukefile.php [options]
- deletes a file and related notices from the database
- -i --id ID of the file
- -v --verbose Be verbose (print the contents of the notices deleted).
- END_OF_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- if (have_option('i', 'id')) {
- $id = get_option_value('i', 'id');
- $file = File::getKV('id', $id);
- if (!$file instanceof File) {
- print "Can't find file with ID $id\n";
- exit(1);
- }
- } else {
- print "You must provide a file ID.\n";
- exit(1);
- }
- $verbose = have_option('v', 'verbose');
- if (!have_option('y', 'yes')) {
- try {
- $filename = $file->getFilename();
- } catch (Exception $e) {
- $filename = '(remote file or no filename)';
- }
- print "About to PERMANENTLY delete file ($filename) with id=={$file->id}) AND its related notices. Are you sure? [y/N] ";
- $response = fgets(STDIN);
- if (strtolower(trim($response)) != 'y') {
- print "Aborting.\n";
- exit(0);
- }
- }
- print "Finding notices...\n";
- try {
- $ids = File_to_post::getNoticeIDsByFile($file);
- $notice = Notice::multiGet('id', $ids);
- while ($notice->fetch()) {
- print "Deleting notice {$notice->id}".($verbose ? ": $notice->content\n" : "\n");
- $notice->delete();
- }
- } catch (NoResultException $e) {
- print "No notices found with this File attached.\n";
- }
- print "Deleting File object together with possibly locally stored copy.\n";
- $file->delete();
- print "DONE.\n";
|