CC-2225 airtime-clean-storage doesnt work

Forced the user to run the script as superuser.
This commit is contained in:
Paul Baranowski 2011-04-25 18:34:03 -04:00
parent 78ed3e2822
commit 219598ac06
2 changed files with 15 additions and 6 deletions

View file

@ -1174,10 +1174,7 @@ class StoredFile {
return TRUE; return TRUE;
} }
else { else {
return PEAR::raiseError( return PEAR::raiseError("StoredFile::deleteFile: unlink failed ({$this->filepath})");
"StoredFile::deleteFile: unlink failed ({$this->filepath})",
GBERR_FILEIO
);
} }
} }
else { else {
@ -1237,7 +1234,10 @@ class StoredFile {
$files = StoredFile::getAll(); $files = StoredFile::getAll();
foreach ($files as $file) { foreach ($files as $file) {
$media = StoredFile::Recall($file["id"]); $media = StoredFile::Recall($file["id"]);
$media->delete(); $result = $media->delete();
if (PEAR::isError($result)) {
return $result;
}
} }
} }

View file

@ -59,7 +59,10 @@ function airtime_empty_db($db)
Playlist::deleteAll(); Playlist::deleteAll();
echo " * Clearing files table...".PHP_EOL; echo " * Clearing files table...".PHP_EOL;
StoredFile::deleteAll(); $result = StoredFile::deleteAll();
if (PEAR::isError($result)) {
echo $result->getMessage().PHP_EOL;
}
} }
@ -88,6 +91,12 @@ if (isset($opts->h)) {
exit; exit;
} }
// Need to check that we are superuser before running this.
if (exec("whoami") != "root") {
echo PHP_EOL."You must be root to use this script.".PHP_EOL.PHP_EOL;
exit(1);
}
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); $CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);