From 66c1871d981128178f8cebe9ff91ff7bfb77d024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Pardini?= Date: Tue, 15 Aug 2017 09:35:34 -0300 Subject: [PATCH] New feature #12563 remote control: process files on add_response() (#793) Dev: When calling add_response(), if the response data has fields for file attachments, move those files to the final upload folder if they are not there. This assumes that the files are already present on the temporary upload folder. --- .../remotecontrol/remotecontrol_handle.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index 5fe811b36bb..6adb080b960 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -2468,10 +2468,30 @@ public function add_response($sSessionKey, $iSurveyID, $aResponseData) $aResponseData=array_intersect_key($aResponseData, array_flip($aBasicDestinationFields)); $result_id = $survey_dynamic->insertRecords($aResponseData); - if ($result_id) + if ($result_id) { + $oResponse = Response::model($iSurveyID)->findByAttributes(array('token' => $sToken, 'id' => $result_id)); + foreach ($oResponse->getFiles() as $aFile) { + $sUploadPath = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/"; + $sFileRealName = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/" . $aFile['filename']; + $sFileTempName = Yii::app()->getConfig('tempdir') . "/upload/" . $aFile['filename']; + + if (!file_exists($sFileRealName)) { + if (!is_dir($sUploadPath)) { + mkdir($sUploadPath, 0777, true); + } + + if (!rename($sFileTempName, $sFileRealName)) { + return array('status' => 'Unable to move files ' . $sFileTmpName . ' ' . $sFileRealName); + } + } + + } + return $result_id; - else + } + else { return array('status' => 'Unable to add response'); + } } else return array('status' => 'No permission');