Skip to content

Commit

Permalink
New feature #12563 remote control: process files on add_response() (#793
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
pardo-bsso authored and LouisGac committed Aug 15, 2017
1 parent 931f92f commit 66c1871
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -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');
Expand Down

0 comments on commit 66c1871

Please sign in to comment.