format('Y-m-d H:i:s'); $cutoffDate = AutoPublishLib::secondSundayBackwardDate($now); $builder = $db->table('attendance_day'); $builder->where('status', 'submitted') ->groupStart() ->where('auto_publish_at <=', $nowStr) ->orGroupStart() ->where('auto_publish_at IS NULL', null, false) ->where('date <=', $cutoffDate) ->groupEnd() ->groupEnd(); $count = $builder->countAllResults(false); // keep the WHEREs if ($count > 0) { $builder->update([ 'status' => 'published', 'published_by' => 0, // system 'published_at' => $nowStr, 'updated_at' => $nowStr, ]); } CLI::write("Auto-publish checked at {$nowStr} (TZ: {$zone->getName()}). Published rows: {$count}."); } }