Skip to content

Commit

Permalink
ecs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Dec 16, 2019
1 parent 97aa1df commit dd8248e
Show file tree
Hide file tree
Showing 52 changed files with 604 additions and 549 deletions.
3 changes: 2 additions & 1 deletion src/Command/Chash/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O

$zippy = Zippy::load();
$archive = $zippy->open($tempFile);

try {
$archive->extract($folderPath);
} catch (\Alchemy\Zippy\Exception\RunTimeException $e) {
$output->writeln("<comment>Chash update failed during unzip.");
$output->writeln('<comment>Chash update failed during unzip.');
$output->writeln($e->getMessage());

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Chash/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$version = $input->getArgument('version');
$chamiloRoot = $input->getArgument('chamilo_root');

if ($version == '111') {
if ('111' == $version) {
$file = $chamiloRoot.'app/config/migrations.yml';

require_once $chamiloRoot.'app/Migrations/AbstractMigrationChamilo.php';
Expand All @@ -60,7 +60,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
return 1;
}

if ($version == '110') {
if ('110' == $version) {
$file = $chamiloRoot.'app/config/migrations110.yml';

$this->migrationFile = $file;
Expand Down
2 changes: 0 additions & 2 deletions src/Command/Common/ChamiloEmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

/**
* Class CommonChamiloUserCommand.
*
* @package Chash\Command\User
*/
class ChamiloEmailCommand extends Command
{
Expand Down
78 changes: 43 additions & 35 deletions src/Command/Common/CommonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function getInstallationFolder()
*/
public function getInstallationPath($version)
{
if ($version === 'master') {
if ('master' === $version) {
$version = $this->getLatestVersion();
}

Expand Down Expand Up @@ -619,7 +619,7 @@ public function setRootSysDependingConfigurationPath($path)
{
$configurationPath = $this->getConfigurationHelper()->getNewConfigurationPath($path);

if ($configurationPath == false) {
if (false == $configurationPath) {
// Seems an old installation!
$configurationPath = $this->getConfigurationHelper()->getConfigurationPath($path);
$this->setRootSys(realpath($configurationPath.'/../../../').'/');
Expand All @@ -640,12 +640,12 @@ public function setRootSysDependingConfigurationPath($path)
*/
public function writeConfiguration($version, $path, $output)
{
$output->writeln("");
$output->writeln("<comment>Starting the writeConfiguration process.</comment>");
$output->writeln('');
$output->writeln('<comment>Starting the writeConfiguration process.</comment>');
$portalSettings = $this->getPortalSettings();
$databaseSettings = $this->getDatabaseSettings();
$configurationPath = $this->getConfigurationHelper()->getConfigurationPath($path);
$output->writeln("<comment>Recovered all info. Reviewing.</comment>");
$output->writeln('<comment>Recovered all info. Reviewing.</comment>');

// Creates a YML File
$configuration = [];
Expand All @@ -672,10 +672,10 @@ public function writeConfiguration($version, $path, $output)

// Version settings
$configuration['system_version'] = $version;
$output->writeln("<comment>Data reviewed. Checking where to write to...</comment>");
$output->writeln('<comment>Data reviewed. Checking where to write to...</comment>');

if (file_exists($this->getRootSys().'config/parameters.yml.dist')) {
$output->writeln("<comment>parameters.yml.dist file found.</comment>");
$output->writeln('<comment>parameters.yml.dist file found.</comment>');

$file = $this->getRootSys().'config/parameters.yml';
if (!file_exists($file)) {
Expand All @@ -697,7 +697,7 @@ public function writeConfiguration($version, $path, $output)
}
} else {
// Try the old one
$output->writeln("<comment>Looking for main/install/configuration.dist.php.</comment>");
$output->writeln('<comment>Looking for main/install/configuration.dist.php.</comment>');

$contents = file_get_contents($this->getRootSys().'main/install/configuration.dist.php');

Expand All @@ -710,18 +710,18 @@ public function writeConfiguration($version, $path, $output)
$config['{DATABASE_DRIVER}'] = $configuration['driver'];

$config['{COURSE_TABLE_PREFIX}'] = '';
$config['{DATABASE_GLUE}'] = "`.`"; // keeping for backward compatibility
$config['{DATABASE_GLUE}'] = '`.`'; // keeping for backward compatibility
$config['{DATABASE_PREFIX}'] = '';
$config['{DATABASE_STATS}'] = $configuration['main_database'];
$config['{DATABASE_SCORM}'] = $configuration['main_database'];
$config['{DATABASE_PERSONAL}'] = $configuration['main_database'];
$config['TRACKING_ENABLED'] = "'true'";
$config['SINGLE_DATABASE'] = "false";
$config['SINGLE_DATABASE'] = 'false';

$config['{ROOT_WEB}'] = $portalSettings['site_url'];
$config['{ROOT_SYS}'] = $this->getRootSys();

$config['{URL_APPEND_PATH}'] = "";
$config['{URL_APPEND_PATH}'] = '';
$config['{SECURITY_KEY}'] = $configuration['security_key'];
$config['{ENCRYPT_PASSWORD}'] = $configuration['password_encryption'];

Expand All @@ -734,10 +734,10 @@ public function writeConfiguration($version, $path, $output)
}

$newConfigurationFile = $configurationPath.'configuration.php';
$output->writeln(sprintf("<comment>Writing config to %s</comment>", $newConfigurationFile));
$output->writeln(sprintf('<comment>Writing config to %s</comment>', $newConfigurationFile));

$result = file_put_contents($newConfigurationFile, $contents);
$output->writeln("<comment>Config file written.</comment>");
$output->writeln('<comment>Config file written.</comment>');
}

return $result;
Expand Down Expand Up @@ -789,9 +789,9 @@ public function updateConfiguration(OutputInterface $output, $dryRun, $newValues
$configurationPath = $this->getConfigurationPath();
$newConfigurationFile = $configurationPath.'configuration.php';

if ($dryRun == false) {
if (false == $dryRun) {
if (version_compare($newValues['system_version'], '1.10', '>=') ||
($newValues['system_version'] == '1.10.x' || $newValues['system_version'] == '1.11.x')
('1.10.x' == $newValues['system_version'] || '1.11.x' == $newValues['system_version'])
) {
$configurationPath = $_configuration['root_sys'].'app/config/';
$newConfigurationFile = $configurationPath.'configuration.php';
Expand Down Expand Up @@ -919,6 +919,7 @@ public function removeFiles($files, OutputInterface $output)
}

$fs = new Filesystem();

try {
if ($dryRun) {
$output->writeln('<comment>Files to be removed (--dry-run is on).</comment>');
Expand Down Expand Up @@ -969,20 +970,24 @@ public function getPackage(OutputInterface $output, $version, $updateInstallatio

// Download the chamilo package from from github:
if (empty($updateInstallation)) {
$updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/v".$version.".zip";
$updateInstallation = 'https://github.com/chamilo/chamilo-lms/archive/v'.$version.'.zip';

switch ($version) {
case 'master':
$updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/master.zip";
$updateInstallation = 'https://github.com/chamilo/chamilo-lms/archive/master.zip';

break;
case '1.9.x':
$updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/1.9.x.zip";
$updateInstallation = 'https://github.com/chamilo/chamilo-lms/archive/1.9.x.zip';

break;
case '1.10.x':
$updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/1.10.x.zip";
$updateInstallation = 'https://github.com/chamilo/chamilo-lms/archive/1.10.x.zip';

break;
case '1.11.x':
$updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/1.11.x.zip";
$updateInstallation = 'https://github.com/chamilo/chamilo-lms/archive/1.11.x.zip';

break;
}
}
Expand All @@ -998,7 +1003,7 @@ public function getPackage(OutputInterface $output, $version, $updateInstallatio
}

// Download file?
if (strpos($updateInstallation, 'http') === false) {
if (false === strpos($updateInstallation, 'http')) {
if (!file_exists($updateInstallation)) {
$output->writeln("<comment>File does not exists: $updateInstallation</comment>");

Expand All @@ -1012,14 +1017,14 @@ public function getPackage(OutputInterface $output, $version, $updateInstallatio
$output->writeln("<comment>Executing</comment> <info>wget -O $updateInstallationLocalName '$updateInstallation'</info>");
$output->writeln('');

$execute = "wget -O ".$updateInstallationLocalName." '$updateInstallation'\n";
$execute = 'wget -O '.$updateInstallationLocalName." '$updateInstallation'\n";

$systemOutput = shell_exec($execute);

$systemOutput = str_replace("\n", "\n\t", $systemOutput);
$output->writeln($systemOutput);
} else {
$output->writeln("<comment>Seems that the chamilo v".$version." has been already downloaded. File location:</comment> <info>$updateInstallationLocalName</info>");
$output->writeln('<comment>Seems that the chamilo v'.$version." has been already downloaded. File location:</comment> <info>$updateInstallationLocalName</info>");
}

$updateInstallation = $updateInstallationLocalName;
Expand All @@ -1044,7 +1049,7 @@ public function getPackage(OutputInterface $output, $version, $updateInstallatio
// Load from cache
$chamiloPath = $folderPath.'/chamilo-lms-CHAMILO_'.$versionTag.'_STABLE/main/inc/global.inc.php';
if (file_exists($chamiloPath)) {
$output->writeln("<comment>Files have been already extracted here: </comment><info>".$folderPath.'/chamilo-lms-CHAMILO_'.$versionTag.'_STABLE/'."</info>");
$output->writeln('<comment>Files have been already extracted here: </comment><info>'.$folderPath.'/chamilo-lms-CHAMILO_'.$versionTag.'_STABLE/'.'</info>');

return $folderPath.'/chamilo-lms-CHAMILO_'.$versionTag.'_STABLE/';
}
Expand All @@ -1061,12 +1066,13 @@ public function getPackage(OutputInterface $output, $version, $updateInstallatio
/** @var \SplFileInfo $file */
foreach ($files as $file) {
$chamiloLocationPath = $file->getRealPath();

break;
}
}

if (empty($chamiloLocationPath)) {
$output->writeln("<error>Chamilo folder structure not found in package.</error>");
$output->writeln('<error>Chamilo folder structure not found in package.</error>');

return 0;
}
Expand Down Expand Up @@ -1121,20 +1127,20 @@ public function copyPackageIntoSystem(
}

if (empty($chamiloLocationPath)) {
$output->writeln("<error>The chamiloLocationPath variable is empty<error>");
$output->writeln('<error>The chamiloLocationPath variable is empty<error>');

return 0;
}

$output->writeln("<comment>Copying files from </comment><info>$chamiloLocationPath</info><comment> to </comment><info>".$destinationPath."</info>");
$output->writeln("<comment>Copying files from </comment><info>$chamiloLocationPath</info><comment> to </comment><info>".$destinationPath.'</info>');

if (empty($destinationPath)) {
$output->writeln("<error>The root path was not set.<error>");
$output->writeln('<error>The root path was not set.<error>');

return 0;
} else {
$fileSystem->mirror($chamiloLocationPath, $destinationPath, null, ['override' => true]);
$output->writeln("<comment>Copy finished.<comment>");
$output->writeln('<comment>Copy finished.<comment>');

return 1;
}
Expand Down Expand Up @@ -1207,13 +1213,13 @@ public function copyConfigFilesToNewLocation(OutputInterface $output)
$configFile = str_replace('dist.', '', $file);

if (file_exists($confDir.$configFile)) {
$output->writeln("<comment> Moving file from: </comment>".$confDir.$configFile);
$output->writeln("<comment> to: </comment>".$configurationPath.$configFile);
$output->writeln('<comment> Moving file from: </comment>'.$confDir.$configFile);
$output->writeln('<comment> to: </comment>'.$configurationPath.$configFile);
if (!file_exists($configurationPath.$configFile)) {
$fs->copy($confDir.$configFile, $configurationPath.$configFile);
}
} else {
$output->writeln("<comment> File not found: </comment>".$confDir.$configFile);
$output->writeln('<comment> File not found: </comment>'.$confDir.$configFile);
}
}

Expand Down Expand Up @@ -1473,12 +1479,12 @@ protected function setConnections($version, $path, $databaseList)
foreach ($dbList as &$dbInfo) {
$params = $this->getDatabaseSettings();

if (isset($_configuration['single_database']) && $_configuration['single_database'] == true) {
if (isset($_configuration['single_database']) && true == $_configuration['single_database']) {
$em = \Doctrine\ORM\EntityManager::create($params, $config);
} else {
if ($section == 'course') {
if ('course' == $section) {
if (version_compare($version, '10', '<=')) {
if (strpos($dbInfo['database'], '_chamilo_course_') === false) {
if (false === strpos($dbInfo['database'], '_chamilo_course_')) {
//$params['dbname'] = $params['dbname'];
} else {
$params['dbname'] = str_replace('_chamilo_course_', '', $dbInfo['database']);
Expand All @@ -1490,9 +1496,11 @@ protected function setConnections($version, $path, $databaseList)
switch ($dbInfo['database']) {
case 'statistics_database':
$databaseName = isset($_configuration['statistics_database']) ? $_configuration['statistics_database'] : $databaseName;

break;
case 'user_personal_database':
$databaseName = isset($_configuration['user_personal_database']) ? $_configuration['user_personal_database'] : $databaseName;

break;
}
$params['dbname'] = $databaseName;
Expand Down
2 changes: 0 additions & 2 deletions src/Command/Database/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*
* Returns a dump of the database (caller should use an output redirect of some
* kind to store to a file.
*
* @package Chash\Command\Database
*/
class DumpCommand extends DatabaseCommand
{
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Database/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
{
$conn = $this->getHelper('db')->getConnection();

if (($fileNames = $input->getArgument('file')) !== null) {
if (null !== ($fileNames = $input->getArgument('file'))) {
foreach ((array) $fileNames as $fileName) {
if (!file_exists($fileName)) {
throw new \InvalidArgumentException(sprintf("SQL file '<info>%s</info>' does not exist.", $fileName));
Expand All @@ -89,7 +89,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$stmt->fetch();
$stmt->closeCursor();

$lines++;
++$lines;
} while ($stmt->nextRowset());

$output->write(sprintf('%d statements executed!', $lines).PHP_EOL);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Database/RunSQLCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$proc_status = proc_get_status($process);
$exit_code = proc_close($process);

return $proc_status["running"] ? $exit_code : $proc_status["exitcode"];
return $proc_status['running'] ? $exit_code : $proc_status['exitcode'];

/*$output->writeln('<comment>Starting Chamilo process</comment>');
$output->writeln('<info>Chamilo process ended succesfully</info>');
Expand Down
6 changes: 3 additions & 3 deletions src/Command/Database/ShowConnInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$_configuration = $this->getConfigurationArray();

$output->writeln("Database connection details:");
$output->writeln('Database connection details:');
$output->writeln("Host:\t".$_configuration['db_host']);
$output->writeln("User:\t".$_configuration['db_user']);
$output->writeln("Pass:\t".$_configuration['db_password']);
$output->writeln("DB:\t".$_configuration['main_database']);
$output->writeln("Connection string (add password manually for increased security:");
$output->writeln("mysql -h ".$_configuration['db_host']." -u ".$_configuration['db_user']." -p ".$_configuration['main_database']."\n");
$output->writeln('Connection string (add password manually for increased security:');
$output->writeln('mysql -h '.$_configuration['db_host'].' -u '.$_configuration['db_user'].' -p '.$_configuration['main_database']."\n");
}
}
10 changes: 6 additions & 4 deletions src/Command/Email/SendEmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$userTable = $_configuration['main_database'].'.user';
$adminTable = $_configuration['main_database'].'.admin';

require_once "SendEmailCommand.php";
require_once "SendEmailCommand.php";
require_once "SendEmailCommand.php";
require_once 'SendEmailCommand.php';
require_once 'SendEmailCommand.php';
require_once 'SendEmailCommand.php';

$recipient_name = $input->getArgument('recipient-name');
$recipient_email = $input->getArgument('recipient-email');
Expand All @@ -99,12 +99,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($conn instanceof \Doctrine\DBAL\Connection) {
$sql = "SELECT email, CONCAT(lastname, firstname) as name FROM $userTable u "
."LEFT JOIN $adminTable a ON a.user_id = u.user_id "
."ORDER BY u.user_id LIMIT 1";
.'ORDER BY u.user_id LIMIT 1';

try {
$stmt = $conn->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
$output->write('SQL error!'.PHP_EOL);

throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
}
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Files/CleanConfigFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$this->writeCommandHeader($output, "Cleaning config files.");
$this->writeCommandHeader($output, 'Cleaning config files.');

$helper = $this->getHelperSet()->get('question');
$question = new ConfirmationQuestion(
Expand Down
Loading

0 comments on commit dd8248e

Please sign in to comment.