CC-3230: Show appropriate error message if disk is full when attempting to upload files via the web UI
- updated formating of file, removed tabs in favour of four spaces for some lines.
This commit is contained in:
parent
31abc21aaa
commit
15552319aa
|
@ -82,7 +82,7 @@ class Application_Model_StoredFile {
|
||||||
* @param array $p_md
|
* @param array $p_md
|
||||||
* example: $p_md['MDATA_KEY_URL'] = 'http://www.fake.com'
|
* example: $p_md['MDATA_KEY_URL'] = 'http://www.fake.com'
|
||||||
*/
|
*/
|
||||||
public function setMetadata($p_md=null)
|
public function setMetadata($p_md=null)
|
||||||
{
|
{
|
||||||
if (is_null($p_md)) {
|
if (is_null($p_md)) {
|
||||||
$this->setDbColMetadata();
|
$this->setDbColMetadata();
|
||||||
|
@ -105,7 +105,7 @@ class Application_Model_StoredFile {
|
||||||
* @param array $p_md
|
* @param array $p_md
|
||||||
* example: $p_md['url'] = 'http://www.fake.com'
|
* example: $p_md['url'] = 'http://www.fake.com'
|
||||||
*/
|
*/
|
||||||
public function setDbColMetadata($p_md=null)
|
public function setDbColMetadata($p_md=null)
|
||||||
{
|
{
|
||||||
if (is_null($p_md)) {
|
if (is_null($p_md)) {
|
||||||
foreach ($this->_dbMD as $dbColumn => $propelColumn) {
|
foreach ($this->_dbMD as $dbColumn => $propelColumn) {
|
||||||
|
@ -627,7 +627,7 @@ class Application_Model_StoredFile {
|
||||||
$fromTable = $unionTable;
|
$fromTable = $unionTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables);
|
$results = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables);
|
||||||
|
|
||||||
|
|
||||||
foreach ($results['aaData'] as &$row) {
|
foreach ($results['aaData'] as &$row) {
|
||||||
|
@ -666,77 +666,77 @@ class Application_Model_StoredFile {
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function searchFiles($displayColumns, $fromTable, $data)
|
public static function searchFiles($displayColumns, $fromTable, $data)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
|
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
if ($data["sSearch"] !== "") {
|
if ($data["sSearch"] !== "") {
|
||||||
$searchTerms = explode(" ", $data["sSearch"]);
|
$searchTerms = explode(" ", $data["sSearch"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectorCount = "SELECT COUNT(*) ";
|
$selectorCount = "SELECT COUNT(*) ";
|
||||||
$selectorRows = "SELECT ".join(",", $displayColumns)." ";
|
$selectorRows = "SELECT ".join(",", $displayColumns)." ";
|
||||||
|
|
||||||
$sql = $selectorCount." FROM ".$fromTable;
|
$sql = $selectorCount." FROM ".$fromTable;
|
||||||
$sqlTotalRows = $sql;
|
$sqlTotalRows = $sql;
|
||||||
|
|
||||||
if (isset($searchTerms)) {
|
if (isset($searchTerms)) {
|
||||||
$searchCols = array();
|
$searchCols = array();
|
||||||
for ($i = 0; $i < $data["iColumns"]; $i++) {
|
for ($i = 0; $i < $data["iColumns"]; $i++) {
|
||||||
if ($data["bSearchable_".$i] == "true") {
|
if ($data["bSearchable_".$i] == "true") {
|
||||||
$searchCols[] = $data["mDataProp_{$i}"];
|
$searchCols[] = $data["mDataProp_{$i}"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$outerCond = array();
|
$outerCond = array();
|
||||||
|
|
||||||
foreach ($searchTerms as $term) {
|
foreach ($searchTerms as $term) {
|
||||||
$innerCond = array();
|
$innerCond = array();
|
||||||
|
|
||||||
foreach ($searchCols as $col) {
|
foreach ($searchCols as $col) {
|
||||||
$escapedTerm = pg_escape_string($term);
|
$escapedTerm = pg_escape_string($term);
|
||||||
$innerCond[] = "{$col}::text ILIKE '%{$escapedTerm}%'";
|
$innerCond[] = "{$col}::text ILIKE '%{$escapedTerm}%'";
|
||||||
}
|
}
|
||||||
$outerCond[] = "(".join(" OR ", $innerCond).")";
|
$outerCond[] = "(".join(" OR ", $innerCond).")";
|
||||||
}
|
}
|
||||||
$where[] = "(".join(" AND ", $outerCond).")";
|
$where[] = "(".join(" AND ", $outerCond).")";
|
||||||
}
|
}
|
||||||
// End Where clause
|
// End Where clause
|
||||||
|
|
||||||
// Order By clause
|
// Order By clause
|
||||||
$orderby = array();
|
$orderby = array();
|
||||||
for ($i = 0; $i < $data["iSortingCols"]; $i++){
|
for ($i = 0; $i < $data["iSortingCols"]; $i++){
|
||||||
$num = $data["iSortCol_".$i];
|
$num = $data["iSortCol_".$i];
|
||||||
$orderby[] = $data["mDataProp_{$num}"]." ".$data["sSortDir_".$i];
|
$orderby[] = $data["mDataProp_{$num}"]." ".$data["sSortDir_".$i];
|
||||||
}
|
}
|
||||||
$orderby[] = "id";
|
$orderby[] = "id";
|
||||||
$orderby = join("," , $orderby);
|
$orderby = join("," , $orderby);
|
||||||
// End Order By clause
|
// End Order By clause
|
||||||
|
|
||||||
if (count($where) > 0) {
|
if (count($where) > 0) {
|
||||||
$where = join(" AND ", $where);
|
$where = join(" AND ", $where);
|
||||||
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$where;
|
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$where;
|
||||||
$sqlTotalDisplayRows = $sql;
|
$sqlTotalDisplayRows = $sql;
|
||||||
|
|
||||||
$sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
$sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$r = $con->query($sqlTotalRows);
|
$r = $con->query($sqlTotalRows);
|
||||||
$totalRows = $r->fetchColumn(0);
|
$totalRows = $r->fetchColumn(0);
|
||||||
|
|
||||||
if (isset($sqlTotalDisplayRows)) {
|
if (isset($sqlTotalDisplayRows)) {
|
||||||
$r = $con->query($sqlTotalDisplayRows);
|
$r = $con->query($sqlTotalDisplayRows);
|
||||||
$totalDisplayRows = $r->fetchColumn(0);
|
$totalDisplayRows = $r->fetchColumn(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$totalDisplayRows = $totalRows;
|
$totalDisplayRows = $totalRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = $con->query($sql);
|
$r = $con->query($sql);
|
||||||
$r->setFetchMode(PDO::FETCH_ASSOC);
|
$r->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
$results = $r->fetchAll();
|
$results = $r->fetchAll();
|
||||||
|
@ -744,109 +744,109 @@ class Application_Model_StoredFile {
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
Logging::log($e->getMessage());
|
Logging::log($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
//display sql executed in airtime log for testing
|
//display sql executed in airtime log for testing
|
||||||
Logging::log($sql);
|
Logging::log($sql);
|
||||||
|
|
||||||
return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function uploadFile($p_targetDir)
|
public static function uploadFile($p_targetDir)
|
||||||
{
|
{
|
||||||
// HTTP headers for no cache etc
|
// HTTP headers for no cache etc
|
||||||
header('Content-type: text/plain; charset=UTF-8');
|
header('Content-type: text/plain; charset=UTF-8');
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||||
header("Pragma: no-cache");
|
header("Pragma: no-cache");
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
$cleanupTargetDir = false; // Remove old files
|
$cleanupTargetDir = false; // Remove old files
|
||||||
$maxFileAge = 60 * 60; // Temp file age in seconds
|
$maxFileAge = 60 * 60; // Temp file age in seconds
|
||||||
|
|
||||||
// 5 minutes execution time
|
// 5 minutes execution time
|
||||||
@set_time_limit(5 * 60);
|
@set_time_limit(5 * 60);
|
||||||
// usleep(5000);
|
// usleep(5000);
|
||||||
|
|
||||||
// Get parameters
|
// Get parameters
|
||||||
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
|
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
|
||||||
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
|
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
|
||||||
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
|
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
|
||||||
Logging::log(__FILE__.":uploadFile(): filename=$fileName to $p_targetDir");
|
Logging::log(__FILE__.":uploadFile(): filename=$fileName to $p_targetDir");
|
||||||
// Clean the fileName for security reasons
|
// Clean the fileName for security reasons
|
||||||
//this needs fixing for songs not in ascii.
|
//this needs fixing for songs not in ascii.
|
||||||
//$fileName = preg_replace('/[^\w\._]+/', '', $fileName);
|
//$fileName = preg_replace('/[^\w\._]+/', '', $fileName);
|
||||||
|
|
||||||
// Create target dir
|
// Create target dir
|
||||||
if (!file_exists($p_targetDir))
|
if (!file_exists($p_targetDir))
|
||||||
@mkdir($p_targetDir);
|
@mkdir($p_targetDir);
|
||||||
|
|
||||||
// Remove old temp files
|
// Remove old temp files
|
||||||
if (is_dir($p_targetDir) && ($dir = opendir($p_targetDir))) {
|
if (is_dir($p_targetDir) && ($dir = opendir($p_targetDir))) {
|
||||||
while (($file = readdir($dir)) !== false) {
|
while (($file = readdir($dir)) !== false) {
|
||||||
$filePath = $p_targetDir . DIRECTORY_SEPARATOR . $file;
|
$filePath = $p_targetDir . DIRECTORY_SEPARATOR . $file;
|
||||||
|
|
||||||
// Remove temp files if they are older than the max age
|
// Remove temp files if they are older than the max age
|
||||||
if (preg_match('/\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
|
if (preg_match('/\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
|
||||||
@unlink($filePath);
|
@unlink($filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir($dir);
|
closedir($dir);
|
||||||
} else
|
} else
|
||||||
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
|
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
|
||||||
|
|
||||||
// Look for the content type header
|
// Look for the content type header
|
||||||
if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
|
if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
|
||||||
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
|
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
|
||||||
|
|
||||||
if (isset($_SERVER["CONTENT_TYPE"]))
|
if (isset($_SERVER["CONTENT_TYPE"]))
|
||||||
$contentType = $_SERVER["CONTENT_TYPE"];
|
$contentType = $_SERVER["CONTENT_TYPE"];
|
||||||
|
|
||||||
// create temp file name (CC-3086)
|
// create temp file name (CC-3086)
|
||||||
// we are not using mktemp command anymore.
|
// we are not using mktemp command anymore.
|
||||||
// plupload support unique_name feature.
|
// plupload support unique_name feature.
|
||||||
$tempFilePath= $p_targetDir . DIRECTORY_SEPARATOR . $fileName;
|
$tempFilePath= $p_targetDir . DIRECTORY_SEPARATOR . $fileName;
|
||||||
|
|
||||||
if (strpos($contentType, "multipart") !== false) {
|
if (strpos($contentType, "multipart") !== false) {
|
||||||
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
|
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
|
||||||
// Open temp file
|
// Open temp file
|
||||||
$out = fopen($tempFilePath, $chunk == 0 ? "wb" : "ab");
|
$out = fopen($tempFilePath, $chunk == 0 ? "wb" : "ab");
|
||||||
if ($out) {
|
if ($out) {
|
||||||
// Read binary input stream and append it to temp file
|
// Read binary input stream and append it to temp file
|
||||||
$in = fopen($_FILES['file']['tmp_name'], "rb");
|
$in = fopen($_FILES['file']['tmp_name'], "rb");
|
||||||
|
|
||||||
if ($in) {
|
if ($in) {
|
||||||
while ($buff = fread($in, 4096))
|
while ($buff = fread($in, 4096))
|
||||||
fwrite($out, $buff);
|
fwrite($out, $buff);
|
||||||
} else
|
} else
|
||||||
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
||||||
|
|
||||||
fclose($out);
|
fclose($out);
|
||||||
unlink($_FILES['file']['tmp_name']);
|
unlink($_FILES['file']['tmp_name']);
|
||||||
} else
|
} else
|
||||||
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
||||||
} else
|
} else
|
||||||
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
|
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
|
||||||
} else {
|
} else {
|
||||||
// Open temp file
|
// Open temp file
|
||||||
$out = fopen($tempFilePath, $chunk == 0 ? "wb" : "ab");
|
$out = fopen($tempFilePath, $chunk == 0 ? "wb" : "ab");
|
||||||
if ($out) {
|
if ($out) {
|
||||||
// Read binary input stream and append it to temp file
|
// Read binary input stream and append it to temp file
|
||||||
$in = fopen("php://input", "rb");
|
$in = fopen("php://input", "rb");
|
||||||
|
|
||||||
if ($in) {
|
if ($in) {
|
||||||
while ($buff = fread($in, 4096))
|
while ($buff = fread($in, 4096))
|
||||||
fwrite($out, $buff);
|
fwrite($out, $buff);
|
||||||
} else
|
} else
|
||||||
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
||||||
|
|
||||||
fclose($out);
|
fclose($out);
|
||||||
} else
|
} else
|
||||||
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tempFilePath;
|
return $tempFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -873,8 +873,8 @@ class Application_Model_StoredFile {
|
||||||
$md5 = md5_file($audio_file);
|
$md5 = md5_file($audio_file);
|
||||||
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
|
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
|
||||||
if ($duplicate) {
|
if ($duplicate) {
|
||||||
if (PEAR::isError($duplicate)) {
|
if (PEAR::isError($duplicate)) {
|
||||||
$result = array("code" => 105, "message" => $duplicate->getMessage());
|
$result = array("code" => 105, "message" => $duplicate->getMessage());
|
||||||
}
|
}
|
||||||
if (file_exists($duplicate->getFilePath())) {
|
if (file_exists($duplicate->getFilePath())) {
|
||||||
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
|
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
|
||||||
|
@ -882,36 +882,35 @@ class Application_Model_StoredFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($result)){//The file has no duplicate, so procceed to copy.
|
if (!isset($result)){//The file has no duplicate, so procceed to copy.
|
||||||
$storDir = Application_Model_MusicDir::getStorDir();
|
$storDir = Application_Model_MusicDir::getStorDir();
|
||||||
$stor = $storDir->getDirectory();
|
$stor = $storDir->getDirectory();
|
||||||
|
|
||||||
//check to see if there is enough space in $stor to continue.
|
//check to see if there is enough space in $stor to continue.
|
||||||
$result = Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
|
$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
|
if (!isset($result)){//if result not set then there's enough disk space to copy the file over
|
||||||
$stor .= "/organize";
|
$stor .= "/organize";
|
||||||
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
|
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
|
||||||
|
|
||||||
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
|
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
|
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
|
||||||
$r = @rename($audio_file, $audio_stor);
|
$r = @rename($audio_file, $audio_stor);
|
||||||
|
|
||||||
if ($r === false) {
|
if ($r === false) {
|
||||||
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
|
#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.
|
#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
|
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.");
|
$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;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getFileCount()
|
public static function getFileCount()
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG["filesTable"];
|
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG["filesTable"];
|
||||||
return $CC_DBC->GetOne($sql);
|
return $CC_DBC->GetOne($sql);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue