Internal: Scripts: Fix Config Access in Script - refs BT#21099

pull/5133/head
christianbeeznst 2 years ago
parent 70178f39b2
commit 763837ec9c
  1. 43
      public/main/inc/global.inc.php
  2. 12
      tests/scripts/disable_user_conditions.php

@ -58,24 +58,37 @@ if (!empty($flashBag->keys())) {
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false); $response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false);
$context = Container::getRouter()->getContext(); $context = Container::getRouter()->getContext();
$pos = strpos($currentBaseUrl, 'main'); $isCli = 'cli' === php_sapi_name();
$posPlugin = strpos($currentBaseUrl, 'plugin'); $baseUrl = null;
$posCertificate = strpos($currentBaseUrl, 'certificate'); if ($isCli) {
$cliOptions = getopt('', ['url:']);
if (false === $pos && false === $posPlugin && false === $posCertificate) { if (!empty($cliOptions['url'])) {
echo 'Cannot load current URL'; $baseUrl = $cliOptions['url'];
exit; }
} }
if (false !== $pos) { if ($isCli && $baseUrl) {
$newBaseUrl = substr($currentBaseUrl, 0, $pos - 1); $context->setBaseUrl($baseUrl);
}elseif (false !== $posPlugin) { } else {
$newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1); $pos = strpos($currentBaseUrl, 'main');
} elseif (false !== $posCertificate) { $posPlugin = strpos($currentBaseUrl, 'plugin');
$newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1); $posCertificate = strpos($currentBaseUrl, 'certificate');
}
$context->setBaseUrl($newBaseUrl); if (false === $pos && false === $posPlugin && false === $posCertificate) {
echo 'Cannot load current URL';
exit;
}
if (false !== $pos) {
$newBaseUrl = substr($currentBaseUrl, 0, $pos - 1);
}elseif (false !== $posPlugin) {
$newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1);
} elseif (false !== $posCertificate) {
$newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1);
}
$context->setBaseUrl($newBaseUrl);
}
try { try {
// Load legacy configuration.php // Load legacy configuration.php

@ -1,6 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt /* For licensing terms, see /license.txt
* This script disable users depending on 3 use cases and send an email to the user to inform him * This script disable users depending on 3 use cases and send an email to the user to inform him
* The 3 cases for disabling a user are : * The 3 cases for disabling a user are :
* * Case 1 * * Case 1
@ -8,17 +8,17 @@
* platform for more than 3 months then deactivate his account and send an email to the user * platform for more than 3 months then deactivate his account and send an email to the user
* * Case 2 * * Case 2
* If a learner has validated his terms and conditions and has not connected to the plateform * If a learner has validated his terms and conditions and has not connected to the plateform
* for more than 6 months then deactivate his account and send an email to the learner and to * for more than 6 months then deactivate his account and send an email to the learner and to
* it's superior. The superior of the learner is also removed from this learner (deassignment). * it's superior. The superior of the learner is also removed from this learner (deassignment).
* * Case 3 * * Case 3
* If a learner has completed its courses (a learner is considered to have finished their courses * If a learner has completed its courses (a learner is considered to have finished their courses
* if he has a generated the general certificate) and has not connected to the platfrom for more * if he has a generated the general certificate) and has not connected to the platfrom for more
* than 6 months then deactivate his account and send an email to the learner. * than 6 months then deactivate his account and send an email to the learner.
* */ * */
require_once __DIR__.'/../../public/main/inc/global.inc.php'; require_once __DIR__.'/../../public/main/inc/global.inc.php';
$senderId = api_get_setting('disable_user_conditions_sender_id'); $senderId = api_get_setting('platform.disable_user_conditions_sender_id');
if (empty($senderId)) { if (empty($senderId)) {
exit; exit;
@ -56,7 +56,7 @@ $sql = "SELECT u.id
LEFT JOIN extra_field_values ev LEFT JOIN extra_field_values ev
ON u.id = ev.item_id AND field_id = $fieldId ON u.id = ev.item_id AND field_id = $fieldId
WHERE WHERE
(ev.value IS NULL OR ev.value = '') AND (ev.field_value IS NULL OR ev.field_value = '') AND
u.active = 1 u.active = 1
$statusCondition $statusCondition
"; ";
@ -170,7 +170,7 @@ $sql = "SELECT u.id
INNER JOIN extra_field_values ev INNER JOIN extra_field_values ev
ON u.id = ev.item_id AND field_id = $fieldId ON u.id = ev.item_id AND field_id = $fieldId
WHERE WHERE
ev.value = 1 AND ev.field_value = 1 AND
u.active = 1 u.active = 1
$statusCondition $statusCondition
"; ";

Loading…
Cancel
Save