Skip to content

Commit

Permalink
Fixed issue #9274: Uppercase database name leads to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Oct 10, 2014
1 parent 79ce4d0 commit dd18364
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 37 deletions.
40 changes: 10 additions & 30 deletions application/controllers/InstallerController.php
Expand Up @@ -47,6 +47,7 @@ public function run($action = 'index')
{
self::_checkInstallation();
self::_sessioncontrol();
Yii::import('application.helpers.common_helper', true);

switch ($action) {

Expand Down Expand Up @@ -547,7 +548,7 @@ function stepPopulateDb()
case 'mysql':
$sql_file = 'mysql';
break;
case 'dblib':
case 'dblib':
case 'sqlsrv':
case 'mssql':
$sql_file = 'mssql';
Expand Down Expand Up @@ -617,7 +618,7 @@ private function stepOptionalConfiguration()
$sDefaultAdminRealName = $model->adminName;
$sDefaultSiteName = $model->siteName;
$sDefaultSiteLanguage = $model->surveylang;
$sDefaultAdminEmail = $model->adminEmail;
$sDefaultAdminEmail = $model->adminEmail;

$aData['title'] = $clang->gT("Database configuration");
$aData['descp'] = $clang->gT("Please enter the database settings you want to use for LimeSurvey:");
Expand Down Expand Up @@ -839,10 +840,10 @@ function check_DirectoryWriteable($directory, &$data, $base, $keyError, $bRecurs
if (version_compare(PHP_VERSION, '5.3.0', '<'))
$bProceed = !$aData['verror'] = true;

if ($this->return_bytes(ini_get('memory_limit'))/1024/1024<64 && ini_get('memory_limit')!=-1)
if (convertPHPSizeToBytes(ini_get('memory_limit'))/1024/1024<64 && ini_get('memory_limit')!=-1)
$bProceed = !$aData['bMemoryError'] = true;


// mbstring library check
if (!check_PHPFunction('mb_convert_encoding', $aData['mbstringPresent']))
$bProceed = false;
Expand Down Expand Up @@ -1056,7 +1057,7 @@ function _writeConfigFile()

$sConfig .="\t\t" . ")," . "\n"
."\t\t" . "" . "\n"

."\t\t" . "// Uncomment the following line if you need table-based sessions". "\n"
."\t\t" . "// 'session' => array (" . "\n"
."\t\t\t" . "// 'class' => 'system.web.CDbHttpSession'," . "\n"
Expand Down Expand Up @@ -1137,7 +1138,7 @@ function _getDsn($sDatabaseType, $sDatabaseLocation, $sDatabasePort, $sDatabaseN
case 'mysql':
case 'mysqli':
// MySQL allow unix_socket for database location, then test if $sDatabaseLocation start with "/"
if(substr($sDatabaseLocation,0,1)=="/")
if(substr($sDatabaseLocation,0,1)=="/")
$sDSN = "mysql:unix_socket={$sDatabaseLocation};dbname={$sDatabaseName};";
else
$sDSN = "mysql:host={$sDatabaseLocation};port={$sDatabasePort};dbname={$sDatabaseName};";
Expand All @@ -1157,7 +1158,7 @@ function _getDsn($sDatabaseType, $sDatabaseLocation, $sDatabasePort, $sDatabaseN
}
break;

case 'dblib' :
case 'dblib' :
$sDSN = $sDatabaseType.":host={$sDatabaseLocation};dbname={$sDatabaseName}";
break;
case 'mssql' :
Expand Down Expand Up @@ -1242,33 +1243,12 @@ function _dbConnect($aDbConfig = array(), $aData = array())
return true;
} catch(Exception $e) {
if (!empty($aData['model']) && !empty($aData['clang'])) {
$aData['model']->addError('dblocation', $aData['clang']->gT('Try again! Connection with database failed. Reason: ') . $e->message);
$aData['model']->addError('dblocation', $aData['clang']->gT('Try again! Connection with database failed. Reason: ') . $e->getMessage());
$this->render('/installer/dbconfig_view', $aData);
} else {
return false;
}
}
}

/**
* This function returns the full number from a PHP ini value
*
* @param string $sValue
*/
function return_bytes($sValue) {
$sValue = trim($sValue);
$sLast = strtolower($sValue[strlen($sValue)-1]);
switch($sLast) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$sValue *= 1024;
case 'm':
$sValue *= 1024;
case 'k':
$sValue *= 1024;
}

return $sValue;
}

}
47 changes: 47 additions & 0 deletions application/core/LSYii_CaseValidator.php
@@ -0,0 +1,47 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 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.
*
*/

class LSYii_CaseValidator extends CValidator {

public $type='lower';


public function validateAttribute($object,$attribute){

if ($this->type=='upper')
{
if (strtoupper($object->$attribute)==$object->$attribute){
return;
}
else
{
$this->addError($object, $attribute, gT('Text needs to be uppercase.'));
return;
}
}
else // default to lowercase
{
if (strtolower($object->$attribute)==$object->$attribute){
return;
}
else
{
$this->addError($object, $attribute, gT('Text needs to be lowercase.'));
return;
}
}
return;
}

}
4 changes: 2 additions & 2 deletions application/models/InstallerConfigForm.php
Expand Up @@ -29,7 +29,7 @@ class InstallerConfigForm extends CFormModel
'mysqli' => 'MySQL (newer driver)',
'sqlsrv' => 'Microsoft SQL Server (sqlsrv)',
'mssql' => 'Microsoft SQL Server (mssql)',
'dblib' => 'Microsoft SQL Server (dblib)',
'dblib' => 'Microsoft SQL Server (dblib)',
'pgsql' => 'PostgreSQL',
);

Expand Down Expand Up @@ -68,7 +68,7 @@ public function rules()
array('dbtype, dblocation, dbname, dbuser', 'required', 'on' => 'database'),
array('dbpwd, dbprefix', 'safe', 'on' => 'database'),
array('dbtype', 'in', 'range' => array_keys($this->supported_db_types), 'on' => 'database'),

array('dbname','LSYii_CaseValidator','type'=>'lower'),
//Optional
array('adminLoginName, adminName, siteName, confirmPwd', 'safe', 'on' => 'optional'),
array('adminEmail', 'email', 'on' => 'optional'),
Expand Down
10 changes: 5 additions & 5 deletions application/views/installer/precheck_view.php
Expand Up @@ -52,7 +52,7 @@ function dirReport($dir, $write, $clang)
<th class='text-center'><?php $clang->eT("Current"); ?></th>
</tr>
</thead>
<tbody>
<tbody>
<tr>
<td><?php $clang->eT("PHP version"); ?></td>
<td>5.3.0+</td>
Expand All @@ -62,9 +62,9 @@ function dirReport($dir, $write, $clang)
<tr>
<td><?php $clang->eT("Minimum memory available"); ?></td>
<td>64MB</td>
<td><?php
if (isset($bMemoryError) && $bMemoryError) { ?><span style='font-weight:bold; color: red'><?php $clang->eT("Too low"); ?>: <?php echo $this->return_bytes(ini_get('memory_limit'))/1024/1024; ?>MB</span>
<?php } elseif (ini_get('memory_limit')=='-1') $clang->eT("Unlimited"); else { echo $this->return_bytes(ini_get('memory_limit'))/1024/1024; echo ' MB';} ?></td>
<td><?php
if (isset($bMemoryError) && $bMemoryError) { ?><span style='font-weight:bold; color: red'><?php $clang->eT("Too low"); ?>: <?php echo convertPHPSizeToBytes(ini_get('memory_limit'))/1024/1024; ?>MB</span>
<?php } elseif (ini_get('memory_limit')=='-1') $clang->eT("Unlimited"); else { echo convertPHPSizeToBytes(ini_get('memory_limit'))/1024/1024; echo ' MB';} ?></td>
</tr>
<tr>
<td><?php $clang->eT("PHP PDO driver library"); ?></td>
Expand Down Expand Up @@ -141,7 +141,7 @@ function dirReport($dir, $write, $clang)
<td><img src="<?php echo Yii::app()->baseUrl; ?>/installer/images/tick-right.png" alt="Check" /></td>
<td><?php echo $bIMAPPresent ; ?></td>
</tr>
</tbody>
</tbody>

</table>
</fieldset>
Expand Down

0 comments on commit dd18364

Please sign in to comment.