From 1f7580af3fbb5073685a5ca48da518185dcdbcd3 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 2 Sep 2023 09:12:37 +0200 Subject: [PATCH] Fixed `GetCurrentStock` caching --- services/StockService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/StockService.php b/services/StockService.php index 9ab1d98f..a993c4d5 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -620,9 +620,9 @@ class StockService extends BaseService } private static $CurrentStockCache = null; - public function GetCurrentStock() + public function GetCurrentStock(bool $useCache = false) { - if (self::$CurrentStockCache == null) + if (!$useCache || self::$CurrentStockCache == null) { $sql = 'SELECT * FROM stock_current'; $currentStockMapped = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_OBJ); @@ -665,7 +665,7 @@ class StockService extends BaseService public function GetDueProducts(int $days = 5, bool $excludeOverdue = false) { - $currentStock = $this->GetCurrentStock(); + $currentStock = $this->GetCurrentStock(true); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime("+$days days")), '<'); if ($excludeOverdue) @@ -678,7 +678,7 @@ class StockService extends BaseService public function GetExpiredProducts() { - $currentStock = $this->GetCurrentStock(); + $currentStock = $this->GetCurrentStock(true); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('-1 days')), '<'); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'due_type', 2);