Skip to content

Commit

Permalink
Merge branch 'master' into cint
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jul 15, 2016
2 parents 7216e8a + 2f56bab commit 03589f8
Show file tree
Hide file tree
Showing 44 changed files with 1,411 additions and 1,270 deletions.
111 changes: 62 additions & 49 deletions application/commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,70 @@ class InstallCommand extends CConsoleCommand

public function run($sArgument)
{
if (!isset($sArgument) || !isset($sArgument[0]) || !isset($sArgument[1]) || !isset($sArgument[2]) || !isset($sArgument[3])) die('You have to set admin/password/full name and email address on the command line like this: php starter.php adminname mypassword fullname emailaddress');
Yii::import('application.helpers.common_helper', true);

try
if ( isset($sArgument) && isset($sArgument[0]) && isset($sArgument[1]) && isset($sArgument[2]) && isset($sArgument[3]))
{
$this->connection = App()->getDb();
$this->connection->active=true;
}
catch(CDbException $e){
$this->createDatabase();
};

$this->connection->charset = 'utf8';
switch ($this->connection->driverName) {
case 'mysql':
case 'mysqli':
$this->connection->createCommand("ALTER DATABASE ". $this->connection->quoteTableName($this->getDBConnectionStringProperty('dbname')) ." DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")->execute();
$sql_file = 'mysql';
Yii::import('application.helpers.common_helper', true);

try
{
$this->connection = App()->getDb();
$this->connection->active=true;
}
catch(CDbException $e)
{
$this->createDatabase();
};

$this->connection->charset = 'utf8';

switch ($this->connection->driverName)
{
case 'mysql':
case 'mysqli':
$this->connection->createCommand("ALTER DATABASE ". $this->connection->quoteTableName($this->getDBConnectionStringProperty('dbname')) ." DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")->execute();
$sql_file = 'mysql';
break;
case 'pgsql':
$sql_file = 'pgsql';

case 'pgsql':
$sql_file = 'pgsql';
break;
case 'dblib':
case 'mssql':
case 'sqlsrv':
$sql_file = 'mssql';

case 'dblib':
case 'mssql':
case 'sqlsrv':
$sql_file = 'mssql';
break;
default:
throw new Exception(sprintf('Unknown database type "%s".', $this->connection->driverName));

default:
throw new Exception(sprintf('Unknown database type "%s".', $this->connection->driverName));
}
$this->_executeSQLFile(dirname(Yii::app()->basePath).'/installer/sql/create-'.$sql_file.'.sql');
$this->connection->createCommand()->insert($this->connection->tablePrefix.'users', array(
'users_name'=>$sArgument[0],
'password'=>hash('sha256',$sArgument[1]),
'full_name'=>$sArgument[2],
'parent_id'=>0,
'lang'=>'auto',
'email'=>$sArgument[3]
));
$this->connection->createCommand()->insert($this->connection->tablePrefix.'permissions', array(
'entity'=>'global',
'entity_id'=>0,
'uid'=>1,
'permission'=>'superadmin',
'create_p'=>0,
'read_p'=>1,
'update_p'=>0,
'delete_p'=>0,
'import_p'=>0,
'export_p'=>0
));
}
else
{
// TODO: a valid error process
echo 'You have to set admin/password/full name and email address on the command line like this: php starter.php adminname mypassword fullname emailaddress';
}
$this->_executeSQLFile(dirname(Yii::app()->basePath).'/installer/sql/create-'.$sql_file.'.sql');
$this->connection->createCommand()->insert($this->connection->tablePrefix.'users', array(
'users_name'=>$sArgument[0],
'password'=>hash('sha256',$sArgument[1]),
'full_name'=>$sArgument[2],
'parent_id'=>0,
'lang'=>'auto',
'email'=>$sArgument[3]
));
$this->connection->createCommand()->insert($this->connection->tablePrefix.'permissions', array(
'entity'=>'global',
'entity_id'=>0,
'uid'=>1,
'permission'=>'superadmin',
'create_p'=>0,
'read_p'=>1,
'update_p'=>0,
'delete_p'=>0,
'import_p'=>0,
'export_p'=>0
));
}

