We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 3294d704 authored by mattl's avatar mattl

scripts/nukefile.php for blasting crap from the server

Deletes notices and the locally stored file based on File id, as
you may want to just get rid of shit sometimes.
parent f926e27a
...@@ -249,6 +249,15 @@ class File extends Managed_DataObject ...@@ -249,6 +249,15 @@ class File extends Managed_DataObject
return true; return true;
} }
public function getFilename()
if (!self::validFilename($this->filename)) {
// TRANS: Client exception thrown if a file upload does not have a valid name.
throw new ClientException(_("Invalid filename."));
return $this->filename;
// where should the file go? // where should the file go?
static function filename(Profile $profile, $origname, $mimetype) static function filename(Profile $profile, $origname, $mimetype)
...@@ -85,6 +85,24 @@ class File_to_post extends Managed_DataObject ...@@ -85,6 +85,24 @@ class File_to_post extends Managed_DataObject
} }
} }
static function getNoticeIDsByFile(File $file)
$f2p = new File_to_post();
$f2p->file_id = $file->id;
$ids = array();
if (!$f2p->find()) {
throw new NoResultException($f2p);
return $f2p->fetchAll('post_id');
function delete($useWhere=false) function delete($useWhere=false)
{ {
$f = File::getKV('id', $this->file_id); $f = File::getKV('id', $this->file_id);
#!/usr/bin/env php
* StatusNet - a distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$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).
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";
} else {
print "You must provide a file ID.\n";
$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) ({$file->id}). Are you sure? [y/N] ";
$response = fgets(STDIN);
if (strtolower(trim($response)) != 'y') {
print "Aborting.\n";
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");
} catch (NoResultException $e) {
print "No notices found with this File attached.\n";
print "Deleting File object together with possibly locally stored copy.\n";
print "DONE.\n";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment