Skip to content

Commit

Permalink
New feature #09235: Copy, export and import survey plugin settings (#816
Browse files Browse the repository at this point in the history
)

New feature #09235: Copy, export and import survey plugin settings
Dev: update the XML lss file
Dev: export using plugin name, not id
Dev: import with plugin name find id
Dev: must check with broken plugin
Dev: must review Plugin::model()->rules() a little
Dev: add rules to PluginSettings
  • Loading branch information
Shnoulle authored and LouisGac committed Oct 9, 2017
1 parent 3f8dc49 commit cfbe597
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
29 changes: 29 additions & 0 deletions application/helpers/admin/import_helper.php
Expand Up @@ -858,6 +858,7 @@ function XMLImportSurvey($sFullFilePath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
$results['quota']=0;
$results['quotals']=0;
$results['quotamembers']=0;
$results['plugin_settings']=0;
$results['survey_url_parameters']=0;
$results['importwarnings']=array();

Expand Down Expand Up @@ -1538,6 +1539,34 @@ function XMLImportSurvey($sFullFilePath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
}
}

// Import Survey plugins settings
if(isset($xml->plugin_settings)) {
$pluginNamesWarning=array(); // To shown not exist warning only one time.
foreach ($xml->plugin_settings->rows->row as $row)
{
// Find plugin id
if(isset($row->name)) {
$oPlugin = Plugin::model()->find("name = :name",array(":name"=>$row->name));
if($oPlugin) {
$setting = new PluginSetting;
$setting->plugin_id = $oPlugin->id;
$setting->model = "Survey";
$setting->model_id = $iNewSID;
$setting->key = (string) $row->key;
$setting->value = (string) $row->value;
if($setting->save()) {
$results['plugin_settings']++;
} else {
$results['importwarnings'][] = sprintf(gT("An error happen when try to save %s for plugin %s"),CHtml::encode($row->key),CHtml::encode($row->name));
}
} elseif(!isset($pluginNamesWarning[(string)$row->name])) {
$results['importwarnings'][] = sprintf(gT("Plugin %s didn't exist, settings not imported"),CHtml::encode($row->name));
$pluginNamesWarning[(string)$row->name] = 1;
}
}
}
}

// Set survey rights
Permission::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'],$iNewSID);
$aOldNewFieldmap=reverseTranslateFieldNames($iOldSID,$iNewSID,$aGIDReplacements,$aQIDReplacements);
Expand Down
6 changes: 6 additions & 0 deletions application/helpers/export_helper.php
Expand Up @@ -744,6 +744,12 @@ function surveyGetXMLStructure($iSurveyID, $xmlwriter, $exclude=array())
WHERE sid={$iSurveyID}";
buildXMLFromQuery($xmlwriter,$slsquery);

// Survey plugin(s)
$slsquery = " SELECT settings.id,name,".Yii::app()->db->quoteColumnName("key").",".Yii::app()->db->quoteColumnName("value")
. " FROM {{plugin_settings}} as settings JOIN {{plugins}} as plugins ON plugins.id = settings.plugin_id"
. " WHERE model='Survey' and model_id=$iSurveyID";
buildXMLFromQuery($xmlwriter,$slsquery);

}

/**
Expand Down
34 changes: 31 additions & 3 deletions application/models/PluginSetting.php
Expand Up @@ -14,8 +14,16 @@
*/

/**
* This is the model class for table "{{plugin_settings}}".
* Class PluginSetting
*
* @property integer $id primary key
* @property integer $plugin_id see \Plugin
* @property string $model
* @property integer $model_id
* @property string $key
* @property string $value
*/

class PluginSetting extends CActiveRecord {

/**
Expand All @@ -25,8 +33,28 @@ class PluginSetting extends CActiveRecord {
public static function model($className = __CLASS__) {
return parent::model($className);
}


/**
* Returns the table's name
*
* @access public
* @return string
*/
public function tableName() {
return '{{plugin_settings}}';
}
}

/**
* Returns the validation rules for attributes.
* @return array[]
*/
public function rules() {
return array(
array('plugin_id','numerical', 'integerOnly'=>true), // 'allowEmpty'=>false ?
array('model','string', 'max'=>255,'allowEmpty'=>true),
array('model_id','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('key','string', 'max'=>255),
array('value','string'),
);
}
}
3 changes: 3 additions & 0 deletions application/views/admin/survey/importSurvey_view.php
Expand Up @@ -92,6 +92,9 @@
<tr><td><?php eT("Quotas");?>:</td><td><?php echo $aImportResults['quota'];?></td></tr>
<tr><td><?php eT("Quota members:");?></td><td><?php echo $aImportResults['quotamembers'];?></td></tr>
<tr><td><?php eT("Quota language settings:");?></td><td><?php echo $aImportResults['quotals'];?></td></tr>
<?php if(!empty($aImportResults['plugin_settings'])) { ?>
<tr><td><?php eT("Plugin settings:");?></td><td><?php echo $aImportResults['plugin_settings'];?></td></tr>
<?php } ?>
</table>
</div>
</div>
Expand Down

0 comments on commit cfbe597

Please sign in to comment.