/**
Expand All @@ -93,8 +106,8 @@ function _executeSQLFile($sFileName)
$iLineLength = strlen($sLine);

if ($iLineLength && $sLine[0] != '#' && substr($sLine,0,2) != '--') {
if (substr($sLine, $iLineLength-1, 1) == ';') {
$line = substr($sLine, 0, $iLineLength-1);
if (substr($sLine, $iLineLength-1, 1) == ';')
{
$sCommand .= $sLine;
$sCommand = str_replace('prefix_', $this->connection->tablePrefix, $sCommand); // Table prefixes

Expand Down Expand Up @@ -177,4 +190,4 @@ protected function createDatabase()
}

}
?>
?>
22 changes: 15 additions & 7 deletions application/commands/ResetPasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ class ResetPasswordCommand extends CConsoleCommand

public function run($sArgument)
{
if (!isset($sArgument) || !isset($sArgument[0]) || !isset($sArgument[1])) die('You have to set username and password on the command line like this: php console.php username password');
$iUserID=User::model()->getID($sArgument[0]);
if ($iUserID)
if (isset($sArgument) && isset($sArgument[0]) && isset($sArgument[1]))
{
User::model()->updatePassword($iUserID,$sArgument[1]);
echo "Password for user {$sArgument[0]} was set.\n";
$iUserID=User::model()->getID($sArgument[0]);
if ($iUserID)
{
User::model()->updatePassword($iUserID,$sArgument[1]);
echo "Password for user {$sArgument[0]} was set.\n";
}
else
{
echo "User {$sArgument[0]} not found.\n";
}

}
else
{
echo "User {$sArgument[0]} not found.\n";
//TODO: a valid error process
echo 'You have to set username and password on the command line like this: php console.php username password';
}
}
}

?>
?>
170 changes: 91 additions & 79 deletions application/commands/WipeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,89 +15,97 @@ class WipeCommand extends CConsoleCommand

public function run($sArgument)
{
if (!isset($sArgument) || !isset($sArgument[0]) || $sArgument[0]!='yes') die('This CLI command wipes a LimeSurvey installation clean (including all user except for the user ID 1 and user-uploaded content). For security reasons this command can only started if you add the parameter \'yes\' to the command line.');
Yii::import('application.helpers.common_helper', true);
Yii::import('application.helpers.database_helper', true);
if (!isset($sArgument) || !isset($sArgument[0]) || $sArgument[0]!='yes')
{

$actquery="truncate table {{assessments}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{answers}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{conditions}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{defaultvalues}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{labels}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{labelsets}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{groups}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{questions}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{surveys}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{surveys_languagesettings}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="delete from {{permissions}} where uid<>1";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{quota}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{quota_members}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{quota_languagesettings}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{question_attributes}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{user_groups}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{user_in_groups}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{templates}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participants}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_attribute_names}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_attribute_names_lang}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_attribute_values}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_shares}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{failed_login_attempts}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{saved_control}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{survey_links}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="delete from {{users}} where uid<>1";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="update {{users}} set lang='en'";
Yii::app()->db->createCommand($actquery)->execute();
Yii::import('application.helpers.common_helper', true);
Yii::import('application.helpers.database_helper', true);

$surveyidresult = dbGetTablesLike("tokens%");
foreach ( $surveyidresult as $sv )
{
Yii::app()->db->createCommand("drop table ".$sv)->execute();
}
$actquery="truncate table {{assessments}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{answers}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{conditions}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{defaultvalues}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{labels}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{labelsets}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{groups}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{questions}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{surveys}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{surveys_languagesettings}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="delete from {{permissions}} where uid<>1";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{quota}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{quota_members}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{quota_languagesettings}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{question_attributes}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{user_groups}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{user_in_groups}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{templates}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participants}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_attribute_names}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_attribute_names_lang}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_attribute_values}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{participant_shares}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{failed_login_attempts}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{saved_control}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="truncate table {{survey_links}}";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="delete from {{users}} where uid<>1";
Yii::app()->db->createCommand($actquery)->execute();
$actquery="update {{users}} set lang='en'";
Yii::app()->db->createCommand($actquery)->execute();

$surveyidresult = dbGetTablesLike("old\_%");
foreach ( $surveyidresult as $sv )
{
Yii::app()->db->createCommand("drop table ".$sv)->execute();
}
$surveyidresult = dbGetTablesLike("tokens%");
foreach ( $surveyidresult as $sv )
{
Yii::app()->db->createCommand("drop table ".$sv)->execute();
}

$surveyidresult = dbGetTablesLike("survey\_%");
foreach ( $surveyidresult as $sv )
{
if (strpos($sv, 'survey_links')===false && strpos($sv, 'survey_url_parameters')===false)
$surveyidresult = dbGetTablesLike("old\_%");
foreach ( $surveyidresult as $sv )
{
Yii::app()->db->createCommand("drop table ".$sv)->execute();
}
$sBaseUploadDir=dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'upload';
}

SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'surveys',false);
SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'templates',false);
$surveyidresult = dbGetTablesLike("survey\_%");
foreach ( $surveyidresult as $sv )
{
if (strpos($sv, 'survey_links')===false && strpos($sv, 'survey_url_parameters')===false)
Yii::app()->db->createCommand("drop table ".$sv)->execute();
}
$sBaseUploadDir=dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'upload';

SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'surveys',false);
SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'templates',false);
}
else
{
// TODO: a valid error process
echo 'This CLI command wipes a LimeSurvey installation clean (including all user except for the user ID 1 and user-uploaded content). For security reasons this command can only started if you add the parameter \'yes\' to the command line.';
}

}

Expand All @@ -113,6 +121,10 @@ function SureRemoveDir($dir, $DeleteMe) {
}
closedir($dh);
if ($DeleteMe){
@rmdir($dir);
if (!@rmdir($dir))
{
echo "Error: could not delete ".$dir;
}

}
}
}
10 changes: 8 additions & 2 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
} else {
$userConfig = require(dirname(__FILE__) . '/config.php');
}
@date_default_timezone_set(@date_default_timezone_get());

if (! date_default_timezone_set(@date_default_timezone_get()))
{

date_default_timezone_set('Europe/London');
}


if (function_exists('mb_internal_encoding')) {
// Needed to substring arabic etc
Expand Down Expand Up @@ -56,7 +62,7 @@
'pageSizeOptions'=>array(5=>5,10=>10,20=>20,50=>50,100=>100), // Default page size options for most of the grids
'pageSizeOptionsTokens'=>array(5=>5,10=>10,25=>25,50=>50,100=>100, 250=>250, 500=>500, 1000=>1000, 2500=>2500, 5000=>5000, 10000=>10000), // Tokens needs different options
'defaultEllipsizeHeaderValue'=>30, // Default max characters before ellipsizing the headers of responses grid
'defaultEllipsizeQuestionValu'=>50, // Default max characters before ellipsizing the questions inside responses grid
'defaultEllipsizeQuestionValue'=>50, // Default max characters before ellipsizing the questions inside responses grid
),

'import' => array(
Expand Down
2 changes: 1 addition & 1 deletion application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$config['dbversionnumber'] = 258;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '26';
$config['assetsversionnumber'] = '27';
return $config;

?>

0 comments on commit 03589f8

Please sign in to comment.