Example #1
0
 /**
  * Checks to see if any of the dependent tables have been modified since this table
  * was last modified.  If so, it will drop the table and regenerate it.
  */
 public function update()
 {
     $mod_times = \Dataface_Table::getTableModificationTimes();
     if (!isset($mod_times[$this->tableName])) {
         $me = 0;
     } else {
         $me = $mod_times[$this->tableName];
     }
     $outOfDate = false;
     foreach ($this->dependencies as $dep) {
         if (@$mod_times[$dep] > $me) {
             $outOfDate = true;
             break;
         }
     }
     if ($outOfDate) {
         \df_q("DROP TABLE IF EXISTS `" . str_replace('`', '', $this->tableName) . "`");
         \df_q($this->sql);
         import('Dataface/IO.php');
         \Dataface_IO::touchTable($this->tableName);
     }
 }
Example #2
0
 /**
  * @brief Returns an associative array mapping table names to
  * their associated modification as a unix timestamp.
  *
  * Note that these values may not be accurate for views and innodb tables.  Not 
  * sure if this is a MySQL bug or a feature.
  * 
  * @param boolean $refresh Whether to refresh the stats or use cached version.
  *		Generally leave this false as it updates once per request anyways.
  *
  * @return array(string=>timestamp) Associative array of table names and their associated
  *	modification timestamps.
  *
  */
 public static function &getTableModificationTimes($refresh = false)
 {
     static $mod_times = 0;
     if ($mod_times === 0 or $refresh) {
         $mod_times = array();
         $app = Dataface_Application::getInstance();
         $dbname = $app->_conf['_database']['name'];
         //if ( $app->getMySQLMajorVersion() < 5 ){
         //	$res = xf_db_query("show table status", df_db());
         //} else {
         //	$res = xf_db_query("select TABLE_NAME as Name, UPDATE_TIME as Update_time from information_schema.tables where TABLE_SCHEMA='".addslashes($dbname)."'", df_db());
         //}
         $res = xf_db_query("show tables", df_db());
         if (!$res) {
             throw new Exception(xf_db_error(df_db()));
         }
         $backup_times = null;
         //while ( $row = xf_db_fetch_assoc($res) ){
         while ($row = xf_db_fetch_row($res)) {
             $row['Name'] = $row[0];
             if (@$row['Update_time']) {
                 $mod_times[$row['Name']] = @strtotime($row['Update_time']);
             } else {
                 if (!$backup_times) {
                     $backup_times =& self::getBackupModificationTimes($refresh);
                 }
                 if (isset($backup_times[$row['Name']]) and $backup_times[$row['Name']]) {
                     $mod_times[$row['Name']] = $backup_times[$row['Name']];
                 } else {
                     $mod_times[$row['Name']] = time();
                     import('Dataface/IO.php');
                     Dataface_IO::touchTable($row['Name']);
                 }
             }
         }
     }
     return $mod_times;
 }