Exemplo n.º 1
0
if (isCgi()) {
    echo "<body>";
}
writeLogLine(($fromId ? "Continuing" : "Starting") . " recalculation.\n");
$items = $DB->select("SELECT * FROM item WHERE id > ? ORDER BY id", $fromId);
// ORDER BY id is IMPORTANT!
writeLogLine(sprintf("We have %d items left to process.\n\n", count($items)));
$hasError = false;
$t0 = microtime(true);
foreach ($items as $item) {
    foreach ($periods as $period => $periodName) {
        if ($onlyPeriod !== null && $period != $onlyPeriod) {
            continue;
        }
        try {
            recalcItemRow($item['id'], $to, $back, $period);
        } catch (Exception $e) {
            // nothing; error is already displayed above
            $hasError = true;
        }
    }
    writeLogLine("\n");
    if (isCgi() && microtime(true) - $t0 > MAX_RECALC_CGI_TIME) {
        writeLogLine("Continuing recalculation in a second...\n");
        $url = preg_replace('/fromid=[^&]*/s', $fid = 'fromid=' . $item['id'], $_SERVER['REQUEST_URI']);
        if ($url === $_SERVER['REQUEST_URI']) {
            $url .= (false === strpos($url, '?') ? '?' : '&') . $fid;
        }
        echo '<meta http-equiv="Refresh" content="1; URL=' . htmlspecialchars($url) . '"/>';
        exit;
    }
Exemplo n.º 2
0
 } else {
     $DB->update('UPDATE item SET name=?, "sql"=?, dsn_id=?, recalculatable=?, archived=?, dim=?, tags=?, modified=?, relative_to=? WHERE id=?', $item['name'], $item['sql'], $item['dsn_id'], $item['recalculatable'], $item['archived'], $item['dim'], $item['tags'], time(), $item['relative_to'], $id);
 }
 if (!empty($_POST['doSave'])) {
     $DB->commit();
     redirect("{$retpath}#{$id}", "Data is saved.");
 } else {
     if (!empty($_POST['doTest']) || !empty($_POST['doRecalc'])) {
         list($to, $back, $period) = parseToBackPeriod($_POST);
         $periods = $period ? array($period) : array_keys(getPeriods());
         $tables = array();
         $hideLogJs = '</div><script type="text/javascript">document.getElementById("log").style.display="none"</script>';
         try {
             echo '<div id="log">';
             foreach ($periods as $period) {
                 recalcItemRow($id, $to, $back, $period);
                 $data = generateTableData($to + 1, $back, $period, $id);
                 $periods = getPeriods();
                 $tables[$periods[$period]] = generateHtmlTableFromData($data, true);
             }
             echo $hideLogJs;
         } catch (Exception $e) {
             echo $hideLogJs;
             throw $e;
         }
         if (!empty($_POST['doTest'])) {
             $DB->rollBack();
         } else {
             $DB->commit();
             $_POST['item']['id'] = $id;
         }