Exemplo n.º 1
0
<?php

global $db, $sugar_config, $current_language;
require_once "modules/asol_Reports/include_basic/reportsUtils.php";
$tmpFilesDir = "modules/asol_Reports/tmpReportFiles/";
$httpHtmlFile = $_REQUEST['httpHtmlFile'];
if (!file_exists($tmpFilesDir . $httpHtmlFile)) {
    $returnedString = "false";
    if (isset($sugar_config['asolReportsDispatcherMaxRequests']) && $sugar_config['asolReportsDispatcherMaxRequests'] > 0 && isset($_REQUEST["reportRequestId"])) {
        //Only if dispatcher is activated
        //************************************************//
        //***Clean database report_dispatcher if exists***//
        //************************************************//
        if (asol_ReportsUtils::dispatcherTableExists()) {
            $currentTime = time();
            $checkHttpFileTimeout = isset($sugar_config["asolReportsCheckHttpFileTimeout"]) ? $sugar_config["asolReportsCheckHttpFileTimeout"] : "1000";
            $timedOutStamp = $currentTime - $checkHttpFileTimeout;
            //Time to check report execution expiration time
            $closedWindowStamp = $currentTime - $checkHttpFileTimeout / 500;
            //Time to check last recall not updated for manual Reports (browser screen closed).
            $cleanDispatcherTableSql = "DELETE FROM asol_reports_dispatcher WHERE (status IN ('terminated', 'timeout')) OR (request_init_date < '" . date("Y-m-d H:i:s", $timedOutStamp) . "') OR ((status = 'waiting') AND (request_type = 'manual') AND (last_recall < '" . date("Y-m-d H:i:s", $closedWindowStamp) . "'))";
            $db->query($cleanDispatcherTableSql);
        }
        //************************************************//
        //***Clean database report_dispatcher if exists***//
        //************************************************//
        $reportsDispatcherSql = "SELECT COUNT(id) as 'reportsThreads' FROM asol_reports_dispatcher WHERE status = 'executing'";
        $reportsDispatcherRs = $db->query($reportsDispatcherSql);
        $reportsDispatcherRow = $db->fetchByAssoc($reportsDispatcherRs);
        $currentReportsRunningThreads = $reportsDispatcherRow["reportsThreads"];
        if ($currentReportsRunningThreads < $sugar_config['asolReportsDispatcherMaxRequests']) {
 public static function cleanDataBaseReportDispatcher()
 {
     global $db, $sugar_config;
     if (asol_ReportsUtils::dispatcherTableExists()) {
         $currentTime = time();
         $checkHttpFileTimeout = isset($sugar_config["asolReportsCheckHttpFileTimeout"]) ? $sugar_config["asolReportsCheckHttpFileTimeout"] : "1000";
         $timedOutStamp = $currentTime - $sugar_config['asolReportsMaxExecutionTime'];
         //Time to check report execution expiration time
         $closedWindowStamp = $currentTime - $checkHttpFileTimeout / 500;
         //Time to check last recall not updated for manual Reports (browser screen closed).
         $cleanDispatcherTableSql = "DELETE FROM asol_reports_dispatcher WHERE (status IN ('terminated', 'timeout')) OR (request_init_date < '" . date("Y-m-d H:i:s", $timedOutStamp) . "') OR ((status = 'waiting') AND (request_type = 'manual') AND (last_recall < '" . date("Y-m-d H:i:s", $closedWindowStamp) . "'))";
         $db->query($cleanDispatcherTableSql);
     }
 }