CC-1713 - New storage directory structure

Changed the GUNID to a 32 hex string (MD5 value), there is no more
conversion between hex strings and bigints in the database anymore.

Added added the file extension to the file name.

Stored the complete path to the file in the database.  This means that
linking doesnt need to create any files at all. (It used to create a
symlink to the file you were importing)

The structure and file naming should be fine - there are 4096 possibilities
for the first directory level, and even will a million files this is only
244 files per sub-directory.  The GUID is fine for the file name
This commit is contained in:
paul.baranowski 2010-11-11 16:50:30 -05:00
parent 3879d1c7d4
commit 35dc3fd01f
8 changed files with 215 additions and 78 deletions

13
api/api_version.php Normal file
View File

@ -0,0 +1,13 @@
<?php
require_once('../conf.php');
$api_key = $_GET['api_key'];
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
{
header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.';
exit;
}
print json_encode(array("version"=>CAMPCASTER_VERSION));
?>

38
api/get_media.php Normal file
View File

@ -0,0 +1,38 @@
<?php
require_once('../conf.php');
require_once('DB.php');
$api_key = $_GET['api_key'];
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
{
header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.';
exit;
}
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
if (PEAR::isError($CC_DBC)) {
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
exit(1);
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
$file_id = $_GET[""]
if(!is_file($src))
{
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
//print 'Ressource in database, but not in storage. Sorry.';
exit;
}
// !! binary mode !!
$fp = fopen($src, 'rb');
header("Content-Type: audio/mpeg");
header("Content-Length: " . filesize($src));
fpassthru($fp);
exit;
?>

25
api/schedule.php Normal file
View File

@ -0,0 +1,25 @@
<?php
require_once('../conf.php');
require_once('DB.php');
require_once('../backend/Schedule.php');
$api_key = $_GET['api_key'];
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
{
header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.';
exit;
}
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
if (PEAR::isError($CC_DBC)) {
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
exit(1);
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
$from = $_GET["from"];
$to = $_GET["to"];
echo Schedule::ExportRangeAsJson($from, $to);
?>

View File

@ -935,6 +935,9 @@ class BasicStor {
if (!is_array($values)) { if (!is_array($values)) {
$values = array($values); $values = array($values);
} }
if (count($values) == 0) {
return true;
}
if (is_a($id, "StoredFile")) { if (is_a($id, "StoredFile")) {
$storedFile =& $id; $storedFile =& $id;
} else { } else {
@ -949,10 +952,31 @@ class BasicStor {
if ($category == 'dcterms:extent') { if ($category == 'dcterms:extent') {
$oneValue = BasicStor::NormalizeExtent($oneValue); $oneValue = BasicStor::NormalizeExtent($oneValue);
} }
$escapedValue = pg_escape_string($oneValue); // Since track_number is an integer, you cannot set
$sqlValues[] = "$columnName = '$escapedValue'"; // it to be the empty string, so we NULL it instead.
if ($columnName == 'track_number' && empty($oneValue)) {
$sqlPart = "$columnName = NULL";
} elseif (($columnName == 'length') && (strlen($oneValue) > 8)) {
// Postgres doesnt like it if you try to store really large hour
// values. TODO: We need to fix the underlying problem of getting the
// right values.
$parts = explode(':', $oneValue);
$hour = intval($parts[0]);
if ($hour > 24) {
continue;
} else {
$sqlPart = "$columnName = '$oneValue'";
}
} else {
$escapedValue = pg_escape_string($oneValue);
$sqlPart = "$columnName = '$escapedValue'";
}
$sqlValues[] = $sqlPart;
} }
} }
if (count($sqlValues)==0) {
return TRUE;
}
$sql = "UPDATE ".$CC_CONFIG["filesTable"] $sql = "UPDATE ".$CC_CONFIG["filesTable"]
." SET ".join(",", $sqlValues) ." SET ".join(",", $sqlValues)
." WHERE id=$id"; ." WHERE id=$id";

View File

@ -1,6 +1,7 @@
<?php <?php
require_once("Playlist.php"); require_once("Playlist.php");
require_once(dirname(__FILE__)."/../3rd_party/getid3/var/getid3.php"); require_once(dirname(__FILE__)."/../3rd_party/getid3/var/getid3.php");
require_once("BasicStor.php");
/** /**
* Track numbers in metadata tags can come in many formats: * Track numbers in metadata tags can come in many formats:
@ -300,7 +301,7 @@ class StoredFile {
* *
* @var string * @var string
*/ */
private $gunidBigint; //private $gunidBigint;
/** /**
* @var string * @var string
@ -346,14 +347,14 @@ class StoredFile {
*/ */
private $md5; private $md5;
// *** Variables NOT stored in the database ***
/** /**
* @var string * @var string
*/ */
private $filepath; private $filepath;
// *** Variables NOT stored in the database ***
/** /**
* Directory where the file is located. * Directory where the file is located.
* *
@ -384,10 +385,10 @@ class StoredFile {
global $CC_DBC; global $CC_DBC;
$this->gunid = $p_gunid; $this->gunid = $p_gunid;
if (empty($this->gunid)) { if (empty($this->gunid)) {
$this->gunid = StoredFile::CreateGunid(); $this->gunid = StoredFile::generateGunid();
} }
$this->resDir = $this->_getResDir($this->gunid); //$this->resDir = $this->_getResDir($this->gunid);
$this->filepath = "{$this->resDir}/{$this->gunid}"; //$this->filepath = "{$this->resDir}/{$this->gunid}";
$this->exists = is_file($this->filepath) && is_readable($this->filepath); $this->exists = is_file($this->filepath) && is_readable($this->filepath);
$this->md = $this->loadMetadata(); $this->md = $this->loadMetadata();
} }
@ -401,7 +402,7 @@ class StoredFile {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$escapedValue = pg_escape_string($this->gunid); $escapedValue = pg_escape_string($this->gunid);
$sql = "SELECT * FROM ".$CC_CONFIG["filesTable"] $sql = "SELECT * FROM ".$CC_CONFIG["filesTable"]
." WHERE gunid=x'$escapedValue'::bigint"; ." WHERE gunid='$escapedValue'";
//var_dump($sql); //var_dump($sql);
$this->md = $CC_DBC->getRow($sql); $this->md = $CC_DBC->getRow($sql);
if (PEAR::isError($this->md)) { if (PEAR::isError($this->md)) {
@ -409,6 +410,7 @@ class StoredFile {
$this->md = null; $this->md = null;
return $error; return $error;
} }
$this->filepath = $this->md["filepath"];
if (is_null($this->md)) { if (is_null($this->md)) {
$this->md = array(); $this->md = array();
return; return;
@ -465,7 +467,7 @@ class StoredFile {
* Create instance of StoredFile object and insert new file * Create instance of StoredFile object and insert new file
* *
* @param array $p_values * @param array $p_values
* "filepath" - required, local path to media file * "filepath" - required, local path to media file (where it is before import)
* "id" - optional, local object id, will be generated if not given * "id" - optional, local object id, will be generated if not given
* "gunid" - optional, unique id, for insert file with gunid, will be generated if not given * "gunid" - optional, unique id, for insert file with gunid, will be generated if not given
* "filename" - optional, will use "filepath" if not given * "filename" - optional, will use "filepath" if not given
@ -503,9 +505,9 @@ class StoredFile {
} }
$storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $p_values["filepath"]; $storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $p_values["filepath"];
// NOTE: POSTGRES-SPECIFIC KEYWORD "DEFAULT" BEING USED, WOULD BE "NULL" IN MYSQL
$storedFile->id = isset($p_values['id']) && is_integer($p_values['id'])?(int)$p_values['id']:null; $storedFile->id = isset($p_values['id']) && is_integer($p_values['id'])?(int)$p_values['id']:null;
$sqlId = !is_null($storedFile->id)?"'".$storedFile->id."'":'DEFAULT'; // NOTE: POSTGRES-SPECIFIC KEYWORD "DEFAULT" BEING USED, WOULD BE "NULL" IN MYSQL
$sqlId = !is_null($storedFile->id)?"'".$storedFile->id."'":'DEFAULT';
$storedFile->ftype = isset($p_values['filetype']) ? strtolower($p_values['filetype']) : "audioclip"; $storedFile->ftype = isset($p_values['filetype']) ? strtolower($p_values['filetype']) : "audioclip";
$storedFile->mime = (isset($p_values["mime"]) ? $p_values["mime"] : NULL ); $storedFile->mime = (isset($p_values["mime"]) ? $p_values["mime"] : NULL );
// $storedFile->filepath = $p_values['filepath']; // $storedFile->filepath = $p_values['filepath'];
@ -531,7 +533,7 @@ class StoredFile {
$sql = "INSERT INTO ".$CC_CONFIG['filesTable'] $sql = "INSERT INTO ".$CC_CONFIG['filesTable']
."(id, name, gunid, mime, state, ftype, mtime, md5)" ."(id, name, gunid, mime, state, ftype, mtime, md5)"
."VALUES ({$sqlId}, '{$escapedName}', " ."VALUES ({$sqlId}, '{$escapedName}', "
." x'{$storedFile->gunid}'::bigint," ." '{$storedFile->gunid}',"
." '{$storedFile->mime}', 'incomplete', '$escapedFtype'," ." '{$storedFile->mime}', 'incomplete', '$escapedFtype',"
." now(), '{$storedFile->md5}')"; ." now(), '{$storedFile->md5}')";
//$_SESSION["debug"] .= "sql: ".$sql."<br>"; //$_SESSION["debug"] .= "sql: ".$sql."<br>";
@ -550,6 +552,7 @@ class StoredFile {
// Save media file // Save media file
$res = $storedFile->addFile($p_values['filepath'], $p_copyMedia); $res = $storedFile->addFile($p_values['filepath'], $p_copyMedia);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
echo "StoredFile::Insert: ERROR adding file: '".$res->getMessage()."'\n"; echo "StoredFile::Insert: ERROR adding file: '".$res->getMessage()."'\n";
$CC_DBC->query("ROLLBACK"); $CC_DBC->query("ROLLBACK");
@ -596,17 +599,18 @@ class StoredFile {
if (!is_null($p_oid)) { if (!is_null($p_oid)) {
$cond = "id='".intval($p_oid)."'"; $cond = "id='".intval($p_oid)."'";
} elseif (!is_null($p_gunid)) { } elseif (!is_null($p_gunid)) {
$cond = "gunid=x'$p_gunid'::bigint"; $cond = "gunid='$p_gunid'";
} elseif (!is_null($p_md5sum)) { } elseif (!is_null($p_md5sum)) {
$cond = "md5='$p_md5sum'"; $cond = "md5='$p_md5sum'";
} else { } else {
return null; return null;
} }
$sql = "SELECT id, to_hex(gunid)as gunid, gunid as gunid_bigint," $sql = "SELECT id, gunid,"
." name, mime, ftype, state, currentlyaccessing, editedby, " ." name, mime, ftype, state, currentlyaccessing, editedby, "
." mtime, md5" ." mtime, md5"
." FROM ".$CC_CONFIG['filesTable'] ." FROM ".$CC_CONFIG['filesTable']
." WHERE $cond"; ." WHERE $cond";
//echo $sql;
$row = $CC_DBC->getRow($sql); $row = $CC_DBC->getRow($sql);
if (PEAR::isError($row)) { if (PEAR::isError($row)) {
return $row; return $row;
@ -614,7 +618,7 @@ class StoredFile {
if (is_null($row)) { if (is_null($row)) {
return null; return null;
} }
$gunid = StoredFile::NormalizeGunid($row['gunid']); $gunid = $row['gunid'];
if ($row['ftype'] == 'audioclip') { if ($row['ftype'] == 'audioclip') {
$storedFile = new StoredFile($gunid); $storedFile = new StoredFile($gunid);
} elseif ($row['ftype'] == 'playlist') { } elseif ($row['ftype'] == 'playlist') {
@ -623,9 +627,9 @@ class StoredFile {
$storedFile = new StoredFile($gunid); $storedFile = new StoredFile($gunid);
} }
$storedFile->loadMetadata(); $storedFile->loadMetadata();
$storedFile->gunidBigint = $row['gunid_bigint']; //$storedFile->gunidBigint = $row['gunid_bigint'];
//$storedFile->md->gunidBigint = $row['gunid_bigint']; //$storedFile->md->gunidBigint = $row['gunid_bigint'];
$storedFile->md["gunid"] = $row['gunid_bigint']; $storedFile->md["gunid"] = $row['gunid'];
$storedFile->id = $row['id']; $storedFile->id = $row['id'];
$storedFile->name = $row['name']; $storedFile->name = $row['name'];
$storedFile->mime = $row['mime']; $storedFile->mime = $row['mime'];
@ -678,7 +682,7 @@ class StoredFile {
public static function RecallByToken($p_token) public static function RecallByToken($p_token)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT to_hex(gunid) as gunid" $sql = "SELECT gunid"
." FROM ".$CC_CONFIG['accessTable'] ." FROM ".$CC_CONFIG['accessTable']
." WHERE token=x'$p_token'::bigint"; ." WHERE token=x'$p_token'::bigint";
$gunid = $CC_DBC->getOne($sql); $gunid = $CC_DBC->getOne($sql);
@ -689,11 +693,28 @@ class StoredFile {
return PEAR::raiseError( return PEAR::raiseError(
"StoredFile::RecallByToken: invalid token ($p_token)", GBERR_AOBJNEX); "StoredFile::RecallByToken: invalid token ($p_token)", GBERR_AOBJNEX);
} }
$gunid = StoredFile::NormalizeGunid($gunid);
return StoredFile::Recall(null, $gunid); return StoredFile::Recall(null, $gunid);
} }
/**
* Generate the location to store the file.
* It creates the subdirectory if needed.
*/
private function generateFilePath()
{
global $CC_CONFIG, $CC_DBC;
$resDir = $CC_CONFIG['storageDir']."/".substr($this->gunid, 0, 3);
// see Transport::_getResDir too for resDir name create code
if (!is_dir($resDir)) {
mkdir($resDir, 02775);
chmod($resDir, 02775);
}
$info = pathinfo($this->name);
$fileExt = strtolower($info["extension"]);
return "{$resDir}/{$this->gunid}.{$fileExt}";
}
/** /**
* Insert media file to filesystem * Insert media file to filesystem
* *
@ -705,30 +726,43 @@ class StoredFile {
*/ */
public function addFile($p_localFilePath, $p_copyMedia=TRUE) public function addFile($p_localFilePath, $p_copyMedia=TRUE)
{ {
global $CC_CONFIG, $CC_DBC;
if ($this->exists) { if ($this->exists) {
return FALSE; return FALSE;
} }
// for files downloaded from archive: // for files downloaded from remote instance:
if ($p_localFilePath == $this->filepath) { if ($p_localFilePath == $this->filepath) {
$this->exists = TRUE; $this->exists = TRUE;
return TRUE; return TRUE;
} }
umask(0002); umask(0002);
$dstFile = '';
if ($p_copyMedia) { if ($p_copyMedia) {
$r = @copy($p_localFilePath, $this->filepath); $dstFile = $this->generateFilePath();
$r = @copy($p_localFilePath, $dstFile);
if (!$r) {
$this->exists = FALSE;
return PEAR::raiseError(
"StoredFile::addFile: file save failed".
" ($p_localFilePath, {$this->filepath})",GBERR_FILEIO
);
}
} else { } else {
$r = @symlink($p_localFilePath, $this->filepath); $dstFile = $p_localFilePath;
$r = TRUE;
//$r = @symlink($p_localFilePath, $dstFile);
} }
if ($r) { $this->filepath = $dstFile;
$this->exists = TRUE; $sqlPath = pg_escape_string($this->filepath);
return TRUE; $sql = "UPDATE ".$CC_CONFIG["filesTable"]
} else { ." SET filepath='{$sqlPath}'"
$this->exists = FALSE; ." WHERE id={$this->id}";
return PEAR::raiseError( $res = $CC_DBC->query($sql);
"StoredFile::addFile: file save failed". if (PEAR::isError($res)) {
" ($p_localFilePath, {$this->filepath})",GBERR_FILEIO return $res;
);
} }
$this->exists = TRUE;
return TRUE;
} }
@ -1013,7 +1047,7 @@ class StoredFile {
$escapedName = pg_escape_string($p_newname); $escapedName = pg_escape_string($p_newname);
$sql = "UPDATE ".$CC_CONFIG['filesTable'] $sql = "UPDATE ".$CC_CONFIG['filesTable']
." SET name='$escapedName', mtime=now()" ." SET name='$escapedName', mtime=now()"
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $CC_DBC->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
@ -1039,7 +1073,7 @@ class StoredFile {
$eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : ''); $eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : '');
$sql = "UPDATE ".$CC_CONFIG['filesTable'] $sql = "UPDATE ".$CC_CONFIG['filesTable']
." SET state='$escapedState'$eb, mtime=now()" ." SET state='$escapedState'$eb, mtime=now()"
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $CC_DBC->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
@ -1065,7 +1099,7 @@ class StoredFile {
$escapedMime = pg_escape_string($p_mime); $escapedMime = pg_escape_string($p_mime);
$sql = "UPDATE ".$CC_CONFIG['filesTable'] $sql = "UPDATE ".$CC_CONFIG['filesTable']
." SET mime='$escapedMime', mtime=now()" ." SET mime='$escapedMime', mtime=now()"
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $CC_DBC->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
@ -1087,7 +1121,7 @@ class StoredFile {
$escapedMd5 = pg_escape_string($p_md5sum); $escapedMd5 = pg_escape_string($p_md5sum);
$sql = "UPDATE ".$CC_CONFIG['filesTable'] $sql = "UPDATE ".$CC_CONFIG['filesTable']
." SET md5='$escapedMd5', mtime=now()" ." SET md5='$escapedMd5', mtime=now()"
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $CC_DBC->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
@ -1119,7 +1153,7 @@ class StoredFile {
// } // }
$sql = "SELECT to_hex(token)as token, ext " $sql = "SELECT to_hex(token)as token, ext "
." FROM ".$CC_CONFIG['accessTable'] ." FROM ".$CC_CONFIG['accessTable']
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$tokens = $CC_DBC->getAll($sql); $tokens = $CC_DBC->getAll($sql);
if (is_array($tokens)) { if (is_array($tokens)) {
foreach ($tokens as $i => $item) { foreach ($tokens as $i => $item) {
@ -1130,13 +1164,13 @@ class StoredFile {
} }
} }
$sql = "DELETE FROM ".$CC_CONFIG['accessTable'] $sql = "DELETE FROM ".$CC_CONFIG['accessTable']
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $CC_DBC->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
$sql = "DELETE FROM ".$CC_CONFIG['filesTable'] $sql = "DELETE FROM ".$CC_CONFIG['filesTable']
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql); $res = $CC_DBC->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
@ -1182,7 +1216,7 @@ class StoredFile {
return ($this->currentlyaccessing > 0); return ($this->currentlyaccessing > 0);
} }
$sql = "SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable'] $sql = "SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable']
." WHERE gunid=x'$p_gunid'::bigint"; ." WHERE gunid='$p_gunid'";
$ca = $CC_DBC->getOne($sql); $ca = $CC_DBC->getOne($sql);
if (is_null($ca)) { if (is_null($ca)) {
return PEAR::raiseError( return PEAR::raiseError(
@ -1229,7 +1263,7 @@ class StoredFile {
$p_playlistId = $this->gunid; $p_playlistId = $this->gunid;
} }
$sql = "SELECT editedBy FROM ".$CC_CONFIG['filesTable'] $sql = "SELECT editedBy FROM ".$CC_CONFIG['filesTable']
." WHERE gunid=x'$p_playlistId'::bigint"; ." WHERE gunid='$p_playlistId'";
$ca = $CC_DBC->getOne($sql); $ca = $CC_DBC->getOne($sql);
if (PEAR::isError($ca)) { if (PEAR::isError($ca)) {
return $ca; return $ca;
@ -1270,9 +1304,9 @@ class StoredFile {
public function exists() public function exists()
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT to_hex(gunid) " $sql = "SELECT gunid "
." FROM ".$CC_CONFIG['filesTable'] ." FROM ".$CC_CONFIG['filesTable']
." WHERE gunid=x'{$this->gunid}'::bigint"; ." WHERE gunid='{$this->gunid}'";
$indb = $CC_DBC->getRow($sql); $indb = $CC_DBC->getRow($sql);
if (PEAR::isError($indb)) { if (PEAR::isError($indb)) {
return $indb; return $indb;
@ -1291,15 +1325,17 @@ class StoredFile {
* Create new global unique id * Create new global unique id
* @return string * @return string
*/ */
public static function CreateGunid() public static function generateGunid()
{ {
$ip = (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : ''); return md5(uniqid("", true));
$initString = microtime().$ip.rand()."org.mdlf.campcaster";
$hash = md5($initString); // $ip = (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '');
// non-negative int8 // $initString = microtime().$ip.rand();
$hsd = substr($hash, 0, 1); // $hash = md5($initString);
$res = dechex(hexdec($hsd)>>1).substr($hash, 1, 15); // // non-negative int8
return StoredFile::NormalizeGunid($res); // $hsd = substr($hash, 0, 1);
// $res = dechex(hexdec($hsd)>>1).substr($hash, 1, 15);
// return StoredFile::NormalizeGunid($res);
} }
@ -1308,10 +1344,10 @@ class StoredFile {
* *
* @return string * @return string
*/ */
public static function NormalizeGunid($p_gunid) // public static function NormalizeGunid($p_gunid)
{ // {
return str_pad($p_gunid, 16, "0", STR_PAD_LEFT); // return str_pad($p_gunid, 16, "0", STR_PAD_LEFT);
} // }
/** /**
@ -1386,7 +1422,7 @@ class StoredFile {
return $this->state; return $this->state;
} }
$sql = "SELECT state FROM ".$CC_CONFIG['filesTable'] $sql = "SELECT state FROM ".$CC_CONFIG['filesTable']
." WHERE gunid=x'$p_gunid'::bigint"; ." WHERE gunid='$p_gunid'";
return $CC_DBC->getOne($sql); return $CC_DBC->getOne($sql);
} }
@ -1405,7 +1441,7 @@ class StoredFile {
return $this->name; return $this->name;
} }
$sql = "SELECT name FROM ".$CC_CONFIG['filesTable'] $sql = "SELECT name FROM ".$CC_CONFIG['filesTable']
." WHERE gunid=x'$p_gunid'::bigint"; ." WHERE gunid='$p_gunid'";
return $CC_DBC->getOne($sql); return $CC_DBC->getOne($sql);
} }
@ -1416,18 +1452,18 @@ class StoredFile {
* *
* @return string * @return string
*/ */
private function _getResDir() // private function _getResDir()
{ // {
global $CC_CONFIG, $CC_DBC; // global $CC_CONFIG, $CC_DBC;
$resDir = $CC_CONFIG['storageDir']."/".substr($this->gunid, 0, 3); // $resDir = $CC_CONFIG['storageDir']."/".substr($this->gunid, 0, 3);
//$this->gb->debugLog("$resDir"); // //$this->gb->debugLog("$resDir");
// see Transport::_getResDir too for resDir name create code // // see Transport::_getResDir too for resDir name create code
if (!is_dir($resDir)) { // if (!is_dir($resDir)) {
mkdir($resDir, 02775); // mkdir($resDir, 02775);
chmod($resDir, 02775); // chmod($resDir, 02775);
} // }
return $resDir; // return $resDir;
} // }
/** /**
@ -1472,7 +1508,6 @@ class StoredFile {
private function _getAccessFileName($p_token, $p_ext='EXT') private function _getAccessFileName($p_token, $p_ext='EXT')
{ {
global $CC_CONFIG; global $CC_CONFIG;
$token = StoredFile::NormalizeGunid($p_token);
return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; return $CC_CONFIG['accessDir']."/$p_token.$p_ext";
} }

View File

@ -9,7 +9,7 @@ DROP TABLE "cc_access" CASCADE;
CREATE TABLE "cc_access" CREATE TABLE "cc_access"
( (
"id" serial NOT NULL, "id" serial NOT NULL,
"gunid" INT8, "gunid" CHAR(32),
"token" INT8, "token" INT8,
"chsum" CHAR(32) default '' NOT NULL, "chsum" CHAR(32) default '' NOT NULL,
"ext" VARCHAR(128) default '' NOT NULL, "ext" VARCHAR(128) default '' NOT NULL,
@ -61,10 +61,11 @@ DROP TABLE "cc_files" CASCADE;
CREATE TABLE "cc_files" CREATE TABLE "cc_files"
( (
"id" serial NOT NULL, "id" serial NOT NULL,
"gunid" INT8 NOT NULL, "gunid" CHAR(32) NOT NULL,
"name" VARCHAR(255) default '' NOT NULL, "name" VARCHAR(255) default '' NOT NULL,
"mime" VARCHAR(255) default '' NOT NULL, "mime" VARCHAR(255) default '' NOT NULL,
"ftype" VARCHAR(128) default '' NOT NULL, "ftype" VARCHAR(128) default '' NOT NULL,
"filepath" TEXT default '',
"state" VARCHAR(128) default 'empty' NOT NULL, "state" VARCHAR(128) default 'empty' NOT NULL,
"currentlyaccessing" INTEGER default 0 NOT NULL, "currentlyaccessing" INTEGER default 0 NOT NULL,
"editedby" INTEGER, "editedby" INTEGER,
@ -339,7 +340,7 @@ CREATE TABLE "cc_trans"
"target" VARCHAR(255), "target" VARCHAR(255),
"rtrtok" CHAR(16), "rtrtok" CHAR(16),
"mdtrtok" CHAR(16), "mdtrtok" CHAR(16),
"gunid" INT8, "gunid" CHAR(32),
"pdtoken" INT8, "pdtoken" INT8,
"url" VARCHAR(255), "url" VARCHAR(255),
"localfile" VARCHAR(255), "localfile" VARCHAR(255),

View File

@ -3,7 +3,7 @@
<database name="campcaster" defaultIdMethod="native"> <database name="campcaster" defaultIdMethod="native">
<table name="cc_access" phpName="CcAccess"> <table name="cc_access" phpName="CcAccess">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/> <column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="gunid" phpName="Gunid" type="BIGINT" required="false"/> <column name="gunid" phpName="Gunid" type="CHAR" size="32" required="false"/>
<column name="token" phpName="Token" type="BIGINT" required="false"/> <column name="token" phpName="Token" type="BIGINT" required="false"/>
<column name="chsum" phpName="Chsum" type="CHAR" size="32" required="true" defaultValue=""/> <column name="chsum" phpName="Chsum" type="CHAR" size="32" required="true" defaultValue=""/>
<column name="ext" phpName="Ext" type="VARCHAR" size="128" required="true" defaultValue=""/> <column name="ext" phpName="Ext" type="VARCHAR" size="128" required="true" defaultValue=""/>
@ -33,10 +33,11 @@
</table> </table>
<table name="cc_files" phpName="CcFiles"> <table name="cc_files" phpName="CcFiles">
<column name="id" phpName="DbId" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/> <column name="id" phpName="DbId" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="gunid" phpName="Gunid" type="BIGINT" required="true"/> <column name="gunid" phpName="Gunid" type="char" size="32" required="true"/>
<column name="name" phpName="Name" type="VARCHAR" size="255" required="true" defaultValue=""/> <column name="name" phpName="Name" type="VARCHAR" size="255" required="true" defaultValue=""/>
<column name="mime" phpName="Mime" type="VARCHAR" size="255" required="true" defaultValue=""/> <column name="mime" phpName="Mime" type="VARCHAR" size="255" required="true" defaultValue=""/>
<column name="ftype" phpName="Ftype" type="VARCHAR" size="128" required="true" defaultValue=""/> <column name="ftype" phpName="Ftype" type="VARCHAR" size="128" required="true" defaultValue=""/>
<column name="filepath" phpName="filepath" type="LONGVARCHAR" required="false" defaultValue=""/>
<column name="state" phpName="State" type="VARCHAR" size="128" required="true" defaultValue="empty"/> <column name="state" phpName="State" type="VARCHAR" size="128" required="true" defaultValue="empty"/>
<column name="currentlyaccessing" phpName="Currentlyaccessing" type="INTEGER" required="true" defaultValue="0"/> <column name="currentlyaccessing" phpName="Currentlyaccessing" type="INTEGER" required="true" defaultValue="0"/>
<column name="editedby" phpName="Editedby" type="INTEGER" required="false"/> <column name="editedby" phpName="Editedby" type="INTEGER" required="false"/>
@ -232,7 +233,7 @@
<column name="target" phpName="Target" type="VARCHAR" size="255" required="false" defaultValue="NULL"/> <column name="target" phpName="Target" type="VARCHAR" size="255" required="false" defaultValue="NULL"/>
<column name="rtrtok" phpName="Rtrtok" type="CHAR" size="16" required="false" defaultValue="NULL"/> <column name="rtrtok" phpName="Rtrtok" type="CHAR" size="16" required="false" defaultValue="NULL"/>
<column name="mdtrtok" phpName="Mdtrtok" type="CHAR" size="16" required="false"/> <column name="mdtrtok" phpName="Mdtrtok" type="CHAR" size="16" required="false"/>
<column name="gunid" phpName="Gunid" type="BIGINT" required="false"/> <column name="gunid" phpName="Gunid" type="char" size="32" required="false"/>
<column name="pdtoken" phpName="Pdtoken" type="BIGINT" required="false"/> <column name="pdtoken" phpName="Pdtoken" type="BIGINT" required="false"/>
<column name="url" phpName="Url" type="VARCHAR" size="255" required="false"/> <column name="url" phpName="Url" type="VARCHAR" size="255" required="false"/>
<column name="localfile" phpName="Localfile" type="VARCHAR" size="255" required="false"/> <column name="localfile" phpName="Localfile" type="VARCHAR" size="255" required="false"/>

View File

@ -137,7 +137,7 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly =
// Check for non-supported file type // Check for non-supported file type
if (!preg_match('/\.(ogg|mp3)$/i', $p_filepath, $var)) { if (!preg_match('/\.(ogg|mp3)$/i', $p_filepath, $var)) {
echo "IGNORED: $p_filepath\n"; echo "IGNORED: [xxxxx] $p_filepath\n";
//echo " * WARNING: File extension not supported - skipping file: $p_filepath\n"; //echo " * WARNING: File extension not supported - skipping file: $p_filepath\n";
return; return;
} }