Changeset 3088

Show
Ignore:
Timestamp:
11/14/05 22:32:03 (3 years ago)
Author:
ryan
Message:

Flush the cache before installing. fixes #1877

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/install.php

    r3067 r3088  
    138138 
    139139// Set everything up 
     140wp_cache_flush(); 
    140141make_db_current_silent(); 
    141142populate_options(); 
     
    199200@wp_mail($admin_email, __('New WordPress Blog'), $message, $message_headers); 
    200201 
     202wp_cache_flush(); 
    201203?> 
    202204 
  • trunk/wp-includes/cache.php

    r3087 r3088  
    2020function wp_cache_flush() { 
    2121    global $wp_object_cache; 
    22      
     22 
    2323    return $wp_object_cache->flush(); 
    2424} 
     
    6161    var $cache = array (); 
    6262    var $dirty_objects = array (); 
    63     var $non_existant_objects = array(); 
    64     var $global_groups = array('users', 'usermeta'); 
     63    var $non_existant_objects = array (); 
     64    var $global_groups = array ('users', 'usermeta'); 
    6565    var $blog_id; 
    6666    var $cold_cache_hits = 0; 
     
    6969 
    7070    function add($id, $data, $group = 'default', $expire = '') { 
    71         if ( empty($group)
    72             $group = 'default'; 
    73  
    74         if ( false !== $this->get($id, $group, false)
     71        if (empty ($group)
     72            $group = 'default'; 
     73 
     74        if (false !== $this->get($id, $group, false)
    7575            return false; 
    7676 
     
    7979 
    8080    function delete($id, $group = 'default', $force = false) { 
    81         if ( empty($group)
    82             $group = 'default'; 
    83  
    84         if ( !$force && false === $this->get($id, $group, false)
     81        if (empty ($group)
     82            $group = 'default'; 
     83 
     84        if (!$force && false === $this->get($id, $group, false)
    8585            return false; 
    8686 
     
    9292 
    9393    function flush() { 
    94         return $this->rm($this->cache_dir . '*');        
    95     } 
    96      
     94        $this->rm($this->cache_dir.'*'); 
     95        $this->cache = array (); 
     96        $this->dirty_objects = array (); 
     97        $this->non_existant_objects = array (); 
     98        return true; 
     99    } 
     100 
    97101    function get($id, $group = 'default', $count_hits = true) { 
    98         if ( empty($group)
     102        if (empty ($group)
    99103            $group = 'default'; 
    100104 
    101105        if (isset ($this->cache[$group][$id])) { 
    102             if ( $count_hits
     106            if ($count_hits
    103107                $this->warm_cache_hits += 1; 
    104108            return $this->cache[$group][$id]; 
    105109        } 
    106110 
    107         if ( isset($this->non_existant_objects[$group][$id])
     111        if (isset ($this->non_existant_objects[$group][$id])
    108112            return false; 
    109113 
     
    123127        } 
    124128 
    125         $cache_file = $this->cache_dir . $this->get_group_dir($group) . "/" . md5($id . DB_PASSWORD) . '.php'; 
     129        $cache_file = $this->cache_dir.$this->get_group_dir($group)."/".md5($id.DB_PASSWORD).'.php'; 
    126130        if (!file_exists($cache_file)) { 
    127131            $this->non_existant_objects[$group][$id] = true; 
     
    133137        // a refresh. 
    134138        $now = time(); 
    135         if ( (filemtime($cache_file) + $this->expiration_time) <= $now ) { 
     139        if ((filemtime($cache_file) + $this->expiration_time) <= $now) { 
    136140            $this->cache_misses += 1; 
    137141            $this->delete($id, $group, true); 
     
    140144 
    141145        $this->cache[$group][$id] = unserialize(substr(@ file_get_contents($cache_file), strlen(CACHE_SERIAL_HEADER), -strlen(CACHE_SERIAL_FOOTER))); 
    142         if ( false === $this->cache[$group][$id]) 
     146        if (false === $this->cache[$group][$id]) 
    143147            $this->cache[$group][$id] = ''; 
    144148 
     
    148152 
    149153    function get_group_dir($group) { 
    150         if ( false !== array_search($group, $this->global_groups)
     154        if (false !== array_search($group, $this->global_groups)
    151155            return $group; 
    152156 
     
    173177                } 
    174178            } 
    175         } else if ( 'options' == $group ) { 
    176             $wpdb->hide_errors(); 
    177             if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) { 
    178                 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 
    179             } 
    180             $wpdb->show_errors(); 
    181  
    182             foreach ($options as $option) {  
    183                 $this->cache['options'][$option->option_name] = $option->option_value; 
    184             } 
    185         } 
     179        } else 
     180            if ('options' == $group) { 
     181                $wpdb->hide_errors(); 
     182                if (!$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'")) { 
     183                    $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 
     184                } 
     185                $wpdb->show_errors(); 
     186 
     187                foreach ($options as $option) { 
     188                    $this->cache['options'][$option->option_name] = $option->option_value; 
     189                } 
     190            } 
    186191    } 
    187192 
     
    189194        $group_dir = $this->get_group_dir($group); 
    190195        $make_dir = ''; 
    191         foreach ( split('/', $group_dir) as $subdir) { 
     196        foreach (split('/', $group_dir) as $subdir) { 
    192197            $make_dir .= "$subdir/"; 
    193             if (!file_exists($this->cache_dir . $make_dir)) { 
    194                    if (!mkdir($this->cache_dir . $make_dir)) 
    195                        break; 
    196                    @ chmod($this->cache_dir . $make_dir, $perms); 
    197             } 
    198  
    199             if (!file_exists($this->cache_dir . $make_dir . "index.php")) { 
    200                 touch($this->cache_dir . $make_dir . "index.php"); 
    201             } 
    202         } 
    203          
    204         return $this->cache_dir . "$group_dir/"; 
     198            if (!file_exists($this->cache_dir.$make_dir)) { 
     199                if (!mkdir($this->cache_dir.$make_dir)) 
     200                    break; 
     201                @ chmod($this->cache_dir.$make_dir, $perms); 
     202            } 
     203 
     204            if (!file_exists($this->cache_dir.$make_dir."index.php")) { 
     205                touch($this->cache_dir.$make_dir."index.php"); 
     206            } 
     207        } 
     208 
     209        return $this->cache_dir."$group_dir/"; 
    205210    } 
    206211 
    207212    function rm($fileglob) { 
    208        if (is_file($fileglob)) { 
    209            return @unlink($fileglob); 
    210        } else if (is_dir($fileglob)) { 
    211            $ok = $this->rm("$fileglob/*"); 
    212            if (! $ok) { 
    213                return false; 
    214            } 
    215            return @rmdir($fileglob); 
    216        } else { 
    217            $matching = glob($fileglob); 
    218            if ($matching === false) 
    219                return true; 
    220            $rcs = array_map(array('WP_Object_Cache', 'rm'), $matching); 
    221            if (in_array(false, $rcs)) { 
    222                return false; 
    223            
    224        
    225        return true; 
     213       if (is_file($fileglob)) { 
     214           return @ unlink($fileglob); 
     215        } else 
     216            if (is_dir($fileglob)) { 
     217                $ok = WP_Object_Cache::rm("$fileglob/*"); 
     218                if (!$ok) 
     219                    return false; 
     220               return @ rmdir($fileglob); 
     221           } else { 
     222               $matching = glob($fileglob); 
     223               if ($matching === false) 
     224                   return true; 
     225               $rcs = array_map(array ('WP_Object_Cache', 'rm'), $matching); 
     226               if (in_array(false, $rcs)) { 
     227                   return false; 
     228               
     229           
     230       return true; 
    226231    } 
    227232 
    228233    function replace($id, $data, $group = 'default', $expire = '') { 
    229         if ( empty($group)
    230             $group = 'default'; 
    231  
    232         if ( false === $this->get($id, $group, false)
     234        if (empty ($group)
     235            $group = 'default'; 
     236 
     237        if (false === $this->get($id, $group, false)
    233238            return false; 
    234239 
     
    237242 
    238243    function set($id, $data, $group = 'default', $expire = '') { 
    239         if ( empty($group)
    240             $group = 'default'; 
    241  
    242         if ( NULL == $data) 
     244        if (empty ($group)
     245            $group = 'default'; 
     246 
     247        if (NULL == $data) 
    243248            $data = ''; 
    244249 
    245250        $this->cache[$group][$id] = $data; 
    246         unset($this->non_existant_objects[$group][$id]); 
     251        unset ($this->non_existant_objects[$group][$id]); 
    247252        $this->dirty_objects[$group][] = $id; 
    248253 
     
    269274            @ chmod($this->cache_dir, $dir_perms); 
    270275        } 
    271          
    272         if (!file_exists($this->cache_dir . "index.php")) { 
    273             touch($this->cache_dir . "index.php"); 
     276 
     277        if (!file_exists($this->cache_dir."index.php")) { 
     278            touch($this->cache_dir."index.php"); 
    274279        } 
    275280 
     
    291296            $ids = array_unique($ids); 
    292297            foreach ($ids as $id) { 
    293                 $cache_file = $group_dir . md5($id . DB_PASSWORD) . '.php'; 
     298                $cache_file = $group_dir.md5($id.DB_PASSWORD).'.php'; 
    294299 
    295300                // Remove the cache file if the key is not set. 
    296                 if ( ! isset($this->cache[$group][$id]) ) { 
    297                     if ( file_exists($cache_file)
     301                if (!isset ($this->cache[$group][$id])) { 
     302                    if (file_exists($cache_file)
    298303                        unlink($cache_file); 
    299304                    continue; 
     
    301306 
    302307                $temp_file = tempnam($group_dir, 'tmp'); 
    303                 $serial = CACHE_SERIAL_HEADER . serialize($this->cache[$group][$id]) . CACHE_SERIAL_FOOTER; 
     308                $serial = CACHE_SERIAL_HEADER.serialize($this->cache[$group][$id]).CACHE_SERIAL_FOOTER; 
    304309                $fd = fopen($temp_file, 'w'); 
    305310                fputs($fd, $serial); 
    306                 fclose($fd);                
    307                 if (!@rename($temp_file, $cache_file)) { 
    308                     if (copy ($temp_file, $cache_file)) { 
     311                fclose($fd); 
     312                if (!@ rename($temp_file, $cache_file)) { 
     313                    if (copy($temp_file, $cache_file)) { 
    309314                        unlink($temp_file); 
    310315                    } 
     
    334339            print_r($cache); 
    335340            echo "</pre>"; 
    336             if ( isset($this->dirty_objects[$group]) ) { 
     341            if (isset ($this->dirty_objects[$group])) { 
    337342                echo "<strong>Dirty Objects:</strong>"; 
    338343                echo "<pre>"; 
     
    340345                echo "</pre>"; 
    341346                echo "</p>"; 
    342             }               
     347            } 
    343348        } 
    344349    } 
     
    347352        global $blog_id; 
    348353 
    349         if ( defined('DISABLE_CACHE')
     354        if (defined('DISABLE_CACHE')
    350355            return; 
    351356 
    352         if ( defined('CACHE_PATH')
     357        if (defined('CACHE_PATH')
    353358            $this->cache_dir = CACHE_PATH; 
    354359        else 
    355360            $this->cache_dir = ABSPATH.'wp-content/cache/'; 
    356361 
    357         if ( is_dir($this->cache_dir) ) { 
    358             if ( is_writable($this->cache_dir)
     362        if (is_dir($this->cache_dir)) { 
     363            if (is_writable($this->cache_dir)
    359364                $this->cache_enabled = true; 
    360         } else if (is_writable(ABSPATH.'wp-content')) { 
    361             $this->cache_enabled = true; 
    362         } 
    363  
    364         if ( defined('CACHE_EXPIRATION_TIME') ) 
     365        } else 
     366            if (is_writable(ABSPATH.'wp-content')) { 
     367                $this->cache_enabled = true; 
     368            } 
     369 
     370        if (defined('CACHE_EXPIRATION_TIME')) 
    365371            $this->expiration_time = CACHE_EXPIRATION_TIME; 
    366372