Skip to content

Commit 3aa77ce

Browse files
authored
Merge branch 'master' into BT21881
2 parents 23e182a + a2879dc commit 3aa77ce

23 files changed

+349
-378
lines changed

.env.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ JWT_PASSPHRASE=your_secret_passphrase
6262
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
6363
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
6464
###< symfony/messenger ###
65+
66+
###< additional settings ###
67+
DB_MANAGER_ENABLED='{{DB_MANAGER_ENABLED}}'
68+
SOFTWARE_NAME='{{SOFTWARE_NAME}}'
69+
SOFTWARE_URL='{{SOFTWARE_URL}}'
70+
DENY_DELETE_USERS='{{DENY_DELETE_USERS}}'
71+
HOSTING_TOTAL_SIZE_LIMIT='{{HOSTING_TOTAL_SIZE_LIMIT}}'

config/hosting_limits.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
hosting_limits:
3+
urls:
4+
1:
5+
- hosting_limit_users: 0
6+
- hosting_limit_teachers: 0
7+
- hosting_limit_courses: 0
8+
- hosting_limit_sessions: 0
9+
- hosting_limit_disk_space: 0
10+
- hosting_limit_active_courses: 0
11+
- hosting_total_size_limit: 0

config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ imports:
118118
- {resource: ../src/CoreBundle/Resources/config/services.yml}
119119
- {resource: ../src/LtiBundle/Resources/config/services.yml}
120120
- { resource: ./authentication.yaml }
121+
- {resource: ./hosting_limits.yml}

public/main/admin/user_list.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ function modify_filter($user_id, $url_params, $row): string
718718
);
719719
}
720720

721-
$deleteAllowed = !api_get_configuration_value('deny_delete_users');
721+
$deleteAllowed = api_get_env_variable('DENY_DELETE_USERS', false);
722722
if ($deleteAllowed) {
723723
if ($user_id != $currentUserId &&
724724
!$user_is_anonymous &&
@@ -1297,14 +1297,14 @@ function($from, $number_of_items, $column, $direction) use ($showDeletedUsers) {
12971297
$table->set_column_filter(11, 'modify_deleted_filter');
12981298
$actionsList['restore'] = get_lang('Restore');
12991299
if (api_is_platform_admin() &&
1300-
!api_get_configuration_value('deny_delete_users')
1300+
!api_get_env_variable('DENY_DELETE_USERS', false)
13011301
) {
13021302
$actionsList['destroy'] = get_lang('Destroy');
13031303
}
13041304
} else {
13051305
$table->set_column_filter(11, 'modify_filter');
13061306
if (api_is_platform_admin() &&
1307-
!api_get_configuration_value('deny_delete_users')
1307+
!api_get_env_variable('DENY_DELETE_USERS', false)
13081308
) {
13091309
$actionsList['delete'] = get_lang('Remove from portal');
13101310
}

public/main/admin/user_list_consent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ function status_filter($status)
613613
// Only show empty actions bar if delete users has been blocked
614614
$actionsList = [];
615615
if (api_is_platform_admin() &&
616-
!api_get_configuration_value('deny_delete_users')
616+
!api_get_env_variable('DENY_DELETE_USERS', false)
617617
) {
618618
$actionsList['delete'] = get_lang('Remove from portal');
619619
}

public/main/course_info/infocours.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -949,15 +949,14 @@
949949
$illustrationRepo->deleteIllustration($courseEntity);
950950
}
951951

952-
$limitCourses = api_get_configuration_value('hosting_limit_active_courses');
953-
if ($limitCourses > 0) {
952+
$access_url_id = api_get_current_access_url_id();
953+
954+
$limitCourses = get_hosting_limit($access_url_id, 'hosting_limit_active_courses');
955+
if ($limitCourses !== null && $limitCourses > 0) {
954956
$courseInfo = api_get_course_info_by_id($courseId);
955957

956-
// Check if
957-
if (COURSE_VISIBILITY_HIDDEN == $courseInfo['visibility'] &&
958-
$visibility != $courseInfo['visibility']
959-
) {
960-
$num = CourseManager::countActiveCourses($urlId);
958+
if (COURSE_VISIBILITY_HIDDEN == $courseInfo['visibility'] && $visibility != $courseInfo['visibility']) {
959+
$num = CourseManager::countActiveCourses($access_url_id);
961960
if ($num >= $limitCourses) {
962961
api_warn_hosting_contact('hosting_limit_active_courses');
963962

public/main/cron/user_import/client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'import_users',
2929
[
3030
'filepath' => api_get_path(SYS_UPLOAD_PATH)."users_import.csv",
31-
'security_key' => api_get_configuration_value('security_key'),
31+
'security_key' => api_get_env_variable('kernel.secret'),
3232
]
3333
);
3434
echo $response;

public/main/inc/global.inc.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@
9595
}
9696

9797
try {
98-
// Load legacy configuration.php
99-
if ($kernel->isInstalled()) {
100-
require_once $kernel->getConfigurationFile();
101-
} else {
98+
99+
if (!$kernel->isInstalled()) {
102100
throw new Exception('Chamilo is not installed');
103101
}
104102

public/main/inc/lib/api.lib.php

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2525
use Symfony\Component\Security\Core\User\UserInterface;
2626
use Symfony\Component\Validator\Constraints as Assert;
27+
use Symfony\Component\Yaml\Yaml;
2728
use ZipStream\Option\Archive;
2829
use ZipStream\ZipStream;
2930
use Chamilo\CoreBundle\Component\Utils\ActionIcon;
@@ -4307,12 +4308,8 @@ function api_get_version()
43074308
*/
43084309
function api_get_software_name()
43094310
{
4310-
$name = api_get_configuration_value('software_name');
4311-
if (!empty($name)) {
4312-
return $name;
4313-
} else {
4314-
return 'Chamilo';
4315-
}
4311+
$name = api_get_env_variable('SOFTWARE_NAME', 'Chamilo');
4312+
return $name;
43164313
}
43174314

43184315
function api_get_status_list()
@@ -5213,7 +5210,7 @@ function api_is_valid_secret_key($original_key_secret, $security_key)
52135210
return false;
52145211
}
52155212

5216-
return (string) $original_key_secret === sha1($security_key);
5213+
return (string) $original_key_secret === hash('sha512', $security_key);
52175214
}
52185215

52195216
/**
@@ -6816,6 +6813,65 @@ function api_get_configuration_value($variable)
68166813
return false;
68176814
}
68186815

6816+
/**
6817+
* Loads hosting limits from the YAML file.
6818+
*
6819+
* @return array The hosting limits.
6820+
*/
6821+
function load_hosting_limits(): array
6822+
{
6823+
$container = Container::$container;
6824+
6825+
$hostingLimits = $container->getParameter('hosting_limits');
6826+
6827+
return $hostingLimits['urls'] ?? [];
6828+
}
6829+
6830+
/**
6831+
* Gets a specific hosting limit.
6832+
*
6833+
* @param int $urlId The URL ID.
6834+
* @param string $limitName The name of the limit.
6835+
* @return mixed The value of the limit, or null if not found.
6836+
*/
6837+
function get_hosting_limit(int $urlId, string $limitName): mixed
6838+
{
6839+
$limits = load_hosting_limits();
6840+
6841+
foreach ($limits[$urlId] as $limitArray) {
6842+
if (isset($limitArray[$limitName])) {
6843+
return $limitArray[$limitName];
6844+
}
6845+
}
6846+
6847+
return null;
6848+
}
6849+
6850+
6851+
/**
6852+
* Retrieves an environment variable value with validation and handles boolean conversion.
6853+
*
6854+
* @param string $variable The name of the environment variable.
6855+
* @param mixed $default The default value to return if the variable is not set.
6856+
* @return mixed The value of the environment variable, converted to boolean if necessary, or the default value.
6857+
*/
6858+
function api_get_env_variable(string $variable, mixed $default = null): mixed
6859+
{
6860+
if (Container::$container->hasParameter($variable)) {
6861+
$value = Container::$container->getParameter($variable);
6862+
6863+
if ($value === '0') {
6864+
return false;
6865+
}
6866+
if ($value === '1') {
6867+
return true;
6868+
}
6869+
6870+
return $value;
6871+
}
6872+
6873+
return $default;
6874+
}
68196875
/**
68206876
* Retreives and returns a value in a hierarchical configuration array
68216877
* api_get_configuration_sub_value('a/b/c') returns api_get_configuration_value('a')['b']['c'].

public/main/inc/lib/course.lib.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6709,20 +6709,22 @@ public static function addVisibilityOptions(FormValidator $form): void
67096709
*
67106710
* @return bool|string
67116711
*/
6712-
private static function checkCreateCourseAccessUrlParam($_configuration, $accessUrlId, $param, $msgLabel)
6712+
private static function checkCreateCourseAccessUrlParam($accessUrlId, $param, $msgLabel)
67136713
{
6714-
if (isset($_configuration[$accessUrlId][$param]) && $_configuration[$accessUrlId][$param] > 0) {
6714+
$hostingLimit = get_hosting_limit($accessUrlId, $param);
6715+
6716+
if ($hostingLimit !== null && $hostingLimit > 0) {
67156717
$num = null;
67166718
switch ($param) {
67176719
case 'hosting_limit_courses':
6718-
$num = self::count_courses($accessUrlId);
6720+
$num = self::count_courses($accessUrlId);
67196721
break;
67206722
case 'hosting_limit_active_courses':
67216723
$num = self::countActiveCourses($accessUrlId);
67226724
break;
67236725
}
67246726

6725-
if ($num && $num >= $_configuration[$accessUrlId][$param]) {
6727+
if ($num && $num >= $hostingLimit) {
67266728
api_warn_hosting_contact($param);
67276729

67286730
Display::addFlash(

0 commit comments

Comments
 (0)