Exemple #1
0
function runcron($cronid = 0)
{
    global $_SGLOBAL, $_SCONFIG, $_SBLOCK, $_TPL, $_SCOOKIE, $_SN, $space;
    $where = $cronid ? "cronid='{$cronid}'" : "available>'0' AND nextrun<='{$_SGLOBAL['timestamp']}'";
    $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('cron') . " WHERE {$where} ORDER BY nextrun LIMIT 1");
    //只运行一个
    if ($cron = $_SGLOBAL['db']->fetch_array($query)) {
        $lockfile = S_ROOT . './data/runcron_' . $cron['cronid'] . '.lock';
        $cronfile = S_ROOT . './source/cron/' . $cron['filename'];
        if (is_writable($lockfile)) {
            $locktime = filemtime($lockfile);
            if ($locktime > $_SGLOBAL['timestamp'] - 600) {
                //10分钟
                return NULL;
            }
        } else {
            @touch($lockfile);
        }
        @set_time_limit(1000);
        @ignore_user_abort(TRUE);
        cronnextrun($cron);
        if (!@(include $cronfile)) {
            runlog('CRON', $cron['name'] . ' : Cron script(' . $cron['filename'] . ') not found or syntax error', 0);
        }
        @unlink($lockfile);
    }
    //更新config
    cron_config();
}
function runcron($cronid = 0)
{
    global $timestamp, $db, $tablepre, $_DCACHE;
    $query = $db->query("SELECT * FROM {$tablepre}crons WHERE " . ($cronid ? "cronid='{$cronid}'" : "available>'0' AND nextrun<='{$timestamp}'") . " ORDER BY nextrun LIMIT 1");
    if ($cron = $db->fetch_array($query)) {
        $lockfile = DISCUZ_ROOT . './forumdata/runcron_' . $cron['cronid'] . '.lock';
        $cron['filename'] = str_replace(array('..', '/', '\\'), '', $cron['filename']);
        $cronfile = DISCUZ_ROOT . './include/crons/' . $cron['filename'];
        if (is_writable($lockfile) && filemtime($lockfile) > $timestamp - 600) {
            return NULL;
        } else {
            @touch($lockfile);
        }
        @set_time_limit(1000);
        @ignore_user_abort(TRUE);
        $cron['minute'] = explode("\t", $cron['minute']);
        cronnextrun($cron);
        extract($GLOBALS, EXTR_SKIP);
        if (!@(include $cronfile)) {
            errorlog('CRON', $cron['name'] . ' : Cron script(' . $cron['filename'] . ') not found or syntax error', 0);
        }
        @unlink($lockfile);
    }
    $query = $db->query("SELECT nextrun FROM {$tablepre}crons WHERE available>'0' ORDER BY nextrun LIMIT 1");
    $nextrun = $db->result($query, 0);
    if (!$nextrun === FALSE) {
        require_once DISCUZ_ROOT . './include/cache.func.php';
        $_DCACHE['settings']['cronnextrun'] = $db->result($query, 0);
        updatesettings();
    }
}
Exemple #3
0
function runcron($cronid = 0, $debug = 0)
{
    global $_SGLOBAL, $_SCONFIG, $_SBLOCK, $lang;
    //锁定
    $lockfile = S_ROOT . './log/cron.lock.log';
    if (file_exists($lockfile) && !$debug) {
        if ($_SGLOBAL['timestamp'] - filemtime($lockfile) < 300) {
            //5分钟
            return;
        }
    }
    if (@($fp = fopen($lockfile, 'w'))) {
        fwrite($fp, "{$cronid}\n");
        fclose($fp);
    }
    //读取cron列表缓存
    if (empty($_SGLOBAL['crons'])) {
        errorlog('CRON', $cron['name'] . " : Cron script cache list is empty", 0);
        @unlink($lockfile);
        return;
    }
    @set_time_limit(1000);
    @ignore_user_abort(TRUE);
    $cronids = array();
    $crons = $cronid ? array($cronid => $_SGLOBAL['crons'][$cronid]) : $_SGLOBAL['crons'];
    if (empty($crons) || !is_array($crons)) {
        errorlog('CRON', $cron['name'] . " : Cron script list is empty", 0);
        @unlink($lockfile);
        return;
    }
    foreach ($crons as $id => $cron) {
        if ($cron['nextrun'] <= $_SGLOBAL['timestamp'] || $id == $cronid) {
            $cronids[] = $id;
            if (empty($cron[filename])) {
                errorlog('CRON', "Cron script({$cron['filename']}) not found", 0);
                continue;
            }
            if ($debug) {
                if (!(include S_ROOT . ($cronfile = "./include/cron/{$cron['filename']}"))) {
                    errorlog('CRON', $cron['name'] . " : Cron script({$cronfile}) syntax error", 0);
                }
            } else {
                if (!@(include S_ROOT . ($cronfile = "./include/cron/{$cron['filename']}"))) {
                    errorlog('CRON', $cron['name'] . " : Cron script({$cronfile}) syntax error", 0);
                }
            }
        }
    }
    cronnextrun($cronids);
    @unlink($lockfile);
}
Exemple #4
0
function runcron($cronid = 0)
{
    global $_G, $_SGLOBAL, $_SBLOCK, $lang;
    //鎖定
    $lockfile = B_ROOT . './log/cron.lock.log';
    if (file_exists($lockfile)) {
        if ($_G['timestamp'] - filemtime($lockfile) < 300) {
            //5分鐘
            return;
        }
    }
    if (@($fp = fopen($lockfile, 'w'))) {
        fwrite($fp, "\n");
        fclose($fp);
    }
    //讀取cron列表緩存
    if (empty($_SGLOBAL['crons'])) {
        return;
    }
    @set_time_limit(1000);
    @ignore_user_abort(true);
    $cronids = array();
    $crons = $cronid ? array($cronid => $_SGLOBAL['crons'][$cronid]) : $_SGLOBAL['crons'];
    if (empty($crons) || !is_array($crons)) {
        return;
    }
    foreach ($crons as $id => $cron) {
        if ($cron['nextrun'] <= $_G['timestamp'] || $id == $cronid) {
            $cronids[] = $id;
            if (!@(include B_ROOT . ($cronfile = "./source/include/cron/{$cron['filename']}"))) {
                errorlog('CRON', $cron['name'] . " : Cron script({$cronfile}) not found or syntax error", 0);
            }
        }
    }
    cronnextrun($cronids);
    @unlink($lockfile);
}
                    cpmsg('crons_filename_invalid', '', 'error');
                } elseif ($weekdaynew == -1 && $daynew == -1 && $hournew == -1 && $minutenew === '') {
                    cpmsg('crons_time_invalid', '', 'error');
                }
                $db->query("UPDATE {$tablepre}crons SET weekday='{$weekdaynew}', day='{$daynew}', hour='{$hournew}', minute='{$minutenew}', filename='" . trim($filenamenew) . "' WHERE cronid='{$cronid}'");
                updatecache('crons');
                require_once DISCUZ_ROOT . './include/cron.func.php';
                cronnextrun($cron);
                cpmsg('crons_succeed', $BASESCRIPT . '?action=misc&operation=cron', 'succeed');
            }
        } else {
            if (!@(include_once DISCUZ_ROOT . ($cronfile = "./include/crons/{$cron['filename']}"))) {
                cpmsg('crons_run_invalid', '', 'error');
            } else {
                require_once DISCUZ_ROOT . './include/cron.func.php';
                cronnextrun($cron);
                cpmsg('crons_run_succeed', $BASESCRIPT . '?action=misc&operation=cron', 'succeed');
            }
        }
    }
} elseif ($operation == 'tag') {
    if (!$tagstatus) {
        cpmsg('tags_not_open', "{$BASESCRIPT}?action=settings&operation=functions#subtitle_tags");
    }
    if (submitcheck('tagsubmit') && !empty($tag)) {
        $tagdelete = $tagclose = $tagopen = array();
        foreach ($tag as $key => $value) {
            if ($value == -1) {
                $tagdelete[] = $key;
            } elseif ($value == 1) {
                $tagclose[] = $key;
if (!defined('IN_BRAND')) {
    exit('Access Denied');
}
$groupbuycronfile = B_ROOT . './data/system/updategroupbuygrade.cache.php';
if (!file_exists($groupbuycronfile)) {
    $groupbuycrontext = '$crongroupbuyid=0';
    writefile($groupbuycronfile, $groupbuycrontext, 'php');
}
@(include $groupbuycronfile);
$pernum = 1000;
$resultarr = array();
$wheresql = 'itemid>' . $crongroupbuyid . ' AND';
$groupbuynum = DB::result_first('SELECT COUNT(itemid) FROM ' . tname('groupbuyitems') . ' WHERE ' . $wheresql . ' grade>2 ORDER BY itemid ASC');
$query = DB::query('SELECT itemid, validity_end FROM ' . tname('groupbuyitems') . ' WHERE ' . $wheresql . ' grade>2 ORDER BY itemid ASC LIMIT ' . $pernum);
while ($value = DB::fetch($query)) {
    if (!empty($value['validity_end']) && $value['validity_end'] < $_G['timestamp']) {
        DB::query('UPDATE ' . tname('groupbuyitems') . ' SET grade=2 WHERE itemid=' . $value['itemid'], 'UNBUFFERED');
    }
    $resultarr[] = $value;
}
if ($groupbuynum > $pernum) {
    $cronlastgroupbuy = array_pop($resultarr);
    $crongroupbuyid = $cronlastgroupbuy['itemid'];
    $groupbuycrontext = '$crongroupbuyid=' . $crongroupbuyid;
    writefile($groupbuycronfile, $groupbuycrontext, 'php');
    runcron($cron['cronid']);
} else {
    $groupbuycrontext = '$crongroupbuyid=0';
    writefile($groupbuycronfile, $groupbuycrontext, 'php');
    cronnextrun(array($cron['cronid']));
}
Exemple #7
0
        cpmessage('implementation_cycle_incorrect_script');
    }
    $setarr = array('name' => $_POST['name'], 'filename' => $_POST['filename'], 'available' => $_POST['available'], 'weekday' => $_POST['weekday'], 'day' => $_POST['day'], 'hour' => $_POST['hour'], 'minute' => $postminute);
    if (empty($cronid)) {
        //ADD
        $setarr['type'] = 'user';
        $setarr['nextrun'] = $_SGLOBAL['timestamp'];
        $setarr['cronid'] = inserttable('cron', $setarr, 1);
        //返回cronid
    } else {
        //UPDATE
        updatetable('cron', $setarr, array('cronid' => $cronid));
        $setarr['cronid'] = $cronid;
    }
    //重新计算下次执行时间
    cronnextrun($setarr);
    //更新config
    cron_config();
    cpmessage('do_success', 'admincp.php?ac=cron');
}
if ($_GET['op'] == 'edit') {
    $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('cron') . " WHERE cronid='{$cronid}'");
    $thevalue = $_SGLOBAL['db']->fetch_array($query);
} elseif ($_GET['op'] == 'add') {
    $thevalue = array('week' => '-1', 'hour' => '-1', 'day' => '-1', 'minute' => '0', 'available' => 1);
} elseif ($_GET['op'] == 'delete') {
    $_SGLOBAL['db']->query("DELETE FROM " . tname('cron') . " WHERE cronid='{$cronid}' AND type='user'");
    //更新缓存
    cron_config();
    cpmessage('do_success', 'admincp.php?ac=cron');
} elseif ($_GET['op'] == 'run') {
Exemple #8
0
         showsetting('cron_edit_minutenew', 'minutenew', $cron['minute'], 'text');
         showsetting('cron_edit_filenamenew', 'filenamenew', $cron['filename'], 'text');
         showsubmit('editsubmit', 'submit', '', $extbutton . (!empty($from) ? '<input type="hidden" name="from" value="' . $from . '">' : ''));
         showtablefooter();
         showformfooter();
         bind_ajax_form();
     }
 } elseif ($_GET['run']) {
     $query = DB::query("SELECT * FROM " . tname("crons") . " WHERE cronid = {$_GET['run']}");
     $cron = DB::fetch($query);
     include_once B_ROOT . './source/function/cron.func.php';
     if (!@(include B_ROOT . ($cronfile = "./source/include/cron/{$cron['filename']}"))) {
         errorlog('CRON', $cron['name'] . " : Cron script({$cronfile}) not found or syntax error", 0);
         cpmsg($cron['name'] . " : Cron script({$cronfile}) not found or syntax error");
     } else {
         cronnextrun(array($_GET['run']));
         updatecronscache();
         cpmsg('message_success', 'admin.php?action=tool&operation=cron');
     }
 } else {
     if (!empty($_POST['deletesubmit']) && $_POST['multiop'] != 'available' && (!empty($_POST['multiop']) || !empty($_POST['newname']) || !empty($_POST['cronid']))) {
         if (!empty($_POST['newname'])) {
             DB::query("INSERT INTO " . tname("crons") . " (`available`,`type`,`name`, `weekday`, `day`, `hour`, `minute`) VALUES ( 0, 'user', '{$_POST['newname']}', -1, -1, -1, '')");
         }
         if (!empty($_POST['cronid'])) {
             foreach ($_POST['cronid'] as $key => $cronid) {
                 DB::query("UPDATE " . tname("crons") . " SET available = " . ($_POST['available'][$cronid] ? 1 : 0) . " WHERE cronid = {$cronid}");
             }
             if (!empty($_POST['multiop'])) {
                 $cronids = implode(",", $_POST['cronid']);
                 DB::query("DELETE FROM " . tname("crons") . " WHERE cronid IN (" . $cronids . ")");