#CC-1573 CleanStor script added to storage server to clean broken links or purge all files.
This commit is contained in:
parent
2ffe3b0a46
commit
a16e3daa11
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010 Sourcefabric O.P.S.
|
||||||
|
#
|
||||||
|
# This file is part of the Campcaster project.
|
||||||
|
# http://campcaster.sourcefabric.org/
|
||||||
|
#
|
||||||
|
# Campcaster is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Campcaster is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Campcaster; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# This script cleans audio files in the Campcaster storageServer.
|
||||||
|
|
||||||
|
reldir=`dirname $0`/..
|
||||||
|
cd $reldir/var
|
||||||
|
|
||||||
|
php -q CleanStor.php "$@" || exit 1
|
|
@ -0,0 +1,128 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('conf.php');
|
||||||
|
require_once('DB.php');
|
||||||
|
require_once('install/installInit.php');
|
||||||
|
require_once ('StoredFile.php');
|
||||||
|
|
||||||
|
function printUsage() {
|
||||||
|
|
||||||
|
global $CC_CONFIG;
|
||||||
|
|
||||||
|
echo "Usage:\n";
|
||||||
|
echo " ./CleanStor [OPTION] \n";
|
||||||
|
echo "\n";
|
||||||
|
echo "Options:\n";
|
||||||
|
echo " -c, --clean Removes all broken links from the storage server\n";
|
||||||
|
echo " and empties all missing file information from the database.\n";
|
||||||
|
echo "\n";
|
||||||
|
echo " -e, --empty Removes all files from the storage server \n";
|
||||||
|
echo " and empties all relevant information from the database.\n\n";
|
||||||
|
echo "Storage server: ". $CC_CONFIG["storageDir"] ."\n\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
function camp_clean_files($p_path) {
|
||||||
|
if (!empty($p_path) && (strlen($p_path) > 4)) {
|
||||||
|
list($dirList,$fileList) = File_Find::maptree($p_path);
|
||||||
|
|
||||||
|
$array_mus;
|
||||||
|
foreach ($fileList as $filepath) {
|
||||||
|
|
||||||
|
if (@substr($filepath, strlen($filepath) - 3) != "xml") {
|
||||||
|
$array_mus[] = $filepath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($array_mus as $audio_file) {
|
||||||
|
|
||||||
|
if (@is_link($audio_file) && !@stat($audio_file)) {
|
||||||
|
|
||||||
|
//filesystem clean up.
|
||||||
|
@unlink($audio_file);
|
||||||
|
echo "unlinked $audio_file\n";
|
||||||
|
@unlink($audio_file . ".xml");
|
||||||
|
echo "unlinked " . $audio_file . ".xml\n";
|
||||||
|
@rmdir(@dirname($audio_file));
|
||||||
|
echo "removed dir " . @dirname($audio_file) . "\n";
|
||||||
|
|
||||||
|
//database clean up.
|
||||||
|
$stored_audio_file = StoredFile::RecallByGunid(@basename($audio_file));
|
||||||
|
$stored_audio_file->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function camp_remove_files($p_path) {
|
||||||
|
|
||||||
|
if (!empty($p_path) && (strlen($p_path) > 4)) {
|
||||||
|
list($dirList,$fileList) = File_Find::maptree($p_path);
|
||||||
|
|
||||||
|
foreach ($fileList as $filepath) {
|
||||||
|
echo " * Removing $filepath\n";
|
||||||
|
@unlink($filepath);
|
||||||
|
echo "done.\n";
|
||||||
|
}
|
||||||
|
foreach ($dirList as $dirpath) {
|
||||||
|
echo " * Removing $dirpath\n";
|
||||||
|
@rmdir($dirpath);
|
||||||
|
echo "done.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function camp_empty_db($db) {
|
||||||
|
global $CC_CONFIG;
|
||||||
|
|
||||||
|
if (!PEAR::isError($db)) {
|
||||||
|
if (camp_db_table_exists($CC_CONFIG['filesTable'])) {
|
||||||
|
echo " * Deleting from database table ".$CC_CONFIG['filesTable']."\n";
|
||||||
|
$sql = "DELETE FROM ".$CC_CONFIG['filesTable'];
|
||||||
|
camp_install_query($sql, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo " * Skipping: database table ".$CC_CONFIG['prefTable']."\n";
|
||||||
|
}
|
||||||
|
if (camp_db_table_exists($CC_CONFIG['treeTable'])) {
|
||||||
|
echo " * Deleting from database table ".$CC_CONFIG['treeTable']."\n";
|
||||||
|
$sql = "DELETE FROM ".$CC_CONFIG['treeTable'];
|
||||||
|
camp_install_query($sql, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo " * Skipping: database table ".$CC_CONFIG['treeTable']."\n";
|
||||||
|
}
|
||||||
|
if (camp_db_table_exists($CC_CONFIG['mdataTable'])) {
|
||||||
|
echo " * Deleting from database table ".$CC_CONFIG['mdataTable']."\n";
|
||||||
|
$sql = "DELETE FROM ".$CC_CONFIG['mdataTable'];
|
||||||
|
camp_install_query($sql, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo " * Skipping: database table ".$CC_CONFIG['mdataTable']."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
global $CC_CONFIG;
|
||||||
|
|
||||||
|
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
|
||||||
|
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||||
|
|
||||||
|
switch($argv[1]){
|
||||||
|
|
||||||
|
case '-e':
|
||||||
|
case '--empty':
|
||||||
|
camp_empty_db($CC_DBC);
|
||||||
|
camp_remove_files($CC_CONFIG['storageDir']);
|
||||||
|
break;
|
||||||
|
case '-c':
|
||||||
|
case '--clean':
|
||||||
|
camp_clean_files($CC_CONFIG['storageDir']);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printUsage();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue