Skip to content

Internal: Rename hosting_limits.yaml to settings_overrides.yaml #6164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var/upload/*
/main/inc/conf/configuration.php

/config/authentication.yaml
/config/hosting_limits.yaml
/config/settings_overrides.yaml
/config/plugin.yaml

# Home
Expand Down
11 changes: 0 additions & 11 deletions config/hosting_limits.dist.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ imports:
- { resource: ../src/CoreBundle/Resources/config/services.yml }
- { resource: ../src/LtiBundle/Resources/config/services.yml }
- { resource: ./authentication.yaml, ignore_errors: not_found }
- { resource: ./hosting_limits.yaml, ignore_errors: not_found }
- { resource: ./settings_overrides.yaml, ignore_errors: not_found }
- { resource: ./plugin.yaml, ignore_errors: not_found }
11 changes: 11 additions & 0 deletions config/settings_overrides.dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
settings_overrides:
default:
hosting_limit:
users: 0
teachers: 0
courses: 0
sessions: 0
disk_space: 0
active_courses: 0
total_size: 0
2 changes: 1 addition & 1 deletion public/main/course_info/infocours.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@

$access_url_id = api_get_current_access_url_id();

$limitCourses = get_hosting_limit($access_url_id, 'hosting_limit_active_courses');
$limitCourses = get_hosting_limit($access_url_id, 'active_courses');
if ($limitCourses !== null && $limitCourses > 0) {
$courseInfo = api_get_course_info_by_id($courseId);

Expand Down
28 changes: 7 additions & 21 deletions public/main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6832,22 +6832,6 @@ function api_get_configuration_value($variable)
return false;
}

/**
* Loads hosting limits from the YAML file.
*
* @return array The hosting limits.
*/
function load_hosting_limits(): array
{
if (!Container::$container->hasParameter('hosting_limits')) {
return [];
}

$hostingLimits =Container::$container->getParameter('hosting_limits');

return $hostingLimits['urls'] ?? [];
}

/**
* Gets a specific hosting limit.
*
Expand All @@ -6857,13 +6841,15 @@ function load_hosting_limits(): array
*/
function get_hosting_limit(int $urlId, string $limitName): mixed
{
$limits = load_hosting_limits();

if (!isset($limits[$urlId])) {
return null;
if (!Container::$container->hasParameter('settings_overrides')) {
return [];
}

foreach ($limits[$urlId] as $limitArray) {
$settingsOverrides = Container::$container->getParameter('settings_overrides');

$limits = $settingsOverrides[$urlId]['hosting_limit'] ?? $settingsOverrides['default']['hosting_limit'];

foreach ($limits as $limitArray) {
if (isset($limitArray[$limitName])) {
return $limitArray[$limitName];
}
Expand Down
2 changes: 1 addition & 1 deletion public/main/inc/lib/diagnoser.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function get_chamilo_data()
list($size, $none) = explode("\t", $du);
unset($none);

$limit = get_hosting_limit($access_url_id, 'hosting_limit_disk_space');
$limit = get_hosting_limit($access_url_id, 'disk_space');
if ($limit === null) {
$limit = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion public/main/inc/lib/sessionmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function create_session(
? (empty($accessUrlId) ? api_get_current_access_url_id() : (int) $accessUrlId)
: 1;

$hostingLimitSessions = get_hosting_limit($accessUrlId, 'hosting_limit_sessions');
$hostingLimitSessions = get_hosting_limit($accessUrlId, 'sessions');

if ($hostingLimitSessions !== null && $hostingLimitSessions > 0) {
$num = self::count_sessions();
Expand Down
6 changes: 3 additions & 3 deletions public/main/inc/lib/usermanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ public static function create_user(
$accessUrl = Container::getAccessUrlHelper()->getCurrent();
$access_url_id = $accessUrl->getId();

$hostingLimitUsers = get_hosting_limit($access_url_id, 'hosting_limit_users');
$hostingLimitUsers = get_hosting_limit($access_url_id, 'users');

if ($hostingLimitUsers !== null && $hostingLimitUsers > 0) {
$num = self::get_number_of_users();
if ($num >= $hostingLimitUsers) {
api_warn_hosting_contact('hosting_limit_users');
api_warn_hosting_contact('users');
Display::addFlash(
Display::return_message(
get_lang('Sorry, this installation has a users limit, which has now been reached. To increase the number of users allowed on this Chamilo installation, please contact your hosting provider or, if available, upgrade to a superior hosting plan.'),
Expand All @@ -202,7 +202,7 @@ public static function create_user(
}

if (1 === $status) {
$hostingLimitTeachers = get_hosting_limit($access_url_id, 'hosting_limit_teachers');
$hostingLimitTeachers = get_hosting_limit($access_url_id, 'teachers');

if ($hostingLimitTeachers !== null && $hostingLimitTeachers > 0) {
$num = self::get_number_of_users(1);
Expand Down
2 changes: 1 addition & 1 deletion public/main/install/install.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ function executeLexikKeyPair(\Chamilo\Kernel $kernel): void
function createExtraConfigFile(): void {
$files = [
'authentication',
'hosting_limits',
'settings_overrides',
'plugin',
];

Expand Down
34 changes: 17 additions & 17 deletions src/CoreBundle/Migrations/Schema/V200/Version20240806120000.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Version20240806120000 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Migrate settings from configuration.php to .env and hosting_limits.yaml files';
return 'Migrate settings from configuration.php to .env and settings_overrides.yaml files';
}

public function up(Schema $schema): void
Expand Down Expand Up @@ -44,40 +44,40 @@ public function up(Schema $schema): void
'WEBSERVICE_ENABLE' => !empty($_configuration['webservice_enable']) ? '1' : '0',
]);

// Ensure the hosting_limits.yaml file exists
$hostingLimitsFile = $rootPath.'/config/hosting_limits.yaml';
$hostingLimits = ['hosting_limits' => ['urls' => []]];
// Ensure the settings_overrides.yaml file exists
$hostingLimitsFile = $rootPath.'/config/settings_overrides.yaml';
$hostingLimits = ['settings_overrides' => []];

// Prepare hosting limits
if (\is_array($_configuration)) {
foreach ($_configuration as $key => $config) {
if (is_numeric($key) && \is_array($config)) {
// Handle configurations specific to URL IDs
$hostingLimits['hosting_limits']['urls'][$key] = [
['hosting_limit_users' => $config['hosting_limit_users'] ?? 0],
['hosting_limit_teachers' => $config['hosting_limit_teachers'] ?? 0],
['hosting_limit_courses' => $config['hosting_limit_courses'] ?? 0],
['hosting_limit_sessions' => $config['hosting_limit_sessions'] ?? 0],
['hosting_limit_disk_space' => $config['hosting_limit_disk_space'] ?? 0],
['hosting_limit_active_courses' => $config['hosting_limit_active_courses'] ?? 0],
['hosting_total_size_limit' => $_configuration['hosting_total_size_limit'] ?? 0],
$hostingLimits['settings_overrides'][$key]['hosting_limit'] = [
['users' => $config['hosting_limit_users'] ?? 0],
['teachers' => $config['hosting_limit_teachers'] ?? 0],
['courses' => $config['hosting_limit_courses'] ?? 0],
['sessions' => $config['hosting_limit_sessions'] ?? 0],
['disk_space' => $config['hosting_limit_disk_space'] ?? 0],
['active_courses' => $config['hosting_limit_active_courses'] ?? 0],
['total_size' => $_configuration['hosting_total_size_limit'] ?? 0],
];
}
}
}

// Format hosting limits as YAML
$yamlContent = "parameters:\n hosting_limits:\n urls:\n";
foreach ($hostingLimits['hosting_limits']['urls'] as $urlId => $limits) {
$yamlContent .= " {$urlId}:\n";
$yamlContent = "parameters:\n\tsettings_overrides:\n";
foreach ($hostingLimits['settings_overrides'] as $urlId => $limits) {
$yamlContent .= "\t\t{$urlId}:\n\t\t\thosting_limit:\n";
foreach ($limits as $limit) {
foreach ($limit as $key => $value) {
$yamlContent .= " - {$key}: {$value}\n";
$yamlContent .= "\t\t\t\t$key: $value\n";
}
}
}

// Write hosting limits to hosting_limits.yaml
// Write hosting limits to settings_overrides.yaml
file_put_contents($hostingLimitsFile, $yamlContent);
}

Expand Down
Loading