Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Martin Konecny 2012-02-16 14:59:23 -05:00
commit e38682b9e4
4 changed files with 50 additions and 34 deletions

View File

@ -407,7 +407,10 @@ class ApiController extends Zend_Controller_Action
$tempFileName = basename($tempFilePath);
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
$result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
if (isset($result)){
die('{"jsonrpc" : "2.0", "error" : {"code": '.$result[code].', "message" : "'.$result[message].'"}}');
}
}
public function uploadRecordedAction()

View File

@ -38,8 +38,10 @@ class PluploadController extends Zend_Controller_Action
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
$filename = $this->_getParam('name');
$tempname = $this->_getParam('tempname');
Application_Model_StoredFile::copyFileToStor($upload_dir, $filename, $tempname);
$result = Application_Model_StoredFile::copyFileToStor($upload_dir, $filename, $tempname);
if (isset($result)){
die('{"jsonrpc" : "2.0", "error" : {"code": '.$result[code].', "message" : "'.$result[message].'"}}');
}
die('{"jsonrpc" : "2.0"}');
}
}

View File

@ -583,7 +583,7 @@ class Application_Model_StoredFile {
{
global $CC_CONFIG;
$displayData = array("track_title", "artist_name", "album_title", "genre", "length", "year", "utime", "mtime", "ftype");
$displayData = array("track_title", "artist_name", "album_title", "genre", "length", "year", "utime", "mtime", "ftype", "track_number");
$plSelect = "SELECT ";
$fileSelect = "SELECT ";
@ -610,6 +610,9 @@ class Application_Model_StoredFile {
} else if ($key === "mtime") {
$plSelect .= $key.", ";
$fileSelect .= $key.", ";
} else if ($key === "track_number") {
$plSelect .= "NULL AS ".$key.", ";
$fileSelect .= $key.", ";
} else {
$plSelect .= "NULL AS ".$key.", ";
$fileSelect .= $key.", ";
@ -621,10 +624,11 @@ class Application_Model_StoredFile {
UNION
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS";
$results = Application_Model_StoredFile::searchFiles($fromTable, $datatables);
$results = Application_Model_StoredFile::searchFiles($fromTable, $datatables);
foreach($results['aaData'] as &$row){
$row['id'] = intval($row['id']);
//$length = new DateTime($row['length']);
@ -733,6 +737,7 @@ class Application_Model_StoredFile {
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
}
//display sql executed in airtime log for testing
//Logging::log($sql);
$results = $CC_DBC->getAll($sql);
@ -851,11 +856,12 @@ class Application_Model_StoredFile {
$freeSpace = disk_free_space($destination_folder);
$fileSize = filesize($audio_file);
if ( $freeSpace < $fileSize ){
$freeSpace = floor($freeSpace/1024/1024);
$fileSize = floor($fileSize/1024/1024);
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, there was '.$freeSpace.'MB disk space left the file you are uploadings size is '.$fileSize.'MB."}}');
if ( $freeSpace < $fileSize){
$freeSpace = ceil($freeSpace/1024/1024);
$fileSize = ceil($fileSize/1024/1024);
$result = array("code" => 107, "message" => "The file was not uploaded, there is ".$freeSpace."MB of disk space left and the file you are uploading has a size of ".$fileSize."MB.");
}
return $result;
}
public static function copyFileToStor($p_targetDir, $fileName, $tempname){
@ -864,35 +870,39 @@ class Application_Model_StoredFile {
$md5 = md5_file($audio_file);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
if ($duplicate) {
if (PEAR::isError($duplicate)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
if (PEAR::isError($duplicate)) {
$result = array("code" => 105, "message" => $duplicate->getMessage());
}
if (file_exists($duplicate->getFilePath())) {
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named \"' . $duplicateName . '\" already exists on the server."}}');
$result = array( "code" => 106, "message" => "An identical audioclip named '$duplicateName' already exists on the server.");
}
}
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
//check to see if there is enough space in $stor to continue.
Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
if (!isset($result)){//The file has no duplicate, so procceed to copy.
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
//check to see if there is enough space in $stor to continue.
$result = Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
if (!isset($result)){//if result not set then there's enough disk space to copy the file over
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
$r = @rename($audio_file, $audio_stor);
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
$r = @rename($audio_file, $audio_stor);
if ($r === false) {
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
#warn the user that the file wasn't uploaded and they should check if there is enough disk space.
unlink($audio_file);//remove the file from the organize after failed rename
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, this error will occur if the computer hard drive does not have enough disk space."}}');
}
if ($r === false) {
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
#warn the user that the file wasn't uploaded and they should check if there is enough disk space.
unlink($audio_file);//remove the file from the organize after failed rename
$result = array("code" => 108, "message" => "The file was not uploaded, this error will occur if the computer hard drive does not have enough disk space.");
}
}
}
return $result;
//$r = @copy($audio_file, $audio_stor);
//$r = @unlink($audio_file);
}

View File

@ -309,7 +309,8 @@ function createDataTable(data) {
/* Year */ {"sTitle": "Year", "sName": "year", "mDataProp": "year", "sClass": "library_year"},
/* Length */ {"sTitle": "Length", "sName": "length", "mDataProp": "length", "sClass": "library_length"},
/* Upload Time */ {"sTitle": "Uploaded", "sName": "utime", "mDataProp": "utime", "sClass": "library_upload_time"},
/* Last Modified */ {"sTitle": "Last Modified", "sName": "mtime", "bVisible": false, "mDataProp": "mtime", "sClass": "library_modified_time"}
/* Last Modified */ {"sTitle": "Last Modified", "sName": "mtime", "bVisible": false, "mDataProp": "mtime", "sClass": "library_modified_time"},
/* Track Number */ {"sTitle": "Track", "sName": "track", "bSearchable": false, "bVisible": false, "mDataProp": "track_number", "sClass": "library_track"}
],
"aaSorting": [[2,'asc']],
"sPaginationType": "full_numbers",
@ -358,7 +359,7 @@ function createDataTable(data) {
"oColReorder": {
"iFixedColumns": 2,
"aiOrder": [ 0,1,2,3,4,5,6,7,8,9 ]
"aiOrder": [ 0,1,2,3,4,5,6,7,8,9,10 ]
}
});