<?php
$file_name = basename(__FILE__);
$realms = array(null);
if(class_exists('NexoraRealm') && NexoraRealm::enabled()) {
    $realms = defined('NEXORA_CRON_REALM_RUNNER')
        ? array(NexoraRealm::active())
        : NexoraRealm::ids();
}
foreach($realms as $realm) {
    try {
        if($realm !== null) NexoraRealm::selectPublic($realm,false);
        $r = new \Plugin\ReferralSystem\ReferralSystem($realm,false);
        $r->checkUnverifiedReferrals();
        $r->checkReferrals();
        $r->checkPendingRewardReferrals();
        updateCronLastRun($file_name);
    } catch(Throwable $e) {
        @error_log('[Referral cron]['.($realm === null ? 'default' : $realm).'] '.$e->getMessage());
    }
}
