Skip to content

Commit

Permalink
Fixed issue #12066: get whole config in command action
Browse files Browse the repository at this point in the history
Dev: near same logic than WebApp
  • Loading branch information
Shnoulle committed Jan 31, 2017
1 parent 33fc574 commit c40a346
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 25 deletions.
27 changes: 8 additions & 19 deletions application/commands/console.php
Expand Up @@ -15,8 +15,8 @@
* File edited by Sam Mousa for Marcel Minke.
* This loader bypasses the default Yii loader and loads a custom console class instead.
*/
if (!isset($argv[0])) die();
define('BASEPATH','.');
if (!isset($argv[0])) die();
define('BASEPATH','.');
/**
* Load Psr4 autoloader, should be replaced by composer autoloader at some point.
*/
Expand All @@ -26,29 +26,18 @@
$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__);
$settings=require (dirname($sCurrentDir).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config-defaults.php');
$config=require (dirname($sCurrentDir).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'internal.php');
$core = dirname($sCurrentDir) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR;
if(isset($config['config'])){
$settings=array_merge($settings,$config['config']);
}
unset ($config['defaultController']);
unset ($config['config']);
/* fix runtime path, unsure you can lauch function anywhere (if you use php /var/www/limesurvey/... : can be /root/ for config */
$runtimePath=$settings['runtimedir'];
if(!is_dir($runtimePath) || !is_writable($runtimePath)){
$runtimePath=str_replace($settings['rootdir'],dirname(dirname(dirname(__FILE__))),$runtimePath);
}
$config['runtimePath']=$runtimePath;
// Load configuration.
$sCurrentDir=dirname(__FILE__);
$config=require (dirname($sCurrentDir).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'internal.php');
$core = dirname($sCurrentDir) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR;

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

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


/* specific for web */
unset($config['defaultController']);

if(isset($config))
{
Expand Down
36 changes: 36 additions & 0 deletions application/config/console.php
@@ -0,0 +1,36 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2017 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v3 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/

/**
* This file contains the default settings for LimeSurvey for command action
* Do not edit this file as it may change in future revisions of the software.
* @package configuration
*/


$config = array();

$config['rootdir'] = Yii::getPathOfAlias('webroot');

$config['publicdir'] = $config['rootdir']; // The directory path of the public scripts
$config['homedir'] = $config['rootdir']; // The directory path of the admin scripts
$config['tempdir'] = $config['rootdir'].DIRECTORY_SEPARATOR."tmp"; // The directory path where LimeSurvey can store temporary files
$config['imagedir'] = $config['rootdir'].DIRECTORY_SEPARATOR."images"; // The directory path of the image directory
$config['uploaddir'] = $config['rootdir'].DIRECTORY_SEPARATOR."upload";
$config['standardtemplaterootdir'] = $config['rootdir'].DIRECTORY_SEPARATOR."templates"; // The directory path of the standard templates
$config['usertemplaterootdir'] = $config['uploaddir'].DIRECTORY_SEPARATOR."templates"; // The directory path of the user templates
$config['styledir'] = $config['rootdir'].DIRECTORY_SEPARATOR.'styles';
$config['questiontypedir'] = $config['rootdir'].DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'extensions'.DIRECTORY_SEPARATOR.'questionTypes';

return $config;
54 changes: 48 additions & 6 deletions application/core/ConsoleApplication.php
Expand Up @@ -20,16 +20,58 @@ public function getSession()
return $this->getComponent('session');
}

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

/* Using some config part for app config, then load it before*/
$baseConfig = require(__DIR__ . '/../config/config-defaults.php');
if(file_exists(__DIR__ . '/../config/config.php'))
{
$userConfigs = require(__DIR__ . '/../config/config.php');
if(is_array($userConfigs['config']))
{
$baseConfig = array_merge($baseConfig, $userConfigs['config']);
}
}

/* Set the runtime path according to tempdir if needed */
if(!isset($aApplicationConfig['runtimePath'])){
$aApplicationConfig['runtimePath']=$baseConfig['tempdir'] . DIRECTORY_SEPARATOR. 'runtime';
} /* No need to test runtimePath validity : Yii return an exception without issue */

/* Construct CWebApplication */
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
/* Because we have app now : we have to call again the config : can be done before : no real usage of url in console, but usage of getPathOfAlias */
$coreConfig = require(__DIR__ . '/../config/config-defaults.php');
$consoleConfig = require(__DIR__ . '/../config/console.php'); // Only for console : replace some config-defaults
$emailConfig = require(__DIR__ . '/../config/email.php');
$versionConfig = require(__DIR__ . '/../config/version.php');
$updaterVersionConfig = require(__DIR__ . '/../config/updater_version.php');
$lsConfig = array_merge($coreConfig, $emailConfig, $versionConfig, $updaterVersionConfig);
if(file_exists(__DIR__ . '/../config/config.php'))
{
$userConfigs = require(__DIR__ . '/../config/config.php');
if(is_array($userConfigs['config']))
{
$lsConfig = array_merge($lsConfig, $userConfigs['config']);
}
}
$this->config = array_merge($this->config, $lsConfig);

/* Load the database settings : if available */
try {
$settingsTableExist = Yii::app()->db->schema->getTable('{{settings_global}}');
if(is_object($settingsTableExist)){
$dbConfig=CHtml::listData(SettingGlobal::model()->findAll(), 'stg_name', 'stg_value');
$this->config = array_merge($this->config,$dbConfig);
}
}catch(Exception $exception) {
// Allow exception (install for example)
}

}

/**
Expand Down

0 comments on commit c40a346

Please sign in to comment.