Commit f5a615da authored by Chenu Denis's avatar Chenu Denis
Browse files

[feature] Save lss too

[feature] Allow save survey by txt file
parent 44b62a6e
......@@ -4,16 +4,18 @@ Backup activated survey on the server as lsa file.
## Usage
- Create a directory outside web (else everyone can get your bacjupo file)
- Create a directory outside web (else everyone can get your backuped file)
- Set plugin configuration
- Set complete directory name to _Local directory_
- Set the number of backup to keep
- Go to each survey you want to be backuped
- Plugin settings / backupSurveyLocally
- Check _Save the LSA file locally._
- Check _Backup survey locally._
- Alternatively : you can add a list of surveys id in your _Local directory_ name surveys.txt. Each survey id separated by new line
- Save your survey locally with PHP Cli : <code>php application/commands/console.php plugin --target=backupSurveyLocally</code>
If you use LimeSurvey version before 3.17.8, you need to be in LimeSurvey directory for call console.php.
Then for a cron script :
````
#!/bin/bash
......@@ -23,8 +25,8 @@ php application/commands/console.php plugin --target=backupSurveyLocally
## Home page, copyright and support
- HomePage <https://extensions.sondages.pro/>
- Copyright © 2019 Denis Chenu <https://sondages.pro> and [contributors](https://gitlab.com/SondagesPro/coreAndTools/backupSurveyLocally/-/graphs/master)
- Licence : GNU Affero General Public License <https://www.gnu.org/licenses/gpl-3.0.html>
- Copyright © 2019-2021 Denis Chenu <https://sondages.pro> and [contributors](https://gitlab.com/SondagesPro/coreAndTools/backupSurveyLocally/-/graphs/master)
- Licence : GNU Affero General Public License <https://www.gnu.org/licenses/agpl-3.0.html>
- Merge request on [Gitlab](https://gitlab.com/SondagesPro/coreAndTools/backupSurveyLocally/merge_requests)
- Issues on [Gitlab](https://gitlab.com/SondagesPro/coreAndTools/backupSurveyLocally/issues)
- [Professional support](https://support.sondages.pro/)
......@@ -5,7 +5,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2019-2021 Denis Chenu <https://www.sondages.pro>
* @license AGPL v3
* @version 1.0.5
* @version 1.1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
......@@ -86,20 +86,30 @@ class backupSurveyLocally extends PluginBase
}
/* lsa is zip */
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', $localDirectory.DIRECTORY_SEPARATOR."tmp".DIRECTORY_SEPARATOR);
define('PCLZIP_TEMPORARY_DIR', $localDirectory . DIRECTORY_SEPARATOR . "tmp" . DIRECTORY_SEPARATOR);
}
Yii::import('application.libraries.admin.pclzip', true);
$this->_directoryRotate($localDirectory,$this->get('backupNumber'));
/* Backup from DB */
$criteria = New CDbCriteria;
$criteria->compare('plugin_id',$this->id);
$criteria->compare(Yii::app()->getDb()->quoteColumnName('key'),'active');
$criteria->compare(Yii::app()->getDb()->quoteColumnName('value'),'Y',true);// Partial (saved json encoded)
$oSurveysToSave = \PluginSetting::model()->findAll($criteria);
foreach($oSurveysToSave as $oSurvey) {
$surveyId = $oSurvey->model_id;
$this->_saveSurvey($surveyId,$localDirectory);
}
/* Backup from txt file */
if(is_file($localDirectory . DIRECTORY_SEPARATOR . 'surveys.txt')) {
$surveystxt = file_get_contents($localDirectory . DIRECTORY_SEPARATOR . 'surveys.txt');
$surveyList = preg_split('/\n|\r/', $surveystxt, -1, PREG_SPLIT_NO_EMPTY);
foreach($surveyList as $surveyId) {
$this->_saveSurvey(trim($surveyId), $localDirectory);
}
}
}
/** Add the settings **/
public function beforeSurveySettings() {
......@@ -112,7 +122,7 @@ class backupSurveyLocally extends PluginBase
'settings' => array(
'active'=>array(
'type'=>'checkbox',
'label'=> $this->_translate('Save the LSA file locally.'),
'label'=> $this->_translate('Backup survey locally.'),
'htmlOptions' => array(
'value'=>'Y', // Use Y to use N when have inherit system
'uncheckValue'=>'N',// Set to N if submitted
......@@ -322,9 +332,14 @@ class backupSurveyLocally extends PluginBase
$survey = Survey::model()->findByPk($surveyId);
if(empty($survey)) {
/* @todo : delete PluginSettings ? */
echo "[error] Invalid survey id {$surveyId}\n";
return;
}
if($survey->active != "Y") {
$sLSSFileName = $dirName.DIRECTORY_SEPARATOR."backup-last".DIRECTORY_SEPARATOR.'survey_'.$surveyId.'.lss';
touch($sLSSFileName);
file_put_contents($sLSSFileName, surveyGetXMLData($surveyId));
echo "Survey id {$surveyId} lss saved\n";
return;
}
......@@ -361,6 +376,7 @@ class backupSurveyLocally extends PluginBase
$this->_addToZip($zip, $sLSIFileName, 'survey_'.$surveyId.'_timings.lsi');
unlink($sLSIFileName);
}
echo "Survey id {$surveyId} lsa saved\n";
return true;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment