Fixing PHP notices + renaming "Script" class to "Tasks" class (used only when calling composer update - not used yet)

skala
Julio Montoya 12 years ago
parent 86d5008fbe
commit 581ca79746
  1. 4
      composer.json
  2. 1
      main/inc/lib/auth.lib.php
  3. 4
      main/install/1.9.0/update-db-1.8.8-1.9.0.inc.php
  4. 20
      src/ChamiloLMS/Command/Database/InstallCommand.php
  5. 275
      src/ChamiloLMS/Command/Database/InstallExtendCommand.php
  6. 21
      src/ChamiloLMS/Composer/Script.php
  7. 21
      src/ChamiloLMS/Composer/Tasks.php
  8. 4
      src/ChamiloLMS/Resources/config/prod.php

@ -57,8 +57,8 @@
"silex/web-profiler": "~1.0"
},
"scripts": {
"post-install-cmd": "ChamiloLMS\\Composer\\Script::postInstall",
"post-update-cmd": "ChamiloLMS\\Composer\\Script::postUpdate"
"post-install-cmd": "ChamiloLMS\\Composer\\Tasks::postInstall",
"post-update-cmd": "ChamiloLMS\\Composer\\Tasks::postUpdate"
},
"minimum-stability": "stable"
}

@ -59,6 +59,7 @@ class Auth {
AND course_rel_user.user_id = '" . $user_id . "' $without_special_courses
ORDER BY course_rel_user.sort ASC";
$result = Database::query($sql_select_courses);
$courses = array();
while ($row = Database::fetch_array($result)) {
//we only need the database name of the course
$courses[] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']);

@ -11,9 +11,7 @@ $update = function($_configuration, $mainConnection, $dryRun, $output, $app) {
$mainConnection->beginTransaction();
$singleDbForm = $_configuration['single_database'];
$singleDbForm = isset($_configuration['single_database']) ? $_configuration['single_database'] : false;
$dbNameForm = $_configuration['main_database'];
$dbStatsForm = isset($_configuration['statistics_database']) ? $_configuration['statistics_database'] : $_configuration['main_database'];
$dbUserForm = isset($_configuration['user_personal_database']) ? $_configuration['user_personal_database'] : $_configuration['main_database'];

@ -224,9 +224,21 @@ class InstallCommand extends CommonCommand
}
}
$testConnection = $this->testDatabaseConnection($newConfigurationArray['db_host'], $newConfigurationArray['db_user'], $newConfigurationArray['db_password']);
if ($testConnection == 1) {
$output->writeln("<comment>Connection enabled for user: </comment><info>".$newConfigurationArray['db_user']);
} else {
$output->writeln("<error>No access to the database for user:</error><info>".$newConfigurationArray['db_user']."</info>");
exit;
}
$configurationWasSaved = $this->writeConfiguration($newConfigurationArray, $version);
if ($configurationWasSaved) {
global $app;
$app['chamilo.log'] = $app['cache.path'].'chamilo_install.log';
//Installing database
$result = $this->install($version, $newConfigurationArray, $output);
@ -393,14 +405,6 @@ class InstallCommand extends CommonCommand
{
$sqlFolder = $this->getInstallationPath($version);
$testConnection = $this->testDatabaseConnection($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password']);
if ($testConnection == 1) {
$output->writeln("<comment>Connection enabled for user: </comment><info>".$_configuration['db_user']);
} else {
$output->writeln("<error>No access to the database for user:</error><info>".$_configuration['db_user']."</info>");
exit;
}
$databaseMap = $this->getDatabaseMap();

@ -12,7 +12,7 @@ use Symfony\Component\Console;
use Symfony\Component\Yaml\Dumper;
/**
* Class InstallCommand
* Class InstallExtendCommand
*/
class InstallExtendCommand extends InstallCommand
{
@ -139,277 +139,4 @@ class InstallExtendCommand extends InstallCommand
}
}
/**
*
* @param $newConfigurationArray
* @param $output
*
* @return bool
*/
public function createAdminUser($newConfigurationArray, $output)
{
$dialog = $this->getHelperSet()->get('dialog');
//Creating admin user
$adminUser = array(
'lastname' => 'Julio',
'firstname' => 'M',
'username' => 'admin',
'password' => 'admin',
'email' => 'admin@example.org',
'language' => 'english',
'phone' => '6666666'
);
$output->writeln("<comment>Creating an admin User</comment>");
$userInfo = array();
foreach ($adminUser as $key => $value) {
$data = $dialog->ask(
$output,
"Please enter the $key ($value): ",
$value
);
$userInfo[$key] = $data;
}
//By default admin is = 1 so we update it
$userId = $userInfo['user_id'] = 1;
$userInfo['auth_source'] = 'platform';
$userInfo['password'] = api_get_encrypted_password($userInfo['password']);
$result = \UserManager::update($userInfo);
if ($result) {
\UserManager::add_user_as_admin($userInfo['user_id']);
$output->writeln("<comment>User admin created with id: $userId</comment>");
return true;
}
return false;
}
/**
* Writes the configuration file a yml file
* @param $newConfigurationArray
* @param $version
*/
public function writeConfiguration($newConfigurationArray, $version)
{
$configurationPath = $this->getHelper('configuration')->getConfigurationPath();
$newConfigurationArray['system_version'] = $version;
$newConfigurationArray['db_glue'] = '`.`';
$newConfigurationArray['db_prefix'] = '';
$dumper = new Dumper();
$yaml = $dumper->dump($newConfigurationArray, 2); //inline
$newConfigurationFile = $configurationPath.'configuration.yml';
file_put_contents($newConfigurationFile, $yaml);
return file_exists($newConfigurationFile);
}
private function setDatabaseSettings($_configuration, $databaseName)
{
global $config;
$defaultConnection = array(
'driver' => 'pdo_mysql',
'dbname' => $databaseName,
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'host' => $_configuration['db_host'],
);
$em = \Doctrine\ORM\EntityManager::create($defaultConnection, $config);
//Fixes some errors
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('set', 'string');
$helpers = array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em),
);
foreach ($helpers as $name => $helper) {
$this->getApplication()->getHelperSet()->set($helper, $name);
}
$conn_return = @\Database::connect(array(
'server' => $_configuration['db_host'],
'username' => $_configuration['db_user'],
'password' => $_configuration['db_password']
));
global $database_connection;
$checkConnection = @\Database::select_db($databaseName, $database_connection);
}
/**
* Installs Chamilo
*
* @param string $version
* @param array $_configuration
* @param $output
* @return bool
*/
public function install($version, $_configuration, $output)
{
$sqlFolder = $this->getInstallationPath($version);
$testConnection = $this->testDatabaseConnection($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password']);
if ($testConnection == 1) {
$output->writeln("<comment>Connection enabled for user: </comment><info>".$_configuration['db_user']);
} else {
$output->writeln("<error>No access to the database for user:</error><info>".$_configuration['db_user']."</info>");
exit;
}
$databaseMap = $this->getDatabaseMap();
if (isset($databaseMap[$version])) {
$dbInfo = $databaseMap[$version];
$sections = $dbInfo['section'];
foreach ($sections as $section => $sectionData) {
foreach ($sectionData as $dbInfo) {
$databaseName = $dbInfo['name'];
$dbList = $dbInfo['sql'];
$output->writeln("<comment>Creating database</comment> <info>$databaseName ... </info>");
$result = $this->dropAndCreateDatabase($databaseName);
$this->setDatabaseSettings($_configuration, $databaseName);
//Fixing db list
foreach ($dbList as &$db) {
$db = $sqlFolder.$db;
}
//Importing files
if ($result) {
$command = $this->getApplication()->find('dbal:import');
//Importing sql files
$arguments = array(
'command' => 'dbal:import',
'file' => $dbList
);
$input = new ArrayInput($arguments);
$command->run($input, $output);
if ($databaseName == 'chamilo') {
api_set_setting('Institution', 'Portal');
api_set_setting('InstitutionUrl', 'Portal');
api_set_setting('siteName', 'Campus');
api_set_setting('emailAdministrator', 'admin@example.org');
api_set_setting('administratorSurname', 'M');
api_set_setting('administratorName', 'Julio');
api_set_setting('platformLanguage', 'english');
api_set_setting('allow_registration', '1');
api_set_setting('allow_registration_as_teacher', '1');
}
//Getting extra information about the installation
//$value = api_get_setting('chamilo_database_version');
//$output->writeln("<comment>Showing chamilo_database_version value:</comment> ".$value);
$output->writeln("<comment>Database </comment><info>$databaseName </info><comment>process ended!</comment>");
}
}
}
if (isset($sections) && isset($sections['course'])) {
//@todo fix this
$this->setDatabaseSettings($_configuration, $sections['main'][0]['name']);
foreach ($sections['course'] as $courseInfo) {
$databaseName = $courseInfo['name'];
$output->writeln("Inserting course database in chamilo: <info>$databaseName</info>");
$this->createCourse($databaseName);
}
}
$output->writeln("<comment>Check your installation status with </comment><info>chamilo:status</info>");
return true;
}
return false;
}
/**
* Creates a course (only an insert in the DB)
* @param $databaseName
*/
function createCourse($databaseName)
{
$params = array(
'code' => $databaseName,
'db_name' => $databaseName,
'course_language' => 'english',
'title' => $databaseName,
'visual_code' => $databaseName
);
@\Database::insert(TABLE_MAIN_COURSE, $params);
}
/**
* Creates a Database
* @todo use doctrine?
*
* @return resource
*/
public function dropAndCreateDatabase($databaseName)
{
/*
$command = $this->getApplication()->find('orm:schema-tool:create');
$arguments = array(
'command' => 'orm:schema-tool:create',
);
$input = new ArrayInput($arguments);
$command->run($input, $output);
exit;
*/
$this->dropDatabase($databaseName);
$result = \Database::query("CREATE DATABASE IF NOT EXISTS ".mysql_real_escape_string($databaseName)." DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci");
if ($result) {
return \Database::select_db($databaseName);
}
return false;
}
public function dropDatabase($name)
{
\Database::query("DROP DATABASE ".mysql_real_escape_string($name)."");
}
/**
* In step 3. Tests establishing connection to the database server.
* If it's a single database environment the function checks if the database exist.
* If the database doesn't exist we check the creation permissions.
*
* @return int 1 when there is no problem;
* 0 when a new database is impossible to be created, then the single/multiple database configuration is impossible too
* -1 when there is no connection established.
*/
public function testDatabaseConnection($dbHostForm, $dbUsernameForm, $dbPassForm)
{
$dbConnect = -1;
//Checking user credentials
if (@\Database::connect(
array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)
) !== false
) {
$dbConnect = 1;
} else {
$dbConnect = -1;
}
return $dbConnect; //return 1, if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection.
}
}

@ -1,21 +0,0 @@
<?php
namespace ChamiloLMS\Composer;
class Script
{
public static function postInstall()
{
/*chmod('resources/cache', 0777);
chmod('resources/log', 0777);
chmod('web/assets', 0777);
chmod('console', 0500);
exec('php console assetic:dump');*/
//echo 'Execting ChamiloLMS\Composer\Script::install';
}
public static function postUpdate()
{
}
}

@ -0,0 +1,21 @@
<?php
namespace ChamiloLMS\Composer;
class Tasks
{
public static function postInstall()
{
chmod('../../app/cache', 0777);
chmod('../../app/config', 0777);
chmod('../../app/courses', 0777);
chmod('../../app/logs', 0777);
//chmod('console', 0500);
//exec('php console assetic:dump');
}
public static function postUpdate()
{
}
}

@ -97,4 +97,8 @@ if (!is_dir($app['twig.cache.path'])) {
if (!is_dir($app['profiler.cache_dir'])) {
@mkdir($app['profiler.cache_dir'], api_get_permissions_for_new_directories());
}
if (is_file($app['chamilo.log']) && !is_writable($app['chamilo.log'])) {
unlink($app['chamilo.log']);
}
Loading…
Cancel
Save