View Issue Details

This bug affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
12563Bug reportsRemoteControlpublic2017-09-13 12:29
Reporterpardo_bsso Assigned ToLouisGac 
PrioritynoneSeverityfeature 
Status closedResolutionfixed 
Product Version2.67.x 
Summary12563: add_response does not process file attachments
Description

When adding a response using the add_response json rpc call, if it has file upload questions and they are formatted like the web uploader does, they are not moved from the temp folder to the uploads folder.

Steps To Reproduce

(using external service) Upload several files to tmp/upload
call add_response and set the upload file question to something like this (format changed so it looks better here):

[
{
"title": "",
"comment": "",
"size": "97.299",
"name": "theda-bara.jpg",
"filename": "fu_iqmasqdug6qf8kv",
"ext": "jpg"
}
]

The file is not moved to the uploads folder, so the user can not see it when processing the responses.

Additional Information

This is part of an open source app (hope to release before September) we are developing to process surveys without internet access and upload the responses later.

The attached patch is also available at

https://github.com/Cambalab/LimeSurvey/commit/57b626cae9e3fa22a30935a9a90819ced2aca991

I know it doesn't follow all of the commit message rules and the coding style (I used the same as the rest of the file) but I'd like to reach a good implementation before focusing on that.

Thanks!

TagsNo tags attached.
Attached Files
0001-Remote-Control-process-Survey-files-on-add_response.patch (2,318 bytes)   
From 57b626cae9e3fa22a30935a9a90819ced2aca991 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adri=C3=A1n=20Pardini?= <adrian@camba.coop>
Date: Tue, 25 Jul 2017 19:19:17 -0300
Subject: [PATCH 1/1] Remote Control: process Survey files on add_response()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the response data has fields for file attachments, move those files
to the final upload folder.

Signed-off-by: Adrián Pardini <adrian@camba.coop>
---
 .../helpers/remotecontrol/remotecontrol_handle.php | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php
index 53e97e7..f4ffe7d 100644
--- a/application/helpers/remotecontrol/remotecontrol_handle.php
+++ b/application/helpers/remotecontrol/remotecontrol_handle.php
@@ -2491,7 +2491,29 @@ class remotecontrol_handle
             $result_id = $survey_dynamic->insertRecords($aResponseData);
 
             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
                 return array('status' => 'Unable to add response');
         }
-- 
2.7.4

Bug heat4
Complete LimeSurvey version number (& build)2.67.2 8a45bd98a96240698374795eb79cee83e0198f77
I will donate to the project if issue is resolvedNo
BrowserFirefox 54
Database type & version261, MariaDB 10.0.29
Server OS (if known)Ubuntu 16.04
Webserver software & version (if known)nginx 1.10.3
PHP Versionphp-fpm , PHP 7.0.18-0ubuntu0.16.04.1

Users monitoring this issue

There are no users monitoring this issue.

Activities

pardo_bsso

pardo_bsso

2017-08-03 15:16

reporter   ~44275

See also 12564

LouisGac

LouisGac

2017-08-15 14:35

developer   ~44301

Fix committed to develop branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=23656

Related Changesets

LimeSurvey: develop 66c1871d

2017-08-15 14:35:34

Adrián Pardini


Committer: LouisGac Details Diff
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.
Affected Issues
12563
mod - application/helpers/remotecontrol/remotecontrol_handle.php Diff File

Issue History

Date Modified Username Field Change
2017-08-03 15:00 pardo_bsso New Issue
2017-08-03 15:00 pardo_bsso File Added: 0001-Remote-Control-process-Survey-files-on-add_response.patch
2017-08-03 15:16 pardo_bsso Note Added: 44275
2017-08-15 14:35 LouisGac Changeset attached => LimeSurvey develop 66c1871d
2017-08-15 14:35 LouisGac Note Added: 44301
2017-08-15 14:35 LouisGac Assigned To => LouisGac
2017-08-15 14:35 LouisGac Resolution open => fixed
2017-09-13 12:29 LouisGac Status new => resolved
2017-09-13 12:29 LouisGac Status resolved => closed