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', realpath(dirname(__FILE__) . '/..'));
23 $shortoptions = 'i::yv';
24 $longoptions = array('id=', 'yes', 'verbose');
26 $helptext = <<<END_OF_HELP
27 nukefile.php [options]
28 deletes a file and related notices from the database
30 -i --id ID of the file
31 -v --verbose Be verbose (print the contents of the notices deleted).
35 require_once INSTALLDIR.'/scripts/commandline.inc';
37 if (have_option('i', 'id')) {
38 $id = get_option_value('i', 'id');
39 $file = File::getKV('id', $id);
40 if (!$file instanceof File) {
41 print "Can't find file with ID $id\n";
45 print "You must provide a file ID.\n";
49 $verbose = have_option('v', 'verbose');
51 if (!have_option('y', 'yes')) {
53 $filename = $file->getFilename();
54 } catch (Exception $e) {
55 $filename = '(remote file or no filename)';
57 print "About to PERMANENTLY delete file ($filename) with id=={$file->id}) AND its related notices. Are you sure? [y/N] ";
58 $response = fgets(STDIN);
59 if (strtolower(trim($response)) != 'y') {
65 print "Finding notices...\n";
67 $ids = File_to_post::getNoticeIDsByFile($file);
68 $notice = Notice::multiGet('id', $ids);
69 while ($notice->fetch()) {
70 print "Deleting notice {$notice->id}".($verbose ? ": $notice->content\n" : "\n");
73 } catch (NoResultException $e) {
74 print "No notices found with this File attached.\n";
76 print "Deleting File object together with possibly locally stored copy.\n";