fix: Add timeout and user fallback for cronjob safety

- set_time_limit(300) prevents infinite SMTP hangs
- Fallback to admin user if $user is empty in cronjob context

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eduard Wisch 2026-03-10 14:14:14 +01:00
parent 94356a92da
commit 886021bdd5

View file

@ -54,9 +54,19 @@ class PreisBot
{ {
global $conf, $user, $langs; global $conf, $user, $langs;
// Sicherheits-Timeout: Max 5 Minuten für den gesamten Job
@set_time_limit(300);
try { try {
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
// User-Kontext sicherstellen (Cronjob hat manchmal keinen User)
if (empty($user) || !is_object($user) || empty($user->id)) {
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user = new User($this->db);
$user->fetch(1); // Admin-User
}
$priceSource = getDolGlobalString('PREISBOT_PRICE_SOURCE', 'cheapest'); $priceSource = getDolGlobalString('PREISBOT_PRICE_SOURCE', 'cheapest');
$priceDirection = getDolGlobalString('PREISBOT_PRICE_DIRECTION', 'up_only'); $priceDirection = getDolGlobalString('PREISBOT_PRICE_DIRECTION', 'up_only');
$minMargin = (float) getDolGlobalString('PREISBOT_MIN_MARGIN', 20); $minMargin = (float) getDolGlobalString('PREISBOT_MIN_MARGIN', 20);