tera_wurfl
[ class tree: tera_wurfl ] [ index: tera_wurfl ] [ all elements ]

Source for file tera_wurfl_updatedb.php

Documentation is available at tera_wurfl_updatedb.php

  1. <?php
  2. /*
  3.  * Tera_WURFL - PHP MySQL driven WURFL
  4.  * 
  5.  * Tera-WURFL was written by Steve Kamerman, Tera Technologies and is based on the
  6.  * WURFL PHP Tools from http://wurfl.sourceforge.net/.  This version uses a MySQL database
  7.  * to store the entire WURFL file to provide extreme performance increases.
  8.  * 
  9.  * @package tera_wurfl
  10.  * @author Steve Kamerman, Tera Technologies (kamermans AT teratechnologies DOT net)
  11.  * @version Stable 1.5.0 $Date: 2007/04/27 17:43:50 $
  12.  * @version Stable 1.5.0 $Date: 2007/04/27 17:43:50 $
  13.  * @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
  14.  * $Id: tera_wurfl_updatedb.php,v 1.1.2.4.2.8 2007/04/27 17:43:50 kamermans Exp $
  15.  * $RCSfile: tera_wurfl_updatedb.php,v $
  16.  * 
  17.  * Based On: WURFL PHP Tools by Andrea Trasatti ( atrasatti AT users DOT sourceforge DOT net )
  18.  *
  19.  */
  20. $source (isset($_GET['source']))$_GET['source']"local";
  21. $type (isset($_GET['type']))$_GET['type']"main";
  22. require_once('../tera_wurfl_config.php');
  23. require_once(WURFL_PARSER_FILE);
  24.  
  25. // connect to DB
  26. $dbcon mysql_connect(DB_HOST,DB_USER,DB_PASSor die("Could not connect to MySQL Server (".DB_HOST."): ".mysql_error());
  27. // select DB
  28. mysql_select_db(DB_SCHEMA,$dbconor die("Connected to MySQL Server but could not select database (".DB_SCHEMA."): ".mysql_error($dbcon));
  29. // check main device tables (devices,patch,hybrid)
  30. $tablesres mysql_query("SHOW TABLES");
  31. $required_tables array(DB_DEVICE_TABLE,DB_PATCH_TABLE,DB_HYBRID_TABLE);
  32. $tables array();
  33. while($table mysql_fetch_row($tablesres))$tables[]=$table[0];
  34. foreach($required_tables as $req_table){
  35.     if(!in_array($req_table,$tables)){
  36.         echo "Required table '$req_tablewas missing in database (".print_r($tables,true)."), creating...<br />";
  37.         emptyWurflDevTable($req_table);
  38.     }
  39. }
  40. // check for cache table and create it if necessary
  41. $start utime();
  42. $results load_wurfl($type,$source);
  43. $end utime();
  44. if($type == "main"){
  45.     // if this is a patch update, these stats don't really make sense, although they ARE correct
  46.     echo "<strong>Database Update</strong><hr />";
  47.     echo "Total Update Time: ".($end-$start)."<br />";
  48.     echo "Total Devices in WURFL: ".$results['total']."<br />";
  49.     echo "Total Devices inserted in DB: ".$results['inserted']."<br />";
  50.     echo "Total Queries: ".$results['queries']."<br />";
  51.     echo "Largest Query: ".(ceil($results['maxquerysize']/1024))."KB<br />";
  52.     echo "Total Errors: ".count($results['errors'])."<br /><br />";
  53. }
  54. if(count($results['errors']== 0){
  55.     if(WURFL_PATCH_ENABLE === true){
  56.         echo "<strong>Applying Patch</strong><hr />";
  57.         if(!is_readable(WURFL_PATCH_FILE)){
  58.             echo "<strong>ERROR:</strong> You have the 'WURFL_PATCH_ENABLE' option turned on in the 
  59. configuration file (".CLASS_DIRNAME."tera_wurfl_config.php) but either the patch file (".WURFL_PATCH_FILE.") 
  60. is missing or I can't read it.  To fix this problem either turn the patch option off or make sure the file is
  61. in the correct location.";
  62.         }else{
  63.             $start utime();
  64.             $results apply_patch();
  65.             $end utime();
  66.             echo "Total Update Time: ".($end-$start)."<br />";
  67.             echo "Total Devices in Patch File: ".$results['total']."<br />";
  68.             echo "New Devices Added: ".$results['new']."<br />";
  69.             echo "Merged Devices: ".$results['merged']."<br />";
  70.             echo "Total Queries: ".$results['queries']."<br />";
  71.             echo "Total Errors: ".count($results['errors'])."<br /><br />";
  72.         }
  73.     }else{
  74.         echo "<strong>Patch Disabled in Configuration</strong><br />";
  75.     }
  76.     echo "<br /><br />Update Complete!<br />";
  77. }else{
  78.     echo "Did not attept to apply the patch since there were errors while updating.";
  79. }
  80. echo "<a href=\"index.php\">Return to administration tool.</a>";
  81.  
  82. function utime($time false){
  83.     if(!$time)$time time();
  84.     list($usec$secexplode(" "microtime());
  85.     $out ((float)$usec + (float)$sec);
  86.     return($out)
  87. }
  88. function javascriptRedir($page$seconds$custommsg=false){
  89.     global $redirectDelay;
  90.     if(isset($redirectDelay))$seconds += $redirectDelay;
  91.     $file '';
  92.     $line '';
  93.     $sent headers_sent($file,$line);
  94.     if($seconds == && !$sent){
  95.         //headers have not been sent and instant redir was requested - do it!
  96.         session_write_close();
  97.         header("Location$page");
  98. //        die("header");
  99.         exit;
  100.     }
  101.     $time $seconds 1000;
  102. //    die("JavaScript, ($sent)output started on line $line in $file");
  103.     if($custommsg){
  104.         echo $msg;
  105.     }else{
  106.         echo "<br><br>You will be redirected to <a href='$page'>$page</ain $seconds seconds...";
  107.     }
  108.     echo '<script language="javascript">'."\n".'setTimeout('."'".'window.location.href = "'.$page.'"'."'".', '.$time.');'.'</script>';
  109.     echo '<noscript><meta http-equiv="refresh" content="'.$time.';url='.$page.'" /></noscript>';
  110.     exit;
  111. }
  112. ?>

Documentation generated on Fri, 27 Apr 2007 12:10:22 -0400 by phpDocumentor 1.3.1