Exemplo n.º 1
0
function DoCache(&$req)
{
    global $user_req;
    global $verbose;
    global $ROOT_DB;
    global $syslock;
    try {
        $reader = $req->CreateReader(REQUEST::READER_FORBID_CACHEREADER);
    } catch (ADEIException $e) {
        if ($e->getCode() == ADEIException::DISCONNECTED) {
            return;
        }
        $e->logInfo(translate("READER constructor is failed"), $req);
        return $req->GetLocationString() . ", Error: " . $e->getInfo();
    }
    try {
        $opts =& $req->GetOptions();
        $rootdb = $opts->Get('root_database');
        $list = $req->GetGroups($reader);
    } catch (ADEIException $e) {
        $e->logInfo(translate("Problem processing options"), $reader);
        return $req->GetLocationString() . ", Error: " . $e->getInfo();
    }
    if ($rootdb) {
        if (strchr($rootdb, "/")) {
            $db_info = false;
            $inq_app = adei_app("csv2root", "--file " . $rootdb . " --inquiry-latest-data", true);
            $app = adei_app("csv2root", "--file " . $rootdb, true);
        } else {
            try {
                $db_info = $ROOT_DB;
                $db_info['database'] = $rootdb;
                $database = new DATABASE($db_info);
            } catch (ADEIException $e) {
                unset($db_info['database']);
                try {
                    $database = new DATABASE($ROOT_DB);
                    $database->CreateDatabase($rootdb);
                } catch (ADEIException $e) {
                    $e->logInfo(translate("Problem accessing ROOT database \"%s\"", $rootdb), $req);
                    echo translate("Problem accessing ROOT database \"%s\": %s\n", $rootdb, $e->getInfo());
                    $rootdb = false;
                }
            }
            if ($rootdb) {
                $conprm = $db_info['driver'] . "://" . $db_info['host'] . ($db_info['port'] ? ":" . $db_info['port'] : "") . "/" . $rootdb;
                $inq_app = adei_app("csv2root", "--db " . $conprm . " --inquiry-latest-data", true);
                $app = adei_app("csv2root", "--db " . $conprm, true);
            }
        }
        if ($rootdb) {
            if (!$app || !$inq_app) {
                echo "csv2root is not present";
                $rootdb = false;
            } else {
                $groups = $reader->GetGroupList(REQUEST::NEED_INFO);
            }
        }
    }
    foreach ($list as $gid => $greq) {
        if (isset($user_req->props['db_group']) && $user_req->props['db_group'] != $gid) {
            continue;
        }
        if ($verbose) {
            echo "{$greq->props['db_server']} -- {$greq->props['db_name']} -- {$gid}:";
        }
        $syslocked = false;
        $prelocked = false;
        try {
            $cache = $greq->CreateCacheUpdater($reader);
            $syslock->Lock(LOCK::BLOCK);
            $syslocked = true;
            if (!$cache->PreLock()) {
                if ($verbose) {
                    echo " busy\n";
                }
                continue;
            }
            $prelocked = true;
            $syslocked = false;
            $syslock->UnLock();
            $cache->Update($ivl = NULL, CACHE::DIM_AUTO, verbose ? CACHE::VERBOSE : 0);
            $prelocked = false;
            $cache->UnLock();
            if ($rootdb) {
                $grname = " --group \"" . $groups[$gid]["name"] . "\"";
                ROOTCache($cache, $db_info, $app . $grname, $inq_app . $grname, $conprm ? $conprm : $rootdb);
            }
            unset($cache);
        } catch (ADEIException $e) {
            if ($prelocked) {
                $cache->UnLock();
            }
            if ($syslocked) {
                $syslock->UnLock();
            }
            if ($e->getCode() != ADEIException::DISABLED) {
                $e->logInfo(translate("Failed to update CACHE"), $cache ? $cache : $greq);
                if ($verbose) {
                    echo " failed\n";
                }
                return $greq->GetLocationString() . ", Error: " . $e->getInfo();
            }
        }
        if ($verbose) {
            echo " done\n";
        }
    }
    return 0;
}
Exemplo n.º 2
0
 function Close(STREAMHandler $h = NULL, $flags = 0)
 {
     $res = "";
     if (!$this->app_block_mode) {
         $res = parent::BlockEnd($h);
         $this->CloseFilter();
     }
     if ($this->info['end_app']) {
         $end_app = adei_app($this->info['end_app'], $this->end_opts, true);
     } else {
         if ($this->end_opts) {
             $end_app = adei_app($this->info['app'], $this->end_opts, true);
         } else {
             $end_app = false;
         }
     }
     if ($end_app) {
         $res = popen($end_app, "r");
         if ($this->filewriter) {
             while (!feof($res)) {
                 fread($fp, STREAM::BUFER_SIZE);
             }
         } else {
             if ($this->output) {
                 $h = $this->output;
             }
             if ($h) {
                 while (!feof($res)) {
                     $h->WriteData(fread($fp, STREAM::BUFER_SIZE));
                 }
             } else {
                 while (!feof($res)) {
                     $res .= fread($fp, STREAM::BUFER_SIZE);
                 }
             }
         }
         $ret = pclose($res);
         if ($ret) {
             throw new ADEIException(translate("APPFilter (%s) [end] is finished with error %u", $this->info['app'], $ret));
         }
     }
     if ($res) {
         return $res . parent::Close();
     }
     return parent::Close();
 }