Ejemplo n.º 1
0
 public function rebuildCacheTable()
 {
     // We'll use this instance to rebuild the cache and to facilitate logging
     $rebuilder = new TeraWurfl();
     $cachetable = TeraWurflConfig::$TABLE_PREFIX . 'Cache';
     $temptable = TeraWurflConfig::$TABLE_PREFIX . 'Cache' . self::$DB_TEMP_EXT;
     $checkcachequery = "SHOW TABLES LIKE '{$cachetable}'";
     $checkres = $this->dbcon->query($checkcachequery);
     $this->numQueries++;
     if ($checkres->num_rows === 0) {
         // This can only happen if the table doesn't exist
         $this->createCacheTable();
         $this->numQueries++;
         // This table must be empty, so we're finished
         //			$rebuilder->toLog($query,LOG_ERR,"rebuildCacheTable");
         $rebuilder->toLog("Created empty cache table", LOG_NOTICE, "rebuildCacheTable");
         return true;
     }
     $droptemptable = "DROP TABLE IF EXISTS `{$temptable}`";
     $this->numQueries++;
     $this->dbcon->query($droptemptable);
     $query = "RENAME TABLE `{$cachetable}` TO `{$temptable}`";
     $this->numQueries++;
     $this->dbcon->query($query);
     $this->createCacheTable();
     $query = "SELECT `user_agent` FROM `{$temptable}`";
     $this->numQueries++;
     $res = $this->dbcon->query($query);
     if ($res->num_rows == 0) {
         // No records in cache table == nothing to rebuild
         $rebuilder->toLog("Rebuilt cache table, existing table was empty - this is very unusual.", LOG_WARNING, "rebuildCacheTable");
         return true;
     }
     while ($dev = $res->fetch_assoc()) {
         // Just looking the device up will force it to be cached
         $rebuilder->GetDeviceCapabilitiesFromAgent($dev['user_agent']);
         // Reset the number of queries since we're not going to re-instantiate the object
         $this->numQueries += $rebuilder->db->numQueries;
         $rebuilder->db->numQueries = 0;
     }
     $droptable = "DROP TABLE IF EXISTS `{$temptable}`";
     $this->numQueries++;
     $this->dbcon->query($droptable);
     $rebuilder->toLog("Rebuilt cache table.", LOG_NOTICE, "rebuildCacheTable");
     return true;
 }
 public function rebuildCacheTable()
 {
     // We'll use this instance to rebuild the cache and to facilitate logging
     $rebuilder = new TeraWurfl();
     $cachetable = TeraWurflConfig::$TABLE_PREFIX . 'Cache';
     $temptable = TeraWurflConfig::$TABLE_PREFIX . 'Cache' . self::$DB_TEMP_EXT;
     $this->numQueries++;
     if (!$this->tableExists($cachetable)) {
         // This can only happen if the table doesn't exist
         $this->createCacheTable();
         $this->numQueries++;
         // This table must be empty, so we're finished
         $rebuilder->toLog("Created empty cache table", LOG_NOTICE, "rebuildCacheTable");
         return true;
     }
     $this->numQueries++;
     $this->dropTableIfExists($temptable);
     $this->renameTable($cachetable, $temptable);
     $this->numQueries++;
     $this->createCacheTable();
     $query = "SELECT user_agent FROM {$temptable}";
     $this->numQueries++;
     $res = sqlsrv_query($this->dbcon, $query);
     if (!sqlsrv_has_rows($res)) {
         // No records in cache table == nothing to rebuild
         $rebuilder->toLog("Rebuilt cache table, existing table was empty.", LOG_WARNING, "rebuildCacheTable");
         return true;
     }
     while ($dev = sqlsrv_fetch_array($res)) {
         // Just looking the device up will force it to be cached
         $rebuilder->GetDeviceCapabilitiesFromAgent($dev['user_agent']);
         // Reset the number of queries since we're not going to re-instantiate the object
         $this->numQueries += $rebuilder->db->numQueries;
         $rebuilder->db->numQueries = 0;
     }
     $this->numQueries++;
     $this->dropTableIfExists($temptable);
     $rebuilder->toLog("Rebuilt cache table.", LOG_NOTICE, "rebuildCacheTable");
     return true;
 }
