Source for file cmd_line_admin.php
Documentation is available at cmd_line_admin.php
* Tera_WURFL - PHP MySQL driven WURFL
* Tera-WURFL was written by Steve Kamerman, and is based on the
* Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
* This version uses a MySQL database to store the entire WURFL file, multiple patch
* files, and a persistent caching mechanism to provide extreme performance increases.
* @package TeraWurflAdmin
* @author Steve Kamerman <stevekamerman AT gmail.com>
* @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
* @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
require_once realpath(dirname(__FILE__ ). '/../TeraWurfl.php');
require_once realpath(dirname(__FILE__ ). '/../TeraWurflLoader.php');
require_once realpath(dirname(__FILE__ ). '/../TeraWurflXMLParsers/TeraWurflXMLParser.php');
require_once realpath(dirname(__FILE__ ). '/../TeraWurflXMLParsers/TeraWurflXMLParser_XMLReader.php');
require_once realpath(dirname(__FILE__ ). '/../TeraWurflXMLParsers/TeraWurflXMLParser_SimpleXML.php');
$args = parseArgs($_SERVER['argv']);
if($base->db->connected !== true){
throw new Exception("Cannot connect to database: ". $base->db->errors[0]);
$twversion = $base->release_branch . " " . $base->release_version;
$wurflversion = $base->db->getSetting('wurfl_version');
$lastupdated = date('r',$base->db->getSetting('loaded_date'));
The command line WURFL updater for Tera-WURFL
Loaded WURFL: $wurflversion
Last Updated: $lastupdated
---------------------------------------
Usage: php cmd_line_admin.php [OPTIONS]
--update=<local,remote> The source of the WURFL file:
Update from your local wurfl.xml file:
Update from wurfl.sourceforge.net:
--clearCache Clear the device cache
--rebuildCache Rebuild the device cache by redetecting all
cached devices using the current WURFL
--stats Show statistics about the Tera-WURFL Database
$source = (string) $args['update'];
if($source != "local" && $source != "remote"){
echo "You must specify a source when using the --update option. Use --help for help\n\n";
$base->db->createCacheTable();
echo "Device cache has been cleared.\n";
$base->db->rebuildCacheTable();
echo "Device cache has been rebuilt.\n";
$config = $base->rootdir. "TeraWurflConfig.php";
$dbver = $base->db->getServerVersion();
$mergestats = $base->db->getTableStats(TeraWurflConfig::$TABLE_PREFIX. 'Merge');
$mergestats['bytesize'] = WurflSupport::formatBytes($mergestats['bytesize']);
Rows: {$mergestats['rows']}
Devices: {$mergestats['actual_devices']}
Size: {$mergestats['bytesize']}\n";
$indexstats = $base->db->getTableStats(TeraWurflConfig::$TABLE_PREFIX. 'Index');
$indexstats['bytesize'] = WurflSupport::formatBytes($indexstats['bytesize']);
Rows: {$indexstats['rows']}
Size: {$indexstats['bytesize']}\n";
$cachestats = $base->db->getTableStats(TeraWurflConfig::$TABLE_PREFIX. 'Cache');
$cachestats['bytesize'] = WurflSupport::formatBytes($cachestats['bytesize']);
Rows: {$cachestats['rows']}
Size: {$cachestats['bytesize']}\n";
$matcherList = $base->db->getMatcherTableList();
foreach($matcherList as $name){
$matchers[] = array('name'=> $name,'stats'=> $base->db->getTableStats($name));
Database Type: $dbtype (ver $dbver)
Loaded WURFL: $wurflversion
Last Updated: $lastupdated
---------- Table Stats -----------
foreach($matcherList as $matcher){
$matcherClass = $matcher. "UserAgentMatcher";
$file = $base->rootdir. "UserAgentMatchers/{$matcherClass}.php";
$ids = $matcherClass::$constantIDs;
if(empty($ids)) continue;
echo "\n$matcherClass\n\t". implode("\n\t",$ids);
foreach($matcherList as $matcher){
$matcherClass = $matcher. "UserAgentMatcher";
$file = $base->rootdir. "UserAgentMatchers/{$matcherClass}.php";
$ids = array_unique($ids);
echo "Recreating Procedures.\n";
$base->db->createProcedures();
case "batchLookupFallback":
if($base->db->db_implements_fallback){
$tree = $base->db->getDeviceFallBackTree($id);
foreach($tree as $node) $fallback[]= $node['id'];
die("Unsupported on this platform\n");
if($source == "remote" || $source == "remote_cvs"){
$dl_url = TeraWurflConfig::$WURFL_DL_URL;
}elseif($source == "remote_cvs"){
$dl_url = TeraWurflConfig::$WURFL_CVS_URL;
echo "Downloading WURFL from $dl_url ...\n\n";
$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. ")\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 ". $base->rootdir. TeraWurflConfig::$DATADIR);
$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. ")\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 ". $base->rootdir. TeraWurflConfig::$DATADIR);
// Download the new WURFL file and save it in the DATADIR as wurfl.zip
@ini_set('user_agent', "PHP/Tera-WURFL_$version");
Throw New Exception("Error: Unable to download WURFL file from ". TeraWurflConfig::$WURFL_DL_URL);
/* $destination=fopen($newfile,"w");
$source=fopen($dl_url,"r");
while ($block=fread($source,256*1024)) fwrite($destination,$block);
$download_time = microtime(true) - $download_start;
// Try to use ZipArchive, included from 5.2.0
if ($zip->open(str_replace('\\','/',$newfile)) === TRUE) {
Throw New Exception("Error: Unable to extract wurfl.xml from downloaded archive: $newfile");
echo "done ($wurflfile: $size)\nDownloaded in $download_time sec @ $download_rate \n\n";
//$ok = $base->db->initializeDB();
echo "Database Update OK\n";
echo "Total Time: ". $loader->totalLoadTime(). "\n";
echo "Parse Time: ". $loader->parseTime(). " (". $loader->getParserName(). ")\n";
echo "Validate Time: ". $loader->validateTime(). "\n";
echo "Sort Time: ". $loader->sortTime(). "\n";
echo "Patch Time: ". $loader->patchTime(). "\n";
echo "Database Time: ". $loader->databaseTime(). "\n";
echo "Cache Rebuild Time: ". $loader->cacheRebuildTime(). "\n";
echo "Number of Queries: ". $base->db->numQueries. "\n";
echo "--------------------------------\n";
echo "WURFL Version: ". $loader->version. " (". $loader->last_updated. ")\n";
echo "WURFL Devices: ". $loader->mainDevices. "\n";
echo "PATCH New Devices: ". $loader->patchAddedDevices. "\n";
echo "PATCH Merged Devices: ". $loader->patchMergedDevices. "\n";
echo "ERROR LOADING DATA!\n";
* Command Line Interface (CLI) options parser
* @see http://pwfisher.com/nucleus/index.php?itemid=45
* @param array Raw command line arguments
if ($eq !== false){ $o[substr($a,2,$eq- 2)] = substr($a,$eq+ 1); }
else { $k = substr($a,2); if (!isset ($o[$k])){ $o[$k] = true; } } }
else if (substr($a,0,1) == '-'){
else { foreach (str_split(substr($a,1)) as $k){ if (!isset ($o[$k])){ $o[$k] = true; } } } }
|