From 235c1952c9da777dcc02a1d572dcb7d99fde3017 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 10 Nov 2016 15:33:55 +0100 Subject: [PATCH] Add configuration_file as setting --- plugin/vchamilo/lang/english.php | 2 ++ plugin/vchamilo/lib/Virtual.php | 24 ++++++++++--------- plugin/vchamilo/views/import.php | 40 ++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/plugin/vchamilo/lang/english.php b/plugin/vchamilo/lang/english.php index ca874881fb..6762a2f9b9 100644 --- a/plugin/vchamilo/lang/english.php +++ b/plugin/vchamilo/lang/english.php @@ -109,4 +109,6 @@ $strings['RootWebExists'] = 'An instance with the same root web exists.'; $strings['ImportInstance'] = 'Import instance'; $strings['ConfigurationPath'] = 'Chamilo configuration path'; $strings['UploadRealRoot'] = 'Upload files'; +$strings['DatabaseAccessShouldBeDifferentThanMasterChamilo'] = 'Database server should be different than the Chamilo master'; + diff --git a/plugin/vchamilo/lib/Virtual.php b/plugin/vchamilo/lib/Virtual.php index 401a9f299f..b54a850841 100644 --- a/plugin/vchamilo/lib/Virtual.php +++ b/plugin/vchamilo/lib/Virtual.php @@ -679,6 +679,7 @@ class Virtual if ($return === 'head') { $htmlHeadXtra[] = $str; } + if ($return) { return $str; } @@ -744,18 +745,20 @@ class Virtual global $virtualChamilo; if (!isset($virtualChamilo)) { - api_not_allowed(true, 'You have to edit the configuration.php. Please check the readme file.'); + api_not_allowed( + true, + 'You have to edit the configuration.php. Please check the readme file.' + ); } $coursePath = self::getConfig('vchamilo', 'course_real_root'); $homePath = self::getConfig('vchamilo', 'home_real_root'); $archivePath = self::getConfig('vchamilo', 'archive_real_root'); $uploadPath = self::getConfig('vchamilo', 'upload_real_root'); - $cmdSql = self::getConfig('vchamilo', 'cmd_mysql'); $cmdMySql = self::getConfig('vchamilo', 'cmd_mysqldump'); - if (empty($coursePath) || empty($homePath) || empty($uploadPath) || empty($archivePath) || empty($cmdSql)|| empty($cmdMySql)) { + if (empty($coursePath) || empty($homePath) || empty($uploadPath) || empty($archivePath) || empty($cmdSql) || empty($cmdMySql)) { api_not_allowed(true, 'You have to complete all plugin settings.'); } @@ -819,7 +822,6 @@ class Virtual ); if ($getManager) { - return $manager; } @@ -927,8 +929,10 @@ class Virtual $sitename = Database::escape_string($data->sitename); $institution = Database::escape_string($data->institution); + $sqls[] = "UPDATE {$settingstable} SET selected_value = '{$sitename}' WHERE variable = 'siteName' AND category = 'Platform' "; + $sqls[] = "UPDATE {$settingstable} SET selected_value = '{$institution}' WHERE variable = 'institution' AND category = 'Platform' "; @@ -992,7 +996,6 @@ class Virtual $data->lastcron = 0; $data->lastcrongap = 0; $data->croncount = 0; - $template = ''; $mainDatabase = api_get_configuration_value('main_database'); @@ -1001,7 +1004,7 @@ class Virtual Display::return_message('You cannot use the same database as the chamilo master', 'error') ); - return ; + return false; } self::ctrace('Registering: '.$data->root_web); @@ -1021,13 +1024,10 @@ class Virtual $statement = $connection->query('SELECT * FROM settings_current'); $settings = $statement->fetchAll(); $settings = array_column($settings, 'selected_value', 'variable'); - $institution = $settings['Institution']; $siteName = $settings['siteName']; - $newDatabase->sitename = $siteName; $newDatabase->institution = $institution; - $slug = $newDatabase->slug = $data->slug = Virtual::getSlugFromUrl($data->root_web); $id = Database::insert($table, (array) $newDatabase); } @@ -1036,6 +1036,10 @@ class Virtual throw new Exception('Was not registered'); } + if (empty($slug)) { + throw new Exception('Slug is empty'); + } + self::createDirsFromSlug($slug); self::ctrace("Create database"); Virtual::createDatabase($newDatabase); @@ -1139,7 +1143,6 @@ class Virtual } } - $absAlternateHome = Virtual::getConfig('vchamilo', 'home_real_root'); $absAlternateArchive = Virtual::getConfig('vchamilo', 'archive_real_root'); $absAlternateUpload = Virtual::getConfig('vchamilo', 'upload_real_root'); @@ -1204,7 +1207,6 @@ class Virtual $currentVersion = implode('.', [$versionParts[0], $versionParts[1], '0']); if (version_compare($version, $currentVersion, '<')) { - return $version; } diff --git a/plugin/vchamilo/views/import.php b/plugin/vchamilo/views/import.php index 33b9be9cb1..d40b89deb3 100644 --- a/plugin/vchamilo/views/import.php +++ b/plugin/vchamilo/views/import.php @@ -2,13 +2,13 @@ /* For licensing terms, see /license.txt */ $cidReset = true; - require_once '../../../main/inc/global.inc.php'; $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo')); // Security api_protect_admin_script(); + Virtual::checkSettings(); $plugin = VChamiloPlugin::create(); @@ -36,6 +36,15 @@ $form->addElement( // Database name. $form->addText('main_database', [$plugin->get_lang('maindatabase')]); +$form->addText( + 'configuration_file', + [ + $plugin->get_lang('ConfigurationPath'), + get_lang('Example').': /var/www/site/app/config/configuration.php' + ], + true +); + $form->addText( 'course_path', [ @@ -54,6 +63,14 @@ $form->addText( true ); +$form->addText( + 'upload_path', + [ + $plugin->get_lang('UploadPath'), + get_lang('Example').': /var/www/site/virtual/var/upload' + ], + true +); $form->addHeader(get_lang('To')); @@ -73,7 +90,12 @@ $form->addElement( ); // Database name. -$form->addText('to_main_database', [$plugin->get_lang('maindatabase'), $plugin->get_lang('DatabaseDescription')]); +$form->addText('to_main_database', + [ + $plugin->get_lang('maindatabase'), + $plugin->get_lang('DatabaseDescription'), + ] +); $form->addButtonSave($plugin->get_lang('savechanges'), 'submitbutton'); $content = $form->returnForm(); @@ -83,8 +105,13 @@ if ($form->validate()) { $coursePath = $values['course_path']; $homePath = $values['home_path']; + $confFile = $values['configuration_file']; - if (is_dir($coursePath) && is_dir($homePath)) { + if (is_dir($coursePath) && + is_dir($homePath) && + file_exists($confFile) && + is_readable($confFile) + ) { $currentHost = api_get_configuration_value('db_host'); $currentDatabase = api_get_configuration_value('main_database'); $currentUser = api_get_configuration_value('db_user'); @@ -94,11 +121,11 @@ if ($form->validate()) { $values['to_db_user'] !== $currentUser && $values['to_db_password'] !== $currentPassword ) { - } else { Display::addFlash( Display::return_message( - $plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo') + $plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo'), + 'warning' ) ); } @@ -109,14 +136,13 @@ if ($form->validate()) { $vchamilo->db_password = $values['db_password']; $vchamilo->db_host = $values['db_host']; $vchamilo->root_web = $values['root_web']; - $vchamilo->import_to_main_database = $values['to_main_database']; $vchamilo->import_to_db_user = $values['to_db_user']; $vchamilo->import_to_db_password = $values['to_db_password']; $vchamilo->import_to_db_host = $values['to_db_host']; - $vchamilo->course_path = $values['course_path']; $vchamilo->home_path = $values['home_path']; + $vchamilo->upload_path = $values['upload_path']; Virtual::importInstance($vchamilo); }