Ejemplo n.º 3
0
 /**
  * @return boolean
  */
 public function rebuildCacheTable()
 {
     // Use this instance to rebuild the cache and to facilitate logging
     $rebuilder = new TeraWurfl();
     $cachetable = TeraWurflConfig::$TABLE_PREFIX . 'Cache';
     $temptable = TeraWurflConfig::$TABLE_PREFIX . 'Cache' . self::$DB_TEMP_EXT;
     $this->_dropCollectionIfExists($temptable);
     $this->_renameCollection($cachetable, $temptable);
     $this->createCacheTable();
     $tempcoll = $this->dbcon->selectCollection($temptable);
     $cachecoll = $this->dbcon->selectCollection($cachetable);
     /* @var $fromcache MongoCursor */
     $fromcache = $tempcoll->find(array(), array("user_agent" => 1));
     $this->numQueries++;
     // migrate cached items from old cache
     if (0 == $fromcache->count()) {
         // No records in cache table == nothing to rebuild
         $this->_dropCollectionIfExists($temptable);
         $rebuilder->toLog('Rebuilt cache table, existing table was empty - this is very unusual.', LOG_WARNING, __FUNCTION__);
         return true;
     }
     foreach ($fromcache as $item) {
         // Just looking the device up will force it to be cached
         $rebuilder->getDeviceCapabilitiesFromAgent($item['user_agent']);
         // Reset the number of queries since we're not going to re-instantiate the object
         $this->numQueries += $rebuilder->db->numQueries;
         $rebuilder->db->numQueries = 0;
     }
     $this->_dropCollectionIfExists($temptable);
     $rebuilder->toLog('Rebuilt cache table.', LOG_NOTICE, __FUNCTION__);
     return true;
 }
Ejemplo n.º 4
0
    $base->db->createCacheTable();
    header("Location: index.php?msg=" . urlencode("The cache has been successfully cleared ({$base->db->numQueries} queries).") . "&severity=notice");
    exit(0);
}
$newfile = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE . ".zip";
$wurflfile = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE;
if ($source == "remote" || $source == "remote_cvs") {
    if ($source == "remote") {
        $dl_url = TeraWurflConfig::$WURFL_DL_URL;
    } elseif ($source == "remote_cvs") {
        $dl_url = TeraWurflConfig::$WURFL_CVS_URL;
    }
    echo "Downloading WURFL from {$dl_url} ...\n<br/>";
    flush();
    if (!file_exists($newfile) && !is_writable($base->rootdir . TeraWurflConfig::$DATADIR)) {
        $base->toLog("Cannot write to data directory (permission denied)", LOG_ERR);
        throw new Exception("Fatal Error: Cannot write to data directory (permission denied). (" . $base->rootdir . TeraWurflConfig::$DATADIR . ")<br/><br/><strong>Please make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: <pre>chmod -R 777 " . $base->rootdir . TeraWurflConfig::$DATADIR . "</pre></strong>");
        exit(1);
    }
    if (file_exists($newfile) && !is_writable($newfile)) {
        $base->toLog("Cannot overwrite WURFL file (permission denied)", LOG_ERR);
        throw new Exception("Fatal Error: Cannot overwrite WURFL file (permission denied). (" . $base->rootdir . TeraWurflConfig::$DATADIR . ")<br/><br/><strong>Please make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: <pre>chmod -R 777 " . $base->rootdir . TeraWurflConfig::$DATADIR . "</pre></strong>");
        exit(1);
    }
    // Download the new WURFL file and save it in the DATADIR as wurfl.zip
    @ini_set('user_agent', "PHP/Tera-WURFL_{$version}");
    $download_start = microtime(true);
    if (!($gzdata = file_get_contents($dl_url))) {
        throw new Exception("Error: Unable to download WURFL file from " . TeraWurflConfig::$WURFL_DL_URL);
        exit(1);
    }
 protected function checkPermissions()
 {
     if (!file_exists($this->wurfl_file_zipped) && !is_writable($this->wurfl->rootdir . TeraWurflConfig::$DATADIR)) {
         $this->wurfl->toLog("Cannot write to data directory (permission denied)", LOG_ERR);
         throw new TeraWurflException("Fatal Error: Cannot write to data directory (permission denied). (" . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR . ")\n\nPlease make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: chmod -R 777 " . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR);
     }
     if (file_exists($this->wurfl_file_zipped) && !is_writable($this->wurfl_file_zipped)) {
         $this->wurfl->toLog("Cannot overwrite WURFL file (permission denied)", LOG_ERR);
         throw new TeraWurflException("Fatal Error: Cannot overwrite WURFL file (permission denied). (" . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR . ")\n\nPlease make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: chmod -R 777 " . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR);
     }
 }