Skip to content

Commit

Permalink
log import action
Browse files Browse the repository at this point in the history
  • Loading branch information
Aestu committed Nov 5, 2016
1 parent 197b020 commit 8054ca6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions application/controllers/admin/dataentry.php
Expand Up @@ -376,6 +376,12 @@ public function import($surveyid)
{
$targetResponse[$targetField] = $sourceResponse[$sourceField];
}

$beforeDataEntryImport = new PluginEvent('beforeDataEntryImport');
$beforeDataEntryImport->set('iSurveyID',$iSurveyId);
$beforeDataEntryImport->set('oModel',$targetResponse);
App()->getPluginManager()->dispatchEvent($beforeDataEntryImport);

$imported++;
$targetResponse->save();
$aSRIDConversions[$iOldID]=$targetResponse->id;
Expand Down
5 changes: 5 additions & 0 deletions application/helpers/admin/import_helper.php
Expand Up @@ -1936,6 +1936,11 @@ function CSVImportResponses($sFullFilePath,$iSurveyId,$aOptions=array())
}
if($oSurvey->save())
{
$beforeDataEntryImport = new PluginEvent('beforeDataEntryImport');
$beforeDataEntryImport->set('iSurveyID',$iSurveyId);
$beforeDataEntryImport->set('oModel',$oSurvey);
App()->getPluginManager()->dispatchEvent($beforeDataEntryImport);

$oTransaction->commit();
if($bExistingsId && $aOptions['sExistingId']!='renumber')
{
Expand Down
40 changes: 38 additions & 2 deletions plugins/AuditLog/AuditLog.php
Expand Up @@ -33,12 +33,17 @@ class AuditLog extends \ls\pluginmanager\PluginBase {
),
'AuditLog_Log_DataEntryCreate' => array(
'type' => 'checkbox',
'label' => 'Log if a survey admin create a response',
'label' => 'Log if a survey admin creates a response',
'default' => '1',
),
'AuditLog_Log_DataEntryUpdate' => array(
'type' => 'checkbox',
'label' => 'Log if a survey admin modify a response',
'label' => 'Log if a survey admin modifies a response',
'default' => '1',
),
'AuditLog_Log_DataEntryImport' => array(
'type' => 'checkbox',
'label' => 'Log if a survey admin imports responses',
'default' => '1',
),
'AuditLog_Log_TokenSave' => array(
Expand Down Expand Up @@ -84,6 +89,7 @@ public function init() {
$this->subscribe('beforePermissionSetSave');
$this->subscribe('beforeDataEntryCreate');
$this->subscribe('beforeDataEntryUpdate');
$this->subscribe('beforeDataEntryImport');
$this->subscribe('beforeTokenSave');
$this->subscribe('beforeTokenDelete');
$this->subscribe('beforeParticipantSave');
Expand Down Expand Up @@ -336,6 +342,36 @@ public function beforeDataEntryUpdate()
}
}


/**
* Log import responses
* @return unknown_type
*/
public function beforeDataEntryImport()
{
$event = $this->getEvent();
$iSurveyID=$event->get('iSurveyID');
if (!$this->checkSetting('AuditLog_Log_DataEntryImport') || !$this->get('auditing', 'Survey', $iSurveyID, false)) {
return;
}

$oCurrentUser = $this->api->getCurrentUser();
$currentUID = $oCurrentUser ? $oCurrentUser->uid : null;

$oModel = $this->getEvent()->get('oModel');
$aValues = $oModel->getAttributes();
if (count($aValues)){
$oAutoLog = $this->api->newModel($this, 'log');
$oAutoLog->uid=$currentUID;
$oAutoLog->entity='survey_' . $iSurveyID;
$oAutoLog->action="import";
$oAutoLog->newvalues=json_encode($aValues);
// $oAutoLog->reason=App()->request->getPost("reason");
$oAutoLog->fields=implode(',',array_keys($aValues));
$oAutoLog->save();
}
}

/**
* Function catches if a participant of a particular survey was modified or created
* All data is saved - only the password hash is anonymized for security reasons
Expand Down

0 comments on commit 8054ca6

Please sign in to comment.