Skip to content

Commit

Permalink
Merge branch '2.06_SondagesPro' of https://git.framasoft.org/Shnoulle…
Browse files Browse the repository at this point in the history
…/LimeSurvey into 2.06_SondagesPro
  • Loading branch information
Shnoulle committed Jan 30, 2017
2 parents 58d8bb6 + 6a0ca7d commit 42e4287
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,10 @@ Only partial changelog, [commit history](https://framagit.org/Shnoulle/LimeSurve

## unreleased

### Feature
- Allow to update via cli
- Allow to update runtime directory in config (LimeSurvey API 3 compatible only)

### [1.2.2] - 2016-01-12
- Update [PHPMailer](https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.22) for security issue

Expand Down
8 changes: 4 additions & 4 deletions application/commands/PluginCommand.php
Expand Up @@ -15,16 +15,16 @@ class PluginCommand extends CConsoleCommand
{
public $connection;

public function actionCron($interval)
public function actionCron($interval=null)
{

$pm = \Yii::app()->pluginManager;
$event = new PluginEvent('cron');
$event->set('interval', $interval);
$pm->dispatchEvent($event);


}
}

?>
?>
93 changes: 93 additions & 0 deletions application/commands/UpdateCommand.php
@@ -0,0 +1,93 @@
<?php
/*
* @author Denis Chenu <denis@sondages.pro>
* @license GPL v3
* @version 0.1
*
* Copyright (C) 2017 Denis Chenu
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
class UpdateCommand extends CConsoleCommand
{
public function run(){
$this->_setConfigs();
$newDbVersion = (float)Yii::app()->getConfig('dbversionnumber');
$currentDbVersion = (float)Yii::app()->getConfig('DBVersion');
if(!$currentDbVersion){
throw new CException("DB error : LimeSurvey database seems invalid.");
}
if($newDbVersion > $currentDbVersion){
echo "Update ".Yii::app()->db->connectionString.", prefix :".Yii::app()->db->tablePrefix." from {$currentDbVersion} to {$newDbVersion}\n";
Yii::import('application.helpers.common_helper', true);
Yii::import('application.helpers.update.updatedb_helper', true);
$result=db_upgrade_all($currentDbVersion);/* @todo : fix bad echoing here */
if ($result) {
//printf(gT("Database has been successfully upgraded to version %s"),$dbversionnumber)."\n";
echo "Database has been successfully upgraded to version $newDbVersion \n";
} else {
//echo gT("Please fix this error in your database and try again")."\n";
throw new CException("Please fix this error in your database and try again");
}
} else {
echo "no need update ".$newDbVersion ." ". $currentDbVersion ."\n";
}
}

/**
* Fonction to set all needed (and unneeded) config
* @return void
*/
private function _setConfigs(){
/* default config */
$aDefaultConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config-defaults.php');
foreach($aDefaultConfigs as $sConfig=>$defaultConfig){
Yii::app()->setConfig($sConfig,$defaultConfig);
}
/* Fix for badly set rootdir */
$sRootDir=realpath(Yii::app()->basePath. DIRECTORY_SEPARATOR . "..") ;
Yii::app()->setConfig('rootdir',$sRootDir);
Yii::app()->setConfig('publicdir',$sRootDir);
Yii::app()->setConfig('homedir',$sRootDir);
Yii::app()->setConfig('tempdir',$sRootDir.DIRECTORY_SEPARATOR."tmp");
Yii::app()->setConfig('imagedir',$sRootDir.DIRECTORY_SEPARATOR."images");
Yii::app()->setConfig('uploaddir',$sRootDir.DIRECTORY_SEPARATOR."upload");
Yii::app()->setConfig('standardtemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."templates");
Yii::app()->setConfig('usertemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."templates");
Yii::app()->setConfig('styledir',$sRootDir.DIRECTORY_SEPARATOR."styledir");
/* version */
$aVersionConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'version.php');
foreach($aVersionConfigs as $sConfig=>$versionConfig){
Yii::app()->setConfig($sConfig,$versionConfig);
}
/* LS 3 version */
Yii::app()->setConfig('runtimedir',$sRootDir.DIRECTORY_SEPARATOR."tmp".DIRECTORY_SEPARATOR."runtime");
if(file_exists(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'))
{
$config = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php');
if(is_array($config['config']) && !empty($config['config']))
{
foreach($config['config'] as $key=>$value)
Yii::app()->setConfig($key,$value);
}
}
$oSettings=SettingGlobal::model()->findAll();
if (count($oSettings) > 0)
{
foreach ($oSettings as $oSetting)
{
Yii::app()->setConfig($oSetting->getAttribute('stg_name'), $oSetting->getAttribute('stg_value'));
}
}
}

}
?>
22 changes: 10 additions & 12 deletions application/commands/console.php
@@ -1,5 +1,5 @@
#!/usr/bin/php
<?php
<?php
/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
Expand All @@ -11,7 +11,7 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*
*
* File edited by Sam Mousa for Marcel Minke.
* This loader bypasses the default Yii loader and loads a custom console class instead.
*/
Expand All @@ -26,21 +26,19 @@
$loader->addNamespace('ls\\pluginmanager', __DIR__ . '/../libraries/PluginManager');
$loader->addNamespace('ls\\pluginmanager', __DIR__ . '/../libraries/PluginManager/Storage');
require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'yii.php');
// Load configuration.
$sCurrentDir=dirname(__FILE__);
$config=require (dirname($sCurrentDir).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'internal.php');
$core = dirname($sCurrentDir) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR;
unset ($config['defaultController']);
unset ($config['config']);


// Load configuration.
$sCurrentDir=dirname(__FILE__);
$config=require (dirname($sCurrentDir).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'internal.php');
$core = dirname($sCurrentDir) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR;
unset ($config['defaultController']);
unset ($config['config']);

// fix for fcgi
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));

