Ejemplo n.º 1
0
 function handle(&$params)
 {
     session_write_close();
     set_time_limit(0);
     import('Dataface/Index.php');
     $index = new Dataface_Index();
     if (@$_POST['--build-index']) {
         if (is_array($_POST['--tables'])) {
             $tables = $_POST['--tables'];
         } else {
             if (!empty($_POST['--tables'])) {
                 $tables = array($_POST['--tables']);
             } else {
                 $tables = null;
             }
         }
         if (@$_POST['--clear']) {
             $clear = true;
         } else {
             $clear = false;
         }
         $index->buildIndex($tables, '*', $clear);
         $app =& Dataface_Application::getInstance();
         header('Location: ' . $app->url('') . '&--msg=' . urlencode('Successfully indexed database'));
         exit;
     }
     $tables = array_keys(Dataface_Table::getTableModificationTimes());
     $count = 0;
     $indexable = array();
     foreach ($tables as $key => $table) {
         if (preg_match('/^dataface__/', $table)) {
             continue;
         }
         if (preg_match('/^_/', $table)) {
             continue;
         }
         if ($index->isTableIndexable($table)) {
             $indexable[] = $table;
             //unset($tables[$key]);
         }
     }
     $tables = $indexable;
     df_display(array('tables' => $tables), 'manage_build_index.html');
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
 function memcache_get($sql, $lang = null)
 {
     $app =& Dataface_Application::getInstance();
     $memcache =& $app->memcache;
     if (!@$app->_conf['cache_queries']) {
         return null;
     }
     $key = $this->memcache_get_key($sql, $lang);
     $tables = $this->getTableDependencies($sql, $lang);
     if (PEAR::isError($tables)) {
         return null;
     }
     // This is a list of the tables that would cause the cache to be invalidated.
     $modification_times = Dataface_Table::getTableModificationTimes();
     $mtime = 0;
     foreach ($tables as $table) {
         if (isset($modification_times[$table])) {
             $mtime = max($mtime, $modification_times[$table]);
         } else {
             $t =& Dataface_Table::loadTable($table);
             if (@$t->_atts['__source_tables__']) {
                 $ts = explode(',', $t->_atts['__source_tables__']);
                 foreach ($ts as $tst) {
                     if (isset($modification_times[trim($tst)])) {
                         $mtime = max($mtime, $modification_times[trim($tst)]);
                     } else {
                         $mtime = time();
                         break;
                     }
                 }
             } else {
                 //echo "$table no modified date";
                 $mtime = time();
                 break;
             }
             unset($t);
         }
     }
     // Now we will get the cached value if it is newer than $mtime
     $cache_mtime = 0;
     if ($memcache) {
         $cache_mtime = $this->memcache_mtime($key);
     } else {
         $cache_mtime = $this->fcache_mtime($key);
     }
     //echo "Cache time for ".$this->fcache_path($key)." is $cache_mtime";
     //echo "[$sql : $cache_mtime : $mtime]";
     if ($cache_mtime > $mtime) {
         if ($memcache) {
             if ($result = $memcache->get($key)) {
                 return unserialize($result);
             }
         } else {
             if (($result = $this->fcache_get($key)) !== null) {
                 return unserialize($result);
             }
         }
     }
     return null;
 }
Ejemplo n.º 4
0
 /**
  * Returns an associative array of table names and their associated 
  * update times as unix timestamps.
  * eg: [Tablename] -> [Unix Timestamp]
  */
 function &getTableModificationTimes()
 {
     $mod_times =& Dataface_Table::getTableModificationTimes();
     $this->tableModificationTimes =& $mod_times;
     return $mod_times;
 }