From fae5b15a9f8f00245a0dc7377db5d3e8371051f8 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 28 Apr 2014 14:44:52 -0400 Subject: [PATCH] CC-5821: Airtime Analyzer: Ftp-uploaded folder doesn't get removed from organize $_FILES does not store the original file path so we were losing the folder name. Fixed by explicitly passing the full filepath in via the ftp-upload-hook.sh script --- .../rest/controllers/MediaController.php | 21 +++++++++++++------ .../airtime_analyzer/tools/ftp-upload-hook.sh | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index ecd538a12..eec9e1b10 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -136,7 +136,19 @@ class Rest_MediaController extends Zend_Rest_Controller $file->save(); return; } else { - + /* If full_path is set, the post request came from ftp. + * Users are allowed to upload folders via ftp. If this is the case + * we need to include the folder name with the file name, otherwise + * files won't get removed from the organize folder. + */ + if (isset($whiteList["full_path"])) { + $fullPath = $whiteList["full_path"]; + $basePath = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."/srv/airtime/stor/organize/" : "/srv/airtime/stor/organize/"; + $relativePath = substr($fullPath, strlen($basePath)); + } else { + $relativePath = $_FILES["file"]["name"]; + } + $file->fromArray($whiteList); $file->setDbOwnerId($this->getOwnerId()); $now = new DateTime("now", new DateTimeZone("UTC")); @@ -146,8 +158,8 @@ class Rest_MediaController extends Zend_Rest_Controller $file->save(); $callbackUrl = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri() . "/" . $file->getPrimaryKey(); - - $this->processUploadedFile($callbackUrl, $_FILES["file"]["name"], $this->getOwnerId()); + + $this->processUploadedFile($callbackUrl, $relativePath, $this->getOwnerId()); $this->getResponse() ->setHttpResponseCode(201) @@ -365,9 +377,6 @@ class Rest_MediaController extends Zend_Rest_Controller Logging::error($e->getMessage()); return; } - - Logging::info($newTempFilePath); - //Logging::info("Old temp file path: " . $tempFilePath); //Dispatch a message to airtime_analyzer through RabbitMQ, //notifying it that there's a new upload to process! diff --git a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh index e456d8be9..f5be38183 100755 --- a/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh +++ b/python_apps/airtime_analyzer/tools/ftp-upload-hook.sh @@ -28,7 +28,7 @@ post_file() { api_key=$(awk -F "= " '/api_key/ {print $2}' $instance_conf_path) - until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" -F "name=${filename}" + until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@${file_path}" -F "full_path=${file_path}" do retry_count=$[$retry_count+1] if [ $retry_count -ge $max_retry ]; then