defined('YII_DEBUG') or define('YII_DEBUG',true);



if(isset($config))
{
Expand All @@ -53,4 +51,4 @@
$app->commandRunner->addCommands($env);
}
$app->run();
?>
?>
4 changes: 2 additions & 2 deletions application/config/config-defaults.php
Expand Up @@ -594,7 +594,7 @@
//The following url and dir locations do not need to be modified unless you have a non-standard
//LimeSurvey installation. Do not change unless you know what you are doing.

if(!isset($argv[0]))
if(!isset($argv[0]) && Yii::app()!=null)
{
$config['publicurl'] = Yii::app()->baseUrl . '/'; // The public website location (url) of the public survey script
}
Expand All @@ -610,7 +610,7 @@
$config['standardtemplaterooturl'] = $config['publicurl'].'templates'; // Location of the standard templates
$config['adminscripts'] = $config['publicurl'].'scripts/admin/';
$config['generalscripts'] = $config['publicurl'].'scripts/';
$config['third_party'] = $config['publicurl'].'third_party/';
$config['third_party'] = $config['publicurl'].'third_party/';
$config['styleurl'] = $config['publicurl'].'styles/';
$config['publicstyleurl'] = $config['publicurl'].'styles-public/';
$config['sCKEditorURL'] = $config['third_party'].'ckeditor';
Expand Down
1 change: 0 additions & 1 deletion application/config/internal.php
Expand Up @@ -14,7 +14,6 @@
@date_default_timezone_set(@date_default_timezone_get());
$internalConfig = array(
'basePath' => dirname(dirname(__FILE__)),
'runtimePath' => dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'runtime',
'name' => 'LimeSurvey',
'localeClass' => 'LSYii_Locale',
'defaultController' => 'surveys',
Expand Down
11 changes: 3 additions & 8 deletions application/controllers/admin/globalsettings.php
Expand Up @@ -171,19 +171,18 @@ private function _saveSettings()
setGlobalSetting('emailsmtpdebug', sanitize_int(Yii::app()->request->getPost('emailsmtpdebug','0')));
setGlobalSetting('emailsmtpuser', strip_tags(returnGlobal('emailsmtpuser')));
setGlobalSetting('filterxsshtml', strip_tags($_POST['filterxsshtml']));
$warning = '';
// make sure emails are valid before saving them
if (Yii::app()->request->getPost('siteadminbounce', '') == ''
|| validateEmailAddress(Yii::app()->request->getPost('siteadminbounce'))) {
setGlobalSetting('siteadminbounce', strip_tags(Yii::app()->request->getPost('siteadminbounce')));
} else {
$warning .= gT("Warning! Admin bounce email was not saved because it was not valid.").'<br/>';
Yii::app()->setFlashMessage(gT("Warning! Admin bounce email was not saved because it was not valid."),'error');
}
if (Yii::app()->request->getPost('siteadminemail', '') == ''
|| validateEmailAddress(Yii::app()->request->getPost('siteadminemail'))) {
setGlobalSetting('siteadminemail', strip_tags(Yii::app()->request->getPost('siteadminemail')));
} else {
$warning .= gT("Warning! Admin email was not saved because it was not valid.").'<br/>';
Yii::app()->setFlashMessage(gT("Warning! Admin email was not saved because it was not valid."),'error');
}
setGlobalSetting('siteadminname', strip_tags($_POST['siteadminname']));
setGlobalSetting('shownoanswer', sanitize_int($_POST['shownoanswer']));
Expand Down Expand Up @@ -217,11 +216,7 @@ private function _saveSettings()
}
setGlobalSetting('timeadjust', $savetime);
setGlobalSetting('usercontrolSameGroupPolicy', strip_tags($_POST['usercontrolSameGroupPolicy']));

Yii::app()->session['flashmessage'] = $warning.gT("Global settings were saved.");

$url = htmlspecialchars_decode(Yii::app()->session['refurl']);
if($url){Yii::app()->getController()->redirect($url);}
Yii::app()->setFlashMessage(gT("Global settings were saved."));
}

