示例#1
0
function amr_request_cache($list = null)
{
    global $aopt;
    global $amain;
    $logcache = new adb_cache();
    $network = ausers_job_prefix();
    if (!empty($list)) {
        if ($logcache->cache_in_progress($logcache->reportid($list, 'user'))) {
            $text = sprintf(__('Cache of %s already in progress', 'amr-users'), $list);
            $logcache->log_cache_event($text);
            return $text;
        }
        if ($text = $logcache->cache_already_scheduled($list)) {
            $new_text = __('Report ', 'amr-users') . $list . ': ' . $text;
            $logcache->log_cache_event($new_text);
            return $new_text;
        }
        $time = time() + 5;
        $text = sprintf($network . __('Schedule background cacheing of report: %s', 'amr-users'), $list);
        $logcache->log_cache_event($text);
        $args[] = $list;
        wp_schedule_single_event($time, 'amr_' . $network . 'reportcacheing', $args);
        /* request for now a single run of the build function */
        return $text;
    } else {
        ameta_options();
        if (empty($aopt['list'])) {
            $text = $network . __('Error: No stored options found.', 'amr-users');
            $logcache->log_cache_event($text);
            return $text;
        } else {
            $no_rpts = count($aopt['list']);
        }
        $logcache->log_cache_event('<b>' . $network . sprintf(__('Received background cache request for %s reports', 'amr-users'), $no_rpts) . '</b>');
        $returntext = '';
        $time_increment = 60;
        $nexttime = time();
        foreach ($aopt['list'] as $i => $l) {
            if (!empty($amain['names'][$i])) {
                //if ($i <= count($amain['names'])) {
                $args = array('report' => $i);
                if ($text = $logcache->cache_already_scheduled($i)) {
                    $new_text = __('All reports: ', 'amr-users') . $text;
                    $logcache->log_cache_event($new_text);
                    $returntext .= $new_text . '<br />';
                    return $returntext;
                } else {
                    wp_schedule_single_event($nexttime, 'amr_' . $network . 'reportcacheing', $args);
                    /* request for now a single run of the build function */
                    $nexttime = $nexttime + $time_increment;
                    unset($args);
                    $text = sprintf(__('Schedule background cacheing of report: %s', 'amr-users'), $i);
                    $logcache->log_cache_event($text);
                    $returntext .= $text . '<br />';
                }
            }
        }
        return $returntext;
    }
    //$result = spawn_cron( time()); /* kick it off soon */
    // time()+3600 = one hour from now.
}
function amr_rebuildwarning($list)
{
    $logcache = new adb_cache();
    if ($logcache->cache_in_progress($logcache->reportid($list, 'user'))) {
        $text = sprintf(__('Cache of %s already in progress', 'amr-users'), $list);
        $logcache->log_cache_event($text);
        echo $text;
        return;
    } else {
        $text = $logcache->cache_already_scheduled($list);
        if (!empty($text)) {
            $new_text = __('Report ', 'amr-users') . $list . ': ' . $text;
            $logcache->log_cache_event($new_text);
            amr_users_message($new_text);
            //return;	 - let it run anyway
        }
    }
    echo alist_rebuildreal($list);
    return;
}