4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
24 $shortoptions = 'i::yv';
25 $longoptions = array('id=', 'yes', 'verbose');
27 $helptext = <<<END_OF_HELP
28 nukefile.php [options]
29 deletes a file and related notices from the database
31 -i --id ID of the file
32 -v --verbose Be verbose (print the contents of the notices deleted).
36 require_once INSTALLDIR.'/scripts/commandline.inc';
38 if (have_option('i', 'id')) {
39 $id = get_option_value('i', 'id');
40 $file = File::getKV('id', $id);
41 if (!$file instanceof File) {
42 print "Can't find file with ID $id\n";
46 print "You must provide a file ID.\n";
50 $verbose = have_option('v', 'verbose');
52 if (!have_option('y', 'yes')) {
54 $filename = $file->getFilename();
55 } catch (Exception $e) {
56 $filename = '(remote file or no filename)';
58 print "About to PERMANENTLY delete file ($filename) with id=={$file->id}) AND its related notices. Are you sure? [y/N] ";
59 $response = fgets(STDIN);
60 if (strtolower(trim($response)) != 'y') {
66 print "Finding notices...\n";
68 $ids = File_to_post::getNoticeIDsByFile($file);
69 $notice = Notice::multiGet('id', $ids);
70 while ($notice->fetch()) {
71 print "Deleting notice {$notice->id}".($verbose ? ": $notice->content\n" : "\n");
74 } catch (NoResultException $e) {
75 print "No notices found with this File attached.\n";
77 print "Deleting File object together with possibly locally stored copy.\n";