private function _checkSettings()
Expand Down
12 changes: 11 additions & 1 deletion application/controllers/survey/index.php
Expand Up @@ -110,6 +110,17 @@ function action()
{
$sDisplayLanguage=Yii::app()->getConfig('defaultlang');
}
/* Unsure display language is in available language */
if(Survey::model()->findByPk($surveyid)){
if(!in_array($sDisplayLanguage,Survey::model()->findByPk($surveyid)->getAllLanguages())){
$sDisplayLanguage=Survey::model()->findByPk($surveyid)->language;
}
} else {
$aLanguages=getLanguageDataRestricted();
if(!array_key_exists($sDisplayLanguage,$aLanguages)){
$sDisplayLanguage=Yii::app()->getConfig('defaultlang');
}
}
if ($surveyid && $surveyExists)
{
SetSurveyLanguage( $surveyid, $sDisplayLanguage);
Expand All @@ -118,7 +129,6 @@ function action()
{
SetSurveyLanguage( 0, $sDisplayLanguage);
}

if ( $this->_isClientTokenDifferentFromSessionToken($clienttoken,$surveyid) )
{
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",array('token'=>$clienttoken,'lang'=>App()->language,'newtest'=>'Y'));
Expand Down
29 changes: 23 additions & 6 deletions application/core/ConsoleApplication.php
Expand Up @@ -20,16 +20,33 @@ public function getSession()
return $this->getComponent('session');
}

public function __construct($config = null) {
parent::__construct($config);
public function __construct($aApplicationConfig = null) {

$coreConfig = require(__DIR__ . '/../config/config-defaults.php');
$consoleConfig = require(__DIR__ . '/../config/console.php');
$emaiConfig = require(__DIR__ . '/../config/email.php');
$versionConfig = require(__DIR__ . '/../config/version.php');
$updaterVersionConfig = require(__DIR__ . '/../config/updater_version.php');
$lsConfig = array_merge($coreConfig, $consoleConfig, $emaiConfig, $versionConfig, $updaterVersionConfig);
if(file_exists(__DIR__ . '/../config/config.php'))
{
$userConfig = require(__DIR__ . '/../config/config.php');
if(is_array($userConfig['config']))
{
$lsConfig = array_merge($lsConfig, $userConfig['config']);
}
}
// Runtime path has to be set before parent constructor is executed
// User can set it in own config using Yii
if(!isset($aApplicationConfig['runtimePath'])){
$aApplicationConfig['runtimePath']=$lsConfig['tempdir'] . DIRECTORY_SEPARATOR. 'runtime';
}
parent::__construct($aApplicationConfig);

// Set webroot alias.
Yii::setPathOfAlias('webroot', realpath(Yii::getPathOfAlias('application') . '/../'));
// Load email settings.
$email = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'email.php');
$this->config = array_merge($this->config, $email);

// Now initialize the plugin manager
$this->config = array_merge($this->config, $lsConfig);
}

/**
Expand Down
35 changes: 20 additions & 15 deletions application/core/LSYii_Application.php
Expand Up @@ -37,29 +37,34 @@ class LSYii_Application extends CWebApplication
* @param array $config
* @return void
*/
public function __construct($config = null)
public function __construct($aApplicationConfig = null)
{
parent::__construct($config);
Yii::setPathOfAlias('bootstrap' , Yii::getPathOfAlias('ext.bootstrap'));
// Load the default and environmental settings from different files into self.
$ls_config = require(__DIR__ . '/../config/config-defaults.php');
$email_config = require(__DIR__ . '/../config/email.php');
$version_config = require(__DIR__ . '/../config/version.php');
$updater_version_config = require(__DIR__ . '/../config/updater_version.php');
$settings = array_merge($ls_config, $version_config, $email_config, $updater_version_config);


/* Load lsConfig */
$coreConfig = require(__DIR__ . '/../config/config-defaults.php');
$emaiConfig = require(__DIR__ . '/../config/email.php');
$versionConfig = require(__DIR__ . '/../config/version.php');
$updaterVersionConfig = require(__DIR__ . '/../config/updater_version.php');
$lsConfig = array_merge($coreConfig, $emaiConfig, $versionConfig, $updaterVersionConfig);
if(file_exists(__DIR__ . '/../config/config.php'))
{
$ls_config = require(__DIR__ . '/../config/config.php');
if(is_array($ls_config['config']))
$userConfig = require(__DIR__ . '/../config/config.php');
if(is_array($userConfig['config']))
{
$settings = array_merge($settings, $ls_config['config']);
$lsConfig = array_merge($lsConfig, $userConfig['config']);
}
}
// Runtime path has to be set before parent constructor is executed
// User can set it in own config using Yii
if(!isset($aApplicationConfig['runtimePath'])){
$aApplicationConfig['runtimePath']=$lsConfig['tempdir'] . DIRECTORY_SEPARATOR. 'runtime';
}
parent::__construct($aApplicationConfig);

foreach ($settings as $key => $value)
Yii::setPathOfAlias('bootstrap' , Yii::getPathOfAlias('ext.bootstrap'));
// Load the default and environmental settings from different files into self.
foreach ($lsConfig as $key => $value){
$this->setConfig($key, $value);
}

App()->getAssetManager()->setBaseUrl(Yii::app()->getBaseUrl(false) . '/tmp/assets');
}
Expand Down

0 comments on commit 42e4287

Please sign in to comment.