Skip to content

Commit

Permalink
fix: Add all rights to cron and manage session values for CronTask
Browse files Browse the repository at this point in the history
  • Loading branch information
ccailly committed Aug 19, 2024
1 parent 0258854 commit ff5f5cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/CronTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@ public static function launch($mode, $max = 1, $name = '')
}

if (self::get_lock()) {
// Save current session values that could be overwritten for cron tasks
$old_session_values = [
'glpicronuserrunning' => $_SESSION["glpicronuserrunning"] ?? null,
'glpiname' => $_SESSION["glpiname"] ?? null,
'glpigroups' => $_SESSION["glpigroups"] ?? null,
];

for ($i = 1; $i <= $max; $i++) {
$msgprefix = sprintf(
//TRANS: %1$s is mode (external or internal), %2$s is an order number,
Expand All @@ -855,6 +862,8 @@ public static function launch($mode, $max = 1, $name = '')
);
if ($crontask->getNeedToRun($mode, $name)) {
$_SESSION["glpicronuserrunning"] = "cron_" . $crontask->fields['name'];
$_SESSION["glpiname"] = "cron";
$_SESSION["glpigroups"] = [];

$function = sprintf('%s::cron%s', $crontask->fields['itemtype'], $crontask->fields['name']);

Expand Down Expand Up @@ -919,7 +928,15 @@ public static function launch($mode, $max = 1, $name = '')
Toolbox::logInFile('cron', $msgcron . "\n");
}
}
$_SESSION["glpicronuserrunning"] = '';

// Restore session values
foreach ($old_session_values as $key => $value) {
if ($value === null) {
unset($_SESSION[$key]);
} else {
$_SESSION[$key] = $value;
}
}
self::release_lock();
} else {
Toolbox::logInFile('cron', __("Can't get DB lock") . "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ public static function haveRight($module, $right)
/** @var \DBmysql $DB */
global $DB;

if (Session::isInventory()) {
if (Session::isInventory() || Session::isCron()) {
return true;
}

Expand Down

0 comments on commit ff5f5cd

Please sign in to comment.