-removed airtime-clean-storage.php + airtime-import.php
-default created stor dir now has www-data:www-data permission -created airtime-install.ini file for specifying install defaults -removed all references to storDir in /etc/airtime/airtime.conf, and get value from database instead.
This commit is contained in:
parent
2659932cfb
commit
2c4e2afb8b
|
@ -67,9 +67,7 @@ class Config {
|
|||
$CC_CONFIG['basePort'] = $values['general']['base_port'];
|
||||
|
||||
$CC_CONFIG['baseFilesDir'] = $values['general']['base_files_dir'];
|
||||
// main directory for storing binary media files
|
||||
$CC_CONFIG['storageDir'] = $values['general']['base_files_dir']."/stor";
|
||||
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
|
|
|
@ -408,8 +408,8 @@ class ApiController extends Zend_Controller_Action
|
|||
print 'You are not allowed to access this resource.';
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->view->stor = $CC_CONFIG['storageDir'];
|
||||
|
||||
$this->view->stor = MusicDir::getStorDir()->getDirectory();
|
||||
}
|
||||
|
||||
public function reloadMetadataAction() {
|
||||
|
|
|
@ -336,9 +336,11 @@ class StoredFile {
|
|||
if (Schedule::IsFileScheduledInTheFuture($this->getId())) {
|
||||
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
|
||||
}
|
||||
|
||||
$storageDir = MusicDir::getStorDir()->getDirectory();
|
||||
|
||||
// Only delete the file from filesystem if it has been copied to the storage directory
|
||||
if (substr($this->getFilePath(), 0, strlen($CC_CONFIG["storageDir"])) == $CC_CONFIG["storageDir"]) {
|
||||
if (substr($this->getFilePath(), 0, strlen($storageDir) == $storageDir)) {
|
||||
// Delete the file
|
||||
$res = unlink($this->getFilePath());
|
||||
if (!$res) {
|
||||
|
|
|
@ -20,6 +20,8 @@ if (!function_exists('pg_connect')) {
|
|||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
/* This class deals with the config files stored in /etc/airtime */
|
||||
class AirtimeIni
|
||||
{
|
||||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
|
|
|
@ -117,12 +117,18 @@ class AirtimeInstall
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* TODO: This function should be moved to the media-monitor
|
||||
* install script. */
|
||||
public static function InstallStorageDirectory()
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
echo "* Storage directory setup".PHP_EOL;
|
||||
|
||||
$dirs = array($CC_CONFIG['storageDir'], $CC_CONFIG['storageDir']."/organize");
|
||||
$ini = parse_ini_file(__DIR__."/airtime-install.ini");
|
||||
$stor_dir = $ini["storage_dir"];
|
||||
|
||||
$dirs = array($stor_dir, $stor_dir."/organize");
|
||||
|
||||
foreach ($dirs as $dir){
|
||||
if (!file_exists($dir)) {
|
||||
|
@ -150,9 +156,6 @@ class AirtimeInstall
|
|||
$success = chown($rp, "pypo");
|
||||
$success = chmod($rp, 02777);
|
||||
}
|
||||
|
||||
//July 5th, 2011: Why is this here - MK?????
|
||||
//$CC_CONFIG['storageDir'] = $rp;
|
||||
}
|
||||
|
||||
public static function CreateDatabaseUser()
|
||||
|
@ -310,10 +313,6 @@ class AirtimeInstall
|
|||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-import";
|
||||
exec("ln -s $dir /usr/bin/airtime-import");
|
||||
|
||||
echo "* Installing airtime-clean-storage".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-clean-storage";
|
||||
exec("ln -s $dir /usr/bin/airtime-clean-storage");
|
||||
|
||||
echo "* Installing airtime-update-db-settings".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-update-db-settings";
|
||||
exec("ln -s $dir /usr/bin/airtime-update-db-settings");
|
||||
|
@ -326,7 +325,6 @@ class AirtimeInstall
|
|||
public static function RemoveSymlinks()
|
||||
{
|
||||
exec("rm -f /usr/bin/airtime-import");
|
||||
exec("rm -f /usr/bin/airtime-clean-storage");
|
||||
exec("rm -f /usr/bin/airtime-update-db-settings");
|
||||
exec("rm -f /usr/bin/airtime-check-system");
|
||||
}
|
||||
|
|
|
@ -50,8 +50,11 @@ AirtimeInstall::SetAirtimeVersion(AIRTIME_VERSION);
|
|||
AirtimeInstall::SetUniqueId();
|
||||
|
||||
if (AirtimeInstall::$databaseTablesCreated) {
|
||||
echo "* Inserting stor directory into music_dirs table".PHP_EOL;
|
||||
$stor_dir = realpath($CC_CONFIG['storageDir']);
|
||||
|
||||
$ini = parse_ini_file(__DIR__."/airtime-install.ini");
|
||||
|
||||
$stor_dir = $ini["storage_dir"];
|
||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
storage_dir = /srv/airtime/stor
|
|
@ -92,8 +92,6 @@ function LoadConfig($CC_CONFIG) {
|
|||
//$CC_CONFIG['basePort'] = $values['general']['base_port'];
|
||||
|
||||
$CC_CONFIG['baseFilesDir'] = $values['general']['base_files_dir'];
|
||||
// main directory for storing binary media files
|
||||
$CC_CONFIG['storageDir'] = $values['general']['base_files_dir']."/stor";
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
|
|
|
@ -92,8 +92,6 @@ function LoadConfig($CC_CONFIG) {
|
|||
$CC_CONFIG['basePort'] = $values['general']['base_port'];
|
||||
|
||||
$CC_CONFIG['baseFilesDir'] = $values['general']['base_files_dir'];
|
||||
// main directory for storing binary media files
|
||||
$CC_CONFIG['storageDir'] = $values['general']['base_files_dir']."/stor";
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
|
|
|
@ -66,5 +66,5 @@ $CC_CONFIG = Config::loadConfig($CC_CONFIG);
|
|||
|
||||
echo "* Creating default storage directory".PHP_EOL;
|
||||
AirtimeInstall::InstallStorageDirectory();
|
||||
AirtimeInstall::ChangeDirOwnerToWebserver($CC_CONFIG["storageDir"]);
|
||||
AirtimeInstall::ChangeDirOwnerToWebserver($CC_CONFIG['baseFilesDir']."/stor");
|
||||
AirtimeInstall::CreateSymlinksToUtils();
|
||||
|
|
|
@ -104,7 +104,7 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
try:
|
||||
omask = os.umask(0)
|
||||
|
||||
uid = pwd.getpwnam('pypo')[2]
|
||||
uid = pwd.getpwnam('www-data')[2]
|
||||
gid = grp.getgrnam('www-data')[2]
|
||||
|
||||
os.chown(item, uid, gid)
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2010 Sourcefabric O.P.S.
|
||||
#
|
||||
# This file is part of the Airtime project.
|
||||
# http://airtime.sourcefabric.org/
|
||||
#
|
||||
# Airtime 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.
|
||||
#
|
||||
# Airtime 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 Airtime; 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 Airtime.
|
||||
#
|
||||
# Absolute path to this script
|
||||
SCRIPT=`readlink -f $0`
|
||||
# Absolute directory this script is in
|
||||
SCRIPTPATH=`dirname $SCRIPT`
|
||||
|
||||
invokePwd=$PWD
|
||||
cd $SCRIPTPATH
|
||||
|
||||
php -q airtime-clean-storage.php "$@" || exit 1
|
|
@ -1,132 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Do not allow remote execution
|
||||
$arr = array_diff_assoc($_SERVER, $_ENV);
|
||||
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
||||
header("HTTP/1.1 400");
|
||||
header("Content-type: text/plain; charset=UTF-8");
|
||||
echo "400 Not executable\r\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$ini = get_ini_file();
|
||||
$airtime_base_dir = $ini['general']['airtime_dir'];
|
||||
|
||||
set_include_path("$airtime_base_dir/library" . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path("$airtime_base_dir/application/models" . PATH_SEPARATOR . get_include_path());
|
||||
require_once("$airtime_base_dir/application/configs/conf.php");
|
||||
require_once('StoredFile.php');
|
||||
require_once('DB.php');
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init("$airtime_base_dir/application/configs/airtime-conf.php");
|
||||
|
||||
|
||||
function get_ini_file(){
|
||||
$ini = parse_ini_file("/etc/airtime/airtime.conf", true);
|
||||
if ($ini === FALSE || !array_key_exists('airtime_dir', $ini['general'])){
|
||||
echo "Could not open /etc/airtime/airtime.conf. Is Airtime installed?".PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
return $ini;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Look through all the files in the database and remove the rows
|
||||
* that have no associated file.
|
||||
*
|
||||
* @return int
|
||||
* The total number of files that were missing.
|
||||
*/
|
||||
function airtime_clean_files() {
|
||||
$count = 0;
|
||||
$files = StoredFile::GetAll();
|
||||
foreach ($files as $file) {
|
||||
if (($file["ftype"] == "audioclip") && !@file_exists($file["filepath"])) {
|
||||
echo " * Removing metadata for id ".$file["id"].":".PHP_EOL;
|
||||
echo " * File path: ".$file["filepath"].PHP_EOL;
|
||||
echo " * Track title: ".$file["track_title"].PHP_EOL;
|
||||
echo " * Artist: ".$file["artist_name"].PHP_EOL;
|
||||
echo " * Album: ".$file["album_title"].PHP_EOL;
|
||||
StoredFile::deleteById($file["id"]);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function airtime_empty_db($db)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
// NOTE: order matter here.
|
||||
echo " * Clearing schedule table...".PHP_EOL;
|
||||
Schedule::deleteAll();
|
||||
|
||||
// Ugly hack
|
||||
echo " * Resetting show instance times to zero...".PHP_EOL;
|
||||
$sql = "UPDATE cc_show_instances SET time_filled='00:00:00'";
|
||||
$CC_DBC->query($sql);
|
||||
|
||||
echo " * Clearing playlist table...".PHP_EOL;
|
||||
Playlist::deleteAll();
|
||||
|
||||
echo " * Clearing files table...".PHP_EOL;
|
||||
$result = StoredFile::deleteAll();
|
||||
if (PEAR::isError($result)) {
|
||||
echo $result->getMessage().PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
global $CC_CONFIG;
|
||||
|
||||
require_once('Zend/Loader/Autoloader.php');
|
||||
$autoloader = Zend_Loader_Autoloader::getInstance();
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
array(
|
||||
'help|h' => 'Displays usage information.',
|
||||
'clean|c' => 'Removes all audio file metadata from the database that does not have a matching file in the filesystem.',
|
||||
'empty|e' => 'Removes all files and playlists from Airtime.'
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
exit($e->getMessage() .PHP_EOL. $e->getUsageMessage());
|
||||
}
|
||||
|
||||
if (isset($opts->h)) {
|
||||
echo PHP_EOL;
|
||||
echo $opts->getUsageMessage();
|
||||
echo "Storage directory: ". realpath($CC_CONFIG["storageDir"]).PHP_EOL.PHP_EOL;
|
||||
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->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
if (isset($opts->e)) {
|
||||
echo PHP_EOL;
|
||||
airtime_empty_db($CC_DBC);
|
||||
echo "Done.".PHP_EOL.PHP_EOL;
|
||||
} elseif (isset($opts->c)) {
|
||||
$count = airtime_clean_files($CC_CONFIG['storageDir']);
|
||||
if ($count == 0) {
|
||||
echo PHP_EOL."All file metadata in the database is linked to a real file. Nothing to be done.".PHP_EOL.PHP_EOL;
|
||||
} else {
|
||||
echo PHP_EOL."Total rows removed: $count".PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
echo PHP_EOL;
|
||||
echo $opts->getUsageMessage();
|
||||
echo "Storage directory: ". realpath($CC_CONFIG["storageDir"]).PHP_EOL.PHP_EOL;
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2010 Sourcefabric O.P.S.
|
||||
#
|
||||
# This file is part of the Airtime project.
|
||||
# http://airtime.sourcefabric.org/
|
||||
#
|
||||
# Airtime 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.
|
||||
#
|
||||
# Airtime 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 Airtime; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# This script imports audio files into Airtime.
|
||||
#
|
||||
# To get usage help, try the -h option
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Determine directories, files
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Absolute path to this script
|
||||
SCRIPT=`readlink -f $0`
|
||||
# Absolute directory this script is in
|
||||
SCRIPTPATH=`dirname $SCRIPT`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Do import
|
||||
#-------------------------------------------------------------------------------
|
||||
invokePwd=$PWD
|
||||
cd $SCRIPTPATH
|
||||
|
||||
php -q airtime-import.php --dir "$invokePwd" "$@" || exit 1
|
|
@ -1,393 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Mass import of audio files.
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageAdmin
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
ini_set('memory_limit', '128M');
|
||||
set_time_limit(0);
|
||||
error_reporting(E_ALL);
|
||||
set_error_handler("import_error_handler", E_ALL & !E_NOTICE);
|
||||
|
||||
$ini = get_ini_file();
|
||||
$airtime_base_dir = $ini['general']['airtime_dir'];
|
||||
|
||||
set_include_path("$airtime_base_dir/library" . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require_once("$airtime_base_dir/application/configs/conf.php");
|
||||
require_once("$airtime_base_dir/application/models/StoredFile.php");
|
||||
require_once('DB.php');
|
||||
require_once('Console/Getopt.php');
|
||||
|
||||
function import_error_handler()
|
||||
{
|
||||
echo var_dump(debug_backtrace());
|
||||
exit();
|
||||
}
|
||||
|
||||
function get_ini_file(){
|
||||
$ini = parse_ini_file("/etc/airtime/airtime.conf", true);
|
||||
if ($ini === FALSE || !array_key_exists('airtime_dir', $ini['general'])){
|
||||
echo "Could not open /etc/airtime/airtime.conf. Is Airtime installed?".PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
return $ini;
|
||||
}
|
||||
|
||||
|
||||
function printUsage()
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
echo "There are two ways to import audio files into Airtime: linking\n";
|
||||
echo "or copying.\n";
|
||||
echo "\n";
|
||||
echo "Linking has the advantage that it will not duplicate any files,\n";
|
||||
echo "but you must take care not to move, rename, or delete any of the\n";
|
||||
echo "imported files from their current locations on disk.\n";
|
||||
echo "\n";
|
||||
echo "Copying has the advantage that you can do whatever you like with\n";
|
||||
echo "the source files after you import them, but has the disadvantage\n";
|
||||
echo "that it requires doubling the hard drive space needed to store\n";
|
||||
echo "your files.\n";
|
||||
echo "\n";
|
||||
echo "Usage:\n";
|
||||
echo " airtime-import [OPTIONS] FILES_OR_DIRS\n";
|
||||
echo "\n";
|
||||
echo "Options:\n";
|
||||
echo " -l, --link Link to specified files.\n";
|
||||
echo " Saves storage space, but you cannot move, delete,\n";
|
||||
echo " or rename the original files, otherwise there will\n";
|
||||
echo " be dead air when Airtime tries to play the file.\n";
|
||||
echo "\n";
|
||||
echo " -c, --copy Copy the specified files.\n";
|
||||
echo " This is useful if you are importing from removable media.\n";
|
||||
echo " If you are importing files on your hard drive, this will\n";
|
||||
echo " double the disk space required.\n";
|
||||
echo "\n";
|
||||
echo " -h, --help Print this message and exit.\n";
|
||||
echo "\n";
|
||||
echo "Files will be imported to directory:\n";
|
||||
echo " ". realpath($CC_CONFIG["storageDir"]) ."\n";
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print error to the screen and keep a count of number of errors.
|
||||
*
|
||||
* @param PEAR_Error $pearErrorObj
|
||||
* @param string $txt
|
||||
*/
|
||||
function import_err($p_pearErrorObj, $txt='')
|
||||
{
|
||||
global $g_errors;
|
||||
if (PEAR::isError($p_pearErrorObj)) {
|
||||
$msg = $p_pearErrorObj->getMessage()." ".$p_pearErrorObj->getUserInfo();
|
||||
}
|
||||
echo "\nERROR: $msg\n";
|
||||
if (!empty($txt)) {
|
||||
echo "ERROR: $txt\n";
|
||||
}
|
||||
$g_errors++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a file or directory into the storage database.
|
||||
* If it is a directory, files will be imported recursively.
|
||||
*
|
||||
* @param string $p_filepath
|
||||
* You can pass in a directory or file name.
|
||||
* This must be the full absolute path to the file, not relative.
|
||||
* @param string $p_importMode
|
||||
* @param boolean $p_testOnly
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = false)
|
||||
{
|
||||
global $STORAGE_SERVER_PATH;
|
||||
global $g_fileCount;
|
||||
global $g_duplicates;
|
||||
global $g_replaced;
|
||||
|
||||
// Check parameters
|
||||
$p_importMode = strtolower($p_importMode);
|
||||
if (!in_array($p_importMode, array("copy", "link"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fileCount = 0;
|
||||
$duplicates = 0;
|
||||
|
||||
if (!file_exists($p_filepath)) {
|
||||
echo " * WARNING: File does not exist: $p_filepath\n";
|
||||
return;
|
||||
}
|
||||
|
||||
//echo "Memory usage:".memory_get_usage()."\n";
|
||||
|
||||
// If we are given a directory, get all the files recursively and
|
||||
// call this function for each file.
|
||||
if (is_dir($p_filepath)) {
|
||||
// NOTE: this method of using opendir() is used over other
|
||||
// techniques because of its low memory usage. Both PEAR's
|
||||
// File_Find and PHP5's built-in RecursiveDirectoryIterator
|
||||
// use about 5500 bytes per file, while this method uses
|
||||
// about 1100 bytes per file.
|
||||
$d = opendir($p_filepath);
|
||||
while (false !== ($file = readdir($d))) {
|
||||
if ($file != "." && $file != "..") {
|
||||
$path = "$p_filepath/$file";
|
||||
import_audio_file($path, $p_importMode, $p_testOnly);
|
||||
}
|
||||
}
|
||||
closedir($d);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for non-supported file type
|
||||
if (!preg_match('/\.(ogg|mp3)$/i', $p_filepath, $var)) {
|
||||
echo "IGNORED: [xxxxx] $p_filepath\n";
|
||||
//echo " * WARNING: File extension not supported - skipping file: $p_filepath\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the file permissions to be world-readable
|
||||
if ($p_importMode == "link") {
|
||||
// Check current file permissions
|
||||
$fileperms = fileperms($p_filepath);
|
||||
// Explaination of 0x0124:
|
||||
// 1 => owner readable
|
||||
// 2 => group readable
|
||||
// 4 => world readable
|
||||
// (see: http://php.net/manual/en/function.fileperms.php)
|
||||
$readableByAll = !(($fileperms & 0x0124) ^ 0x0124);
|
||||
if (!$readableByAll) {
|
||||
$permError = false;
|
||||
// Check if we have the ability to change the perms
|
||||
if (is_writable($p_filepath)) {
|
||||
// Change the file perms
|
||||
$fileperms = $fileperms | 0x0124;
|
||||
chmod($p_filepath, $fileperms);
|
||||
|
||||
// Check that file perms were changed
|
||||
clearstatcache();
|
||||
$fileperms = fileperms($p_filepath);
|
||||
$readableByAll = !(($fileperms & 0x0124) ^ 0x124);
|
||||
if (!$readableByAll) {
|
||||
$permError = true;
|
||||
}
|
||||
} else {
|
||||
$permError = true;
|
||||
}
|
||||
if ($permError) {
|
||||
global $g_errors;
|
||||
$g_errors++;
|
||||
echo "ERROR: $p_filepath\n"
|
||||
." When importing with the '--link' option, files must be set\n"
|
||||
." world-readable. The file permissions for the file cannot be\n"
|
||||
." changed. Check that you are not trying to import from a FAT32\n"
|
||||
." drive. Otherwise, this problem might be fixed by running this \n"
|
||||
." script with 'sudo'.\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $timeBegin = microtime(true);
|
||||
$md5sum = md5_file($p_filepath);
|
||||
// $timeEnd = microtime(true);
|
||||
// echo " * MD5 time: ".($timeEnd-$timeBegin)."\n";
|
||||
|
||||
// Look up md5sum in database
|
||||
$duplicate = StoredFile::RecallByMd5($md5sum);
|
||||
if (PEAR::isError($duplicate)) {
|
||||
echo $duplicate->getMessage();
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
//row exists in database
|
||||
if (isset($duplicate)) {
|
||||
if (file_exists($duplicate->getRealFilePath())) {
|
||||
echo "DUPLICATE: $p_filepath\n";
|
||||
$g_duplicates++;
|
||||
}
|
||||
else{
|
||||
if ($p_importMode == "copy") {
|
||||
$doCopyFiles = true;
|
||||
}
|
||||
else if ($p_importMode == "link") {
|
||||
$doCopyFiles = false;
|
||||
}
|
||||
$res = $duplicate->replaceFile($p_filepath, $doCopyFiles);
|
||||
if (PEAR::isError($res)) {
|
||||
echo $res->getMessage();
|
||||
echo "\n";
|
||||
return;
|
||||
}
|
||||
$g_replaced++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
echo "Importing: [".sprintf("%05d",$g_fileCount+1)."] $p_filepath\n";
|
||||
|
||||
if (!$p_testOnly) {
|
||||
if ($p_importMode == "copy") {
|
||||
$doCopyFiles = true;
|
||||
} elseif ($p_importMode == "link") {
|
||||
$doCopyFiles = false;
|
||||
}
|
||||
$values = array(
|
||||
"filepath" => $p_filepath,
|
||||
"md5" => $md5sum,
|
||||
);
|
||||
$storedFile = StoredFile::Insert($values, $doCopyFiles);
|
||||
if (PEAR::isError($storedFile)) {
|
||||
import_err($storedFile, "Error in StoredFile::Insert()");
|
||||
echo var_export($metadata)."\n";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
echo "==========================================================================\n";
|
||||
echo "METADATA\n";
|
||||
var_dump($metadata);
|
||||
}
|
||||
|
||||
$g_fileCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
$DEBUG_IMPORT = false;
|
||||
|
||||
echo "========================\n";
|
||||
echo "Airtime Import Script\n";
|
||||
echo "========================\n";
|
||||
$g_errors = 0;
|
||||
//print_r($argv);
|
||||
$start = intval(date('U'));
|
||||
|
||||
if ($DEBUG_IMPORT) {
|
||||
$testonly = false;
|
||||
$importMode = "link";
|
||||
$files = array("/path/to/your/test/file.mp3");
|
||||
$dsn = $CC_CONFIG['dsn'];
|
||||
} else {
|
||||
$dsn = $CC_CONFIG['dsn'];
|
||||
}
|
||||
//PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "import_error_handler");
|
||||
$CC_DBC = DB::connect($dsn, TRUE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
|
||||
exit(1);
|
||||
}
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
if (!$DEBUG_IMPORT) {
|
||||
$parsedCommandLine = Console_Getopt::getopt($argv, "thcld", array("test", "help", "copy", "link", "dir="));
|
||||
//print_r($parsedCommandLine);
|
||||
if (PEAR::isError($parsedCommandLine)) {
|
||||
printUsage();
|
||||
exit(1);
|
||||
}
|
||||
$cmdLineOptions = $parsedCommandLine[0];
|
||||
if (count($parsedCommandLine[1]) == 0) {
|
||||
printUsage();
|
||||
exit;
|
||||
}
|
||||
|
||||
$files = $parsedCommandLine[1];
|
||||
|
||||
$testonly = FALSE;
|
||||
$importMode = null;
|
||||
$currentDir = null;
|
||||
foreach ($cmdLineOptions as $tmpValue) {
|
||||
$optionName = $tmpValue[0];
|
||||
$optionValue = $tmpValue[1];
|
||||
switch ($optionName) {
|
||||
case "h":
|
||||
case '--help':
|
||||
printUsage();
|
||||
exit;
|
||||
case "c":
|
||||
case "--copy":
|
||||
$importMode = "copy";
|
||||
break;
|
||||
case 'l':
|
||||
case '--link':
|
||||
$importMode = "link";
|
||||
break;
|
||||
case '--dir':
|
||||
$currentDir = $optionValue;
|
||||
break;
|
||||
case "t":
|
||||
case "--test":
|
||||
$testonly = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($importMode)) {
|
||||
printUsage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
global $CC_CONFIG;
|
||||
|
||||
if ( ($importMode == "copy") && !is_writable($CC_CONFIG["storageDir"])) {
|
||||
echo "ERROR: You do not have write permissions to the directory you are trying to import to:\n " . $CC_CONFIG["storageDir"] . "\n\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
global $g_fileCount;
|
||||
global $g_duplicates;
|
||||
global $g_replaced;
|
||||
$g_fileCount = 0;
|
||||
$g_duplicates = 0;
|
||||
$g_replaced = 0;
|
||||
if (is_array($files)) {
|
||||
foreach ($files as $filepath) {
|
||||
// absolute path
|
||||
if (($filepath[0] == "/") || ($filepath[0] == "~")) {
|
||||
$fullPath = realpath($filepath);
|
||||
} elseif (!is_null($currentDir)) {
|
||||
$fullPath = realpath("$currentDir/$filepath");
|
||||
} else {
|
||||
$fullPath = null;
|
||||
}
|
||||
|
||||
if (empty($fullPath)) {
|
||||
echo "ERROR: I cant find the given file: $filepath\n\n";
|
||||
exit;
|
||||
}
|
||||
import_audio_file($fullPath, $importMode, $testonly);
|
||||
}
|
||||
}
|
||||
$end = intval(date('U'));
|
||||
$time = $end - $start;
|
||||
if ($time > 0) {
|
||||
$speed = round(($g_fileCount+$g_duplicates)/$time, 1);
|
||||
} else {
|
||||
$speed = ($g_fileCount+$g_duplicates);
|
||||
}
|
||||
|
||||
echo "==========================================================================\n";
|
||||
echo " *** Import mode: $importMode\n";
|
||||
if ($importMode == "copy") {
|
||||
echo " *** Destination folder: ".$CC_CONFIG['storageDir']."\n";
|
||||
}
|
||||
echo " *** Files imported: $g_fileCount\n";
|
||||
echo " *** Files restored: $g_replaced\n";
|
||||
echo " *** Duplicate files (not imported): $g_duplicates\n";
|
||||
if ($g_errors > 0) {
|
||||
echo " *** Errors: $g_errors\n";
|
||||
}
|
||||
echo " *** Total: ".($g_fileCount+$g_duplicates)." files in $time seconds = $speed files/second.\n";
|
||||
echo "==========================================================================\n";
|
||||
|
|
@ -11,8 +11,6 @@ $CC_CONFIG['baseUrl'] = $values['general']['base_url'];
|
|||
$CC_CONFIG['basePort'] = $values['general']['base_port'];
|
||||
|
||||
$CC_CONFIG['baseFilesDir'] = $values['general']['base_files_dir'];
|
||||
// main directory for storing binary media files
|
||||
$CC_CONFIG['storageDir'] = $values['general']['base_files_dir']."/stor";
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
|
|
Loading…
Reference in New Issue