Exemple #1
0
Table - recurrance
-----------
recurranceid - int
invoiceid - int
days - varchar(61)
months - varchar(23)
until - date  (Selected as UNIXTIMESTAMP)
action - ENUM('mail','create')
*/
define('SITE_ROOT', './');
require_once SITE_ROOT . 'includes/common.php';
$recurringItems = $ISL->FetchRecurrances();
print_r($recurringItems);
foreach ($recurringItems as $recurr) {
    if ($recurr['until'] >= time()) {
        if (parseCron($recurr['days'], $recurr['months'])) {
            error_reporting(E_ALL);
            $mainInvoice = $ISL->FetchInvoiceDetails($recurr['invoiceid']);
            // increse InvoiceID
            $mainInvoice['invoiceid'] = $ISL->FindNewInvoiceNumber($recurr['invoiceid'], $mainInvoice['invoiceid']);
            // increase due date
            // change issue date
            // fetch invoiceItems and modify as necessary
            $newInvoiceID = $ISL->InsertInvoice($mainInvoice);
            if ($recurr['action'] == 'mail') {
                file(SITE_ROOT . 'mail.php?id=' . $newInvoiceID);
            }
            unset($mainInvoice);
            unset($newInvoiceID);
        }
    }
Exemple #2
0
/* Set pathes and timezone. */
$zentaoPath = dirname(dirname(dirname(__FILE__))) . "/";
$cronPath = $zentaoPath . 'bin/cron';
include $zentaoPath . 'config/config.php';
include $zentaoPath . 'lib/crontab/crontab.class.php';
date_default_timezone_set($config->timezone);
/* Parase crons. */
$crons = parseCron($cronPath);
$lastParsed = time();
printCrons($crons);
/* Start the cron demon. */
while (true) {
    /* If need parse again, re parse the cron files. */
    if (needParseAgain($cronPath, $lastParsed)) {
        echo "\ncron files changed, re parse them...";
        $crons = parseCron($cronPath);
        $lastParsed = time();
        printCrons($crons);
    }
    $now = new datetime('now');
    foreach ($crons as $key => $cron) {
        if ($now > $cron['time']) {
            $crons[$key]['time'] = $cron['cron']->getNextRunDate();
            $output = array();
            $log = '';
            exec($cron['command'], $output, $return);
            $time = $now->format('G:i:s');
            foreach ($output as $out) {
                $log .= $out . "\n";
            }
            $log = "{$time} task " . ($key + 1) . " executed,\ncommand: {$cron['command']}.\nreturn : {$return}.\noutput : {$log}\n";