Skip to content

Commit

Permalink
fixed: cron handling of stale groups
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Aug 13, 2024
1 parent 3f23ca3 commit bf1d008
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions classes/ColdTrick/GroupTools/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit bf1d008

Please sign in to comment.