public static function lockTables($value) { if (self::$dbConnection) { throw new Exception("Unable to lock tables, connection already established."); } self::$lockTables = (bool) $value; gfDebug('Tables won\'t be locked'); }
public function executeJobs() { $num = count($this->jobs); if ($num) { gfDebug("Executing {$num} background jobs."); foreach ($this->jobs as $job) { $job(); } } }
function shutdown() { if (Database::hasBeenUsed()) { Database::commit(); } // Jobs must not write to database! $queue = JobQueue::getInstance(); $jobs = $queue->executeJobs(); gfDebug("Request ended.\n"); }
private function sendGenericSms($text) { global $gvDebug; if ($gvDebug['active'] && $gvDebug['disableSms']) { return true; } // Get cURL resource $curl = curl_init(); // Set some options curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $this->url . "&text=" . urlencode($text))); // Send the request and save response $resp = curl_exec($curl); gfDebug("Ricevuta risposta\n" . $resp); // Close request to clear up some resources curl_close($curl); if (strpos($resp, "error") !== false) { return false; } return true; }
public static function getClassOrRedirect($pageRequested) { // Handle api reguests if ($pageRequested == "api") { // Log POST data gfDebug(print_r($_POST, true)); return "ApiPage"; } if (array_key_exists($pageRequested, self::$ROUTER_MAP)) { $target = self::$ROUTER_MAP[$pageRequested]; if (strpos($target, "=>") === 0) { // Redirect global $gvPath; $target = substr($target, 2); $redirect = new RedirectOutput("{$gvPath}/{$target}"); return $redirect; } return $target; } //TODO to implement generic error page die('Page unkown in PageRouter'); }
public static function fromDatabaseSearchByCity($city) { $city = mb_strtolower(trim($city), 'utf-8'); $city = str_replace(self::$replaceFrom, self::$replaceTo, $city); $words = explode(' ', $city); // Remove empty words and prepare for regex foreach ($words as $i => $word) { if ($word !== '') { $words[$i] = preg_quote($word); } else { unset($words[$i]); } } $sql = "SELECT * FROM office WHERE of_search REGEXP ? " . "ORDER BY of_city, of_address"; $param = "(^| )(" . implode("|", $words) . ")(\$| )"; $stmt = Database::prepareStatement($sql); if (!$stmt->execute(array($param))) { gfDebug(print_r($stmt->errorInfo(), true)); gfDebug(print_r($words, true)); throw new Exception(__METHOD__ . " Error while reading offices from database"); } $rows = $stmt->fetchall(PDO::FETCH_ASSOC); $offices = array(); foreach ($rows as $row) { $offices[] = self::newFromDatabaseRow($row); } // Sort results to show most relevant entries first $ranking = array(); for ($i = 1; $i <= count($words); $i++) { $ranking[$i] = array(); } foreach ($offices as $office) { $search = $office->getSearch(); $level = 0; foreach ($words as $word) { gfDebug("Analizzo parola {$word} per {$search}"); if (strpos($search, $word) !== false) { gfDebug("La contiene e alzo il livello"); $level++; } } $ranking[$level][] = $office; gfDebug("La città {$office->getCity()} ha livello finale {$level}"); } gfDebug(print_r($words, true)); // Construct final array $ret = array(); foreach ($ranking as $level) { $ret = array_merge($level, $ret); } return $ret; }
public static function recordTicketTrash($ticket) { $source = $ticket->getSource(); $sourceId = $ticket->getSourceId(); // check if the record is present in the table $ban = self::fromDatabaseBySourceId($sourceId); if ($ban) { $ban->incrementTrashCount(); gfDebug('Incrementato valore trash, ora risulta ' . $ban->getTrashCount()); } else { $ban = self::newRecord(); $ban->setSource($source); $ban->setSourceId($sourceId); $ban->setTrashCount(1); } $ban->save(); }
<?php define("ENTRY_POINT", true); // PHP should keep sessions for at least 1 hour ini_set('session.gc_maxlifetime', 3600); // Autoloader include 'Autoloader.php'; spl_autoload_register('Autoloader::autoload'); // Load general functions include 'GeneralFunctions.php'; // Load settings include 'DefaultSettings.php'; if (file_exists($gvDirectory . '/LocalSettings.php')) { include $gvDirectory . '/LocalSettings.php'; } else { gfDebug('Warning: no LocalSettings found!'); }
public function output() { $jobs = JobQueue::getInstance(); if ($jobs->countJobs() > 0 && !$this->willCloseConnection) { gfDebug(__METHOD__ . " Forced close connection for background jobs."); $this->closeConnection(true); } $this->outputHttpHeaders(); $this->outputHttpBody(); if ($this->willCloseConnection) { @ini_set('zlib.output_compression', 'Off'); @apache_setenv('no-gzip', 1); header("Connection: close"); $outputSize = ob_get_length(); header("Content-Length: {$outputSize}"); } ob_end_flush(); ob_flush(); flush(); if ($this->willCloseConnection && session_id()) { session_write_close(); } }
public function getPeopleAndEta() { if ($this->table != "ticket_in") { gfDebug(__METHOD__ . " Warning! Requested ETA for a ticket not in queue."); return array(0, 0); } $td = TopicalDomain::fromDatabaseByCode($this->getCode()); if (!$td) { gfDebug(__METHOD__ . " Warning! Unable to compute ticket ETA."); return array(0, 0); } $peopleBefore = self::countTicketBefore($this->getCode(), $this->getNumber()); $people = self::getNumberTicketInQueue($this->getCode()); $eta = (int) ($td->getEta() / $people) * $peopleBefore; return array($peopleBefore, $eta); }
public function sendTrashNotice() { gfDebug('Send push for ticket trash to ' . $this->token); return $this->sendGenericPush('text'); }