From bf1d00876e41893cb90efd847b29ef6a7dce30e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B4me=20Bakker?= Date: Tue, 13 Aug 2024 08:55:40 +0200 Subject: [PATCH] fixed: cron handling of stale groups --- classes/ColdTrick/GroupTools/Cron.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/classes/ColdTrick/GroupTools/Cron.php b/classes/ColdTrick/GroupTools/Cron.php index ee2c0c0..ab98acb 100644 --- a/classes/ColdTrick/GroupTools/Cron.php +++ b/classes/ColdTrick/GroupTools/Cron.php @@ -24,14 +24,12 @@ public static function notifyStaleGroupOwners(\Elgg\Event $event): void { $time = (int) $event->getParam('time', time()); // get stale groups - $groups = elgg_call(ELGG_IGNORE_ACCESS, function() use ($time) { - return self::findStaleGroups($time); - }); - if (empty($groups)) { - return; - } - - elgg_call(ELGG_IGNORE_ACCESS, function() use ($groups) { + elgg_call(ELGG_IGNORE_ACCESS, function() use ($time) { + $groups = self::findStaleGroups($time); + if (empty($groups)) { + return; + } + // process groups foreach ($groups as $group) { $stale_info = group_tools_get_stale_info($group); @@ -55,16 +53,16 @@ public static function notifyStaleGroupOwners(\Elgg\Event $event): void { * * @param int $ts timestamp to compare to * - * @return \ElggGroup[] + * @return null|\ElggBatch */ - protected static function findStaleGroups(int $ts): array { + protected static function findStaleGroups(int $ts): ?\ElggBatch { if (empty($ts)) { - return []; + return null; } $stale_timeout = (int) elgg_get_plugin_setting('stale_timeout', 'group_tools'); if ($stale_timeout < 1) { - return []; + return null; } $compare_ts_upper = strtotime("-{$stale_timeout} days", $ts); @@ -187,7 +185,7 @@ function (QueryBuilder $qb, $main_alias) use ($compare_ts_lower, $compare_ts_upp $group_guids = array_unique($group_guids); if (empty($group_guids)) { - return []; + return null; } return elgg_get_entities([