Skip to content

Commit

Permalink
Dev: Apply PSR-12 to all files (not third-party code)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jan 21, 2021
1 parent 948bd2f commit 7b1be4d
Show file tree
Hide file tree
Showing 629 changed files with 26,795 additions and 26,127 deletions.
21 changes: 11 additions & 10 deletions application/commands/CompileAssetsCommand.php
@@ -1,4 +1,5 @@
<?php

/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
Expand Down Expand Up @@ -42,18 +43,18 @@ public function run($aArguments)
return;
}
echo "=========================================================================\n";
echo "=== Compiling package ".$package." with ".$method." \n";
echo "=== Compiling package " . $package . " with " . $method . " \n";
echo "=========================================================================\n";

$sCurrentDir = dirname(__FILE__);
$assetsFolder = realpath($sCurrentDir.'/../../assets/');
$packageFolder = $assetsFolder.'/packages/'.$package;
$assetsFolder = realpath($sCurrentDir . '/../../assets/');
$packageFolder = $assetsFolder . '/packages/' . $package;

if (!file_exists($packageFolder)) {
echo "=========================================================================\n";
echo "=== ERROR! Package does not exist! Exiting. ===\n";
echo "=== Checked path: ===\n";
echo "=== ".$packageFolder."\n";
echo "=== " . $packageFolder . "\n";
echo "=========================================================================\n";
return;
}
Expand All @@ -62,18 +63,18 @@ public function run($aArguments)

if ($silent == true && $silent !== "1") {
$logfile = $silent;
} else if ($silent == true && $silent === "1") {
} elseif ($silent == true && $silent === "1") {
$logfile = " /dev/null";
}

switch ($method) {
case "gulp" :
case "gulp":
$this->liveExecuteCommand("(cd {$packageFolder} && {$method})", $logfile);
break;
case "npm" :
case "npm":
$this->liveExecuteCommand("(cd {$packageFolder} && {$method} run compile)", $logfile);
break;
case "bash" :
case "bash":
$this->liveExecuteCommand("(cd {$packageFolder} && {$method} compile.sh)", $logfile);
break;
}
Expand All @@ -95,7 +96,7 @@ private function liveExecuteCommand($cmd, $logfile = false)

while (!feof($proc)) {
$live_output = fread($proc, 4096);
$complete_output = $complete_output.$live_output;
$complete_output = $complete_output . $live_output;

echo "$live_output";
@ flush();
Expand All @@ -109,7 +110,7 @@ private function liveExecuteCommand($cmd, $logfile = false)
// return exit status and intended output
return array(
'exit_status' => intval($matches[0]),
'output' => str_replace("Exit status : ".$matches[0], '', $complete_output)
'output' => str_replace("Exit status : " . $matches[0], '', $complete_output)
);
}
}
54 changes: 26 additions & 28 deletions application/commands/DemomodeCommand.php
@@ -1,4 +1,5 @@
<?php

/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
Expand Down Expand Up @@ -28,24 +29,23 @@ public function run($sArgument)
// 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.';
}

}

private function _resetDatabase()
{
Yii::import('application.helpers.common_helper', true);
Yii::import('application.helpers.database_helper', true);

//Truncate most of the tables
//Truncate most of the tables
$truncatableTables = [
'{{assessments}}', '{{answers}}', '{{answer_l10ns}}', '{{boxes}}', '{{conditions}}', '{{defaultvalues}}', '{{defaultvalue_l10ns}}', '{{labels}}', '{{label_l10ns}}', '{{labelsets}}', '{{groups}}', '{{questions}}', '{{question_l10ns}}', '{{surveys}}', '{{surveys_languagesettings}}', '{{quota}}', '{{quota_members}}', '{{quota_languagesettings}}', '{{question_attributes}}', '{{quota}}', '{{quota_members}}', '{{quota_languagesettings}}', '{{question_attributes}}', '{{user_groups}}', '{{user_in_groups}}', '{{templates}}', '{{template_configuration}}', '{{participants}}', '{{participant_attribute_names}}', '{{participant_attribute_names_lang}}', '{{participant_attribute_values}}', '{{participant_shares}}', '{{settings_user}}', '{{failed_login_attempts}}', '{{saved_control}}', '{{survey_links}}'
];
foreach ($truncatableTables as $table) {
$quotedTable = Yii::app()->db->quoteTableName($table);
$actquery = "truncate table ".$quotedTable;
$actquery = "truncate table " . $quotedTable;
Yii::app()->db->createCommand($actquery)->execute();
}
//Now delete the basics in all other tables
//Now delete the basics in all other tables
$actquery = "delete from {{permissions}} where uid<>1";
Yii::app()->db->createCommand($actquery)->execute();
$actquery = "delete from {{users}} where uid<>1";
Expand All @@ -71,26 +71,26 @@ private function _resetDatabase()

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

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

//Add the general boxes again
foreach ($templateData = LsDefaultDataSets::getBoxesData() as $boxes) {
Yii::app()->db->createCommand()->insert("{{boxes}}", $boxes);
}
// At last reset the basic themes
// At last reset the basic themes
foreach ($templateData = LsDefaultDataSets::getTemplatesData() as $template) {
Yii::app()->db->createCommand()->insert("{{templates}}", $template);
}
Expand All @@ -102,44 +102,43 @@ private function _resetDatabase()
private function _resetFiles()
{

$sBaseUploadDir = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'upload';
$sBaseUploadDir = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'upload';

SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'surveys', false, ['index.html']);
SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'global', false, ['index.html']);
SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'templates', false);
SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.'survey', false, ['index.html']);
SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.'question', false);
SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'surveys', false, ['index.html']);
SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'global', false, ['index.html']);
SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'templates', false);
SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'survey', false, ['index.html']);
SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'question', false);
}

private function _createDemo()
{
Yii::app()->loadHelper('admin/import');
require_once(dirname(dirname(dirname(__FILE__))).'/application/helpers/replacements_helper.php');
require_once(dirname(dirname(dirname(__FILE__))).'/application/helpers/expressions/em_manager_helper.php');
require_once(dirname(dirname(dirname(__FILE__))).'/application/helpers/expressions/em_core_helper.php');
require_once(dirname(dirname(dirname(__FILE__))).'/application/helpers/admin/activate_helper.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/application/helpers/replacements_helper.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/application/helpers/expressions/em_manager_helper.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/application/helpers/expressions/em_core_helper.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/application/helpers/admin/activate_helper.php');

Yii::app()->session->add('loginID', 1);
$documentationSurveyPath = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'docs'.DIRECTORY_SEPARATOR.'demosurveys'.DIRECTORY_SEPARATOR;
$documentationSurveyPath = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'demosurveys' . DIRECTORY_SEPARATOR;
$aSamplesurveys = scandir($documentationSurveyPath);
$surveysToActivate = [];
foreach ($aSamplesurveys as $sSamplesurvey) {
$result = null;
//Try catch for console application to be able to import surveys

$result = @ XMLImportSurvey($documentationSurveyPath.$sSamplesurvey);
$result = @ XMLImportSurvey($documentationSurveyPath . $sSamplesurvey);

if (in_array($sSamplesurvey, ['ls205_sample_survey_multilingual.lss', 'ls205_randomization_group_test.lss', 'ls205_cascading_array_filter_exclude.lss'])) {
$surveysToActivate[] = $result['newsid'];
}
}
require_once(__DIR__.'/../helpers/admin/activate_helper.php');
require_once(__DIR__ . '/../helpers/admin/activate_helper.php');
array_map('activateSurvey', $surveysToActivate);
}

}
}

function SureRemoveDir($dir, $DeleteMe, $excludes=[])
function SureRemoveDir($dir, $DeleteMe, $excludes = [])
{
if (!$dh = @opendir($dir)) {
return;
Expand All @@ -148,15 +147,14 @@ function SureRemoveDir($dir, $DeleteMe, $excludes=[])
if ($obj == '.' || $obj == '..' || in_array($obj, $excludes)) {
continue;
}
if (!@unlink($dir.'/'.$obj)) {
SureRemoveDir($dir.'/'.$obj, true);
if (!@unlink($dir . '/' . $obj)) {
SureRemoveDir($dir . '/' . $obj, true);
}
}
closedir($dh);
if ($DeleteMe) {
if (!@rmdir($dir)) {
echo "Error: could not delete ".$dir;
echo "Error: could not delete " . $dir;
}

}
}
21 changes: 10 additions & 11 deletions application/commands/FlushAssetsCommand.php
@@ -1,4 +1,5 @@
<?php

/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
Expand All @@ -21,17 +22,16 @@ class FlushAssetsCommand extends CConsoleCommand
public function run($aArguments)
{
$sCurrentDir = dirname(__FILE__);
$tmpFolder = realpath($sCurrentDir.'/../../tmp/');
$tmpFolder = realpath($sCurrentDir . '/../../tmp/');
if ($tmpFolder === false) {
echo 'Tmp folder '.$sCurrentDir.'/../../tmp/ not found';
return;
echo 'Tmp folder ' . $sCurrentDir . '/../../tmp/ not found';
return;
}
echo "Flushing assets in ".$tmpFolder;
echo "Flushing assets in " . $tmpFolder;
echo "\n";

$this->_sureRemoveFiles($tmpFolder.'/assets/', false, ['index.html']);
$this->_sureRemoveFiles($tmpFolder.'/runtime/cache/', false, ['index.html']);

$this->_sureRemoveFiles($tmpFolder . '/assets/', false, ['index.html']);
$this->_sureRemoveFiles($tmpFolder . '/runtime/cache/', false, ['index.html']);
}
private function _sureRemoveFiles($dir, $DeleteMe, $exclude = array())
{
Expand All @@ -42,16 +42,15 @@ private function _sureRemoveFiles($dir, $DeleteMe, $exclude = array())
if ($obj == '.' || $obj == '..' || in_array($obj, $exclude)) {
continue;
}
if (!@unlink($dir.'/'.$obj)) {
$this->_sureRemoveFiles($dir.'/'.$obj, true);
if (!@unlink($dir . '/' . $obj)) {
$this->_sureRemoveFiles($dir . '/' . $obj, true);
}
}
closedir($dh);
if ($DeleteMe) {
if (!@rmdir($dir)) {
echo "Error: could not delete ".$dir;
echo "Error: could not delete " . $dir;
}

}
}
}
57 changes: 27 additions & 30 deletions application/commands/InstallCommand.php
Expand Up @@ -44,21 +44,21 @@ public function run($aArguments)
$this->output('Connecting to database...');
$this->connection = App()->getDb();
$this->connection->active = true;
$this->output('Using connection string '.$this->connection->connectionString);
$this->output('Using connection string ' . $this->connection->connectionString);
} catch (CDbException $e) {
$this->output('Could not connect to database: '.$e->getMessage());
$this->output('Could not connect to database: ' . $e->getMessage());
$this->createDatabase();
};

$this->prepareCharset();

$sFileName = dirname(APPPATH).'/installer/create-database.php';
$sFileName = dirname(APPPATH) . '/installer/create-database.php';
require_once($sFileName);
try {
$this->output('Creating tables...');
populateDatabase($this->connection);
} catch (Exception $e) {
$this->output('Could not create LimeSurvey tables: '.$e->getMessage());
$this->output('Could not create LimeSurvey tables: ' . $e->getMessage());
return 1;
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public function getDBConnectionStringProperty($sProperty, $connectionString = nu
$connectionString = $this->connection->connectionString;
}
// Yii doesn't give us a good way to get the database name
if (preg_match('/'.$sProperty.'=([^;]*)/', $connectionString, $aMatches) == 1) {
if (preg_match('/' . $sProperty . '=([^;]*)/', $connectionString, $aMatches) == 1) {
return $aMatches[1];
}
return null;
Expand All @@ -101,10 +101,10 @@ public function getDBConnectionStringProperty($sProperty, $connectionString = nu
protected function createDatabase()
{
$this->output('Creating database...');
App()->configure(array('components'=>array('db'=>array('autoConnect'=>false))));
App()->configure(array('components' => array('db' => array('autoConnect' => false))));
$this->connection = App()->db;

App()->configure(array('components'=>array('db'=>array('autoConnect'=>true))));
App()->configure(array('components' => array('db' => array('autoConnect' => true))));
$connectionString = $this->connection->connectionString;
$this->output($connectionString);
$this->connection->connectionString = preg_replace('/dbname=([^;]*)/', '', $connectionString);
Expand Down Expand Up @@ -164,7 +164,7 @@ protected function createDatabase()
public function output($msg)
{
if ($this->noisy) {
echo $msg.PHP_EOL;
echo $msg . PHP_EOL;
}
}

Expand All @@ -187,7 +187,7 @@ private function prepareCharset()
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();
$this->connection->createCommand("ALTER DATABASE " . $this->connection->quoteTableName($this->getDBConnectionStringProperty('dbname')) . " DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")->execute();
break;
case 'pgsql':
case 'dblib':
Expand All @@ -197,21 +197,20 @@ private function prepareCharset()
default:
throw new Exception(sprintf('Unknown database type "%s".', $this->connection->driverName));
}

}

private function createUser($data)
{
$this->output('Creating admin user...');
$this->connection->createCommand()->insert(
$this->connection->tablePrefix.'users',
$this->connection->tablePrefix . 'users',
array(
'users_name'=>$data[0],
'password'=>password_hash($data[1], PASSWORD_DEFAULT),
'full_name'=>$data[2],
'parent_id'=>0,
'lang'=>'auto',
'email'=>$data[3]
'users_name' => $data[0],
'password' => password_hash($data[1], PASSWORD_DEFAULT),
'full_name' => $data[2],
'parent_id' => 0,
'lang' => 'auto',
'email' => $data[3]
)
);
}
Expand All @@ -220,21 +219,19 @@ private function createPermissions()
{
$this->output('Creating permissions ...');
$this->connection->createCommand()->insert(
$this->connection->tablePrefix.'permissions',
$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
'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
)
);
}


}

0 comments on commit 7b1be4d

Please sign in to comment.