From cb2c2fddee26630cfe2d66bcc93011333fc7828f Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 17 Jul 2024 21:46:40 +0200 Subject: [PATCH] Admin: Enable the multi-URL feature by default (just create a new URL to unlock all related features) --- public/main/admin/index.php | 6 ++---- public/main/admin/settings.lib.php | 9 +------- public/main/inc/lib/api.lib.php | 21 ++++++++++++------- public/main/inc/lib/usergroup.lib.php | 2 +- public/main/install/configuration.dist.php | 6 ------ .../Admin/IndexBlocksController.php | 14 ++++++------- tests/scripts/multi_url_conversion.php | 1 - 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/public/main/admin/index.php b/public/main/admin/index.php index 3634f0c91a..2098836f8d 100644 --- a/public/main/admin/index.php +++ b/public/main/admin/index.php @@ -377,10 +377,8 @@ if (api_is_platform_admin()) { $items[] = ['url' => 'extra_field_list.php', 'label' => get_lang('Extra fields')]; - if (!empty($_configuration['multiple_access_urls'])) { - if (api_is_global_platform_admin()) { - $items[] = ['url' => 'access_urls.php', 'label' => get_lang('Configure multiple access URL')]; - } + if (api_is_global_platform_admin()) { + $items[] = ['url' => 'access_urls.php', 'label' => get_lang('Configure multiple access URL')]; } if ('true' == api_get_plugin_setting('dictionary', 'enable_plugin_dictionary')) { diff --git a/public/main/admin/settings.lib.php b/public/main/admin/settings.lib.php index 69699e5223..3d64545fe3 100644 --- a/public/main/admin/settings.lib.php +++ b/public/main/admin/settings.lib.php @@ -1091,13 +1091,6 @@ function generateSettingsForm($settings, $settings_by_access_list) ); $url_id = api_get_current_access_url_id(); - /* - if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) { - $group = array(); - $group[] = $form->createElement('button', 'mark_all', get_lang('Select all')); - $group[] = $form->createElement('button', 'unmark_all', get_lang('Unselect all')); - $form->addGroup($group, 'buttons_in_action_right'); - }*/ $default_values = []; $url_info = api_get_access_url($url_id); @@ -1114,7 +1107,7 @@ function generateSettingsForm($settings, $settings_by_access_list) $addedSettings[] = $row['variable']; - if (!empty($_configuration['multiple_access_urls'])) { + if (api_get_multiple_access_url()) { if (api_is_global_platform_admin()) { if (0 == $row['access_url_locked']) { if (1 == $url_id) { diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index a06cdd1be5..8a16d537f2 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -716,9 +716,7 @@ function api_get_path($path = '', $configuration = []) ); } - if (isset($configuration['multiple_access_urls']) && - $configuration['multiple_access_urls'] - ) { + if (api_get_multiple_access_url()) { // To avoid that the api_get_access_url() function fails since global.inc.php also calls the main_api.lib.php if (isset($configuration['access_url']) && !empty($configuration['access_url'])) { // We look into the DB the function api_get_access_url @@ -5970,16 +5968,23 @@ function api_get_course_url($courseId = null, $sessionId = null, $groupId = null } /** - * Check if the current portal has the $_configuration['multiple_access_urls'] parameter on. + * Check if there is more than the default URL defined in the access_url table. */ function api_get_multiple_access_url(): bool { - global $_configuration; - if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) { - return true; + static $accessUrlEnabled; + if (!isset($accessUrlEnabled)) { + $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT id FROM $table"; + $res = Database::query($sql); + if (Database::num_rows($res) > 1) { + $accessUrlEnabled = true; + } else { + $accessUrlEnabled = false; + } } - return false; + return $accessUrlEnabled; } function api_is_multiple_url_enabled(): bool diff --git a/public/main/inc/lib/usergroup.lib.php b/public/main/inc/lib/usergroup.lib.php index 035349e79c..b4a4405a35 100644 --- a/public/main/inc/lib/usergroup.lib.php +++ b/public/main/inc/lib/usergroup.lib.php @@ -59,7 +59,7 @@ class UserGroupModel extends Model $this->access_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $this->table_course = Database::get_main_table(TABLE_MAIN_COURSE); $this->table_user = Database::get_main_table(TABLE_MAIN_USER); - $this->useMultipleUrl = api_get_configuration_value('multiple_access_urls'); + $this->useMultipleUrl = api_get_multiple_access_url(); if ($this->allowTeachers()) { $this->columns[] = 'author_id'; } diff --git a/public/main/install/configuration.dist.php b/public/main/install/configuration.dist.php index 4e11f0bdd0..1f7e7ce978 100644 --- a/public/main/install/configuration.dist.php +++ b/public/main/install/configuration.dist.php @@ -49,12 +49,6 @@ $_configuration['hosting_total_size_limit'] = 0; // Security word for password recovery $_configuration['security_key'] = '{SECURITY_KEY}'; -// Activation for multi-url access -// When enabling multi-url, settings can be configured by multi-url using a simple -// sub-element. E.g. $_configuration['session_lifetime'][1] = true; could be turned into -// something like $_configuration['session_lifetime'][2] = false; to affect only URL -// with ID 2. The ID can be found in the access_url table. -//$_configuration['multiple_access_urls'] = true; $_configuration['software_name'] = 'Chamilo'; $_configuration['software_url'] = 'https://chamilo.org/'; // Deny the elimination of users diff --git a/src/CoreBundle/Controller/Admin/IndexBlocksController.php b/src/CoreBundle/Controller/Admin/IndexBlocksController.php index 278a99e1b0..ddb85383d7 100644 --- a/src/CoreBundle/Controller/Admin/IndexBlocksController.php +++ b/src/CoreBundle/Controller/Admin/IndexBlocksController.php @@ -441,14 +441,12 @@ class IndexBlocksController extends BaseController 'label' => $this->translator->trans('Extra fields'), ]; - if (!empty(api_get_configuration_value('multiple_access_urls'))) { - if (api_is_global_platform_admin()) { - $items[] = [ - 'class' => 'item-access-url', - 'url' => $this->generateUrl('legacy_main', ['name' => 'admin/access_urls.php']), - 'label' => $this->translator->trans('Configure multiple access URL'), - ]; - } + if (api_is_global_platform_admin()) { + $items[] = [ + 'class' => 'item-access-url', + 'url' => $this->generateUrl('legacy_main', ['name' => 'admin/access_urls.php']), + 'label' => $this->translator->trans('Configure multiple access URL'), + ]; } if ('true' === api_get_plugin_setting('dictionary', 'enable_plugin_dictionary')) { diff --git a/tests/scripts/multi_url_conversion.php b/tests/scripts/multi_url_conversion.php index 93d6dfee1e..4cd39335ee 100644 --- a/tests/scripts/multi_url_conversion.php +++ b/tests/scripts/multi_url_conversion.php @@ -120,4 +120,3 @@ $resU = Database::query($sqlU); echo "Table $tableAccessUrlRelUserGroup updated".PHP_EOL; echo "Database updated.".PHP_EOL; -echo "Please set \$_configuration['multiple_access_urls'] to true in the app/config/configuration.php file".PHP_EOL;