Recent Topics

1 Nov 19, 2009 01:34    

The following hack allows you to enable or disable caching in all blogs without editing each blog by hands.
It took me a minute to enable cache on 120 blogs :)

Add this code to conf/hacks.php (create the file if it doesn't exist yet)

global $DB, $Messages, $cache_path; 

if( isset($_GET['enable_cache']) )
{					
    $blog_array = $DB->get_col( 'SELECT blog_ID FROM T_blogs' );
    
    foreach( $blog_array as $lbid )
    {
		// Update cache setting
		if( $cset_value = $DB->get_var('SELECT cset_value
										FROM T_coll_settings
										WHERE cset_coll_ID = '.$DB->quote($lbid).'
										AND cset_name = "cache_enabled"') )
		{			
			if( $cset_value != 1 && $DB->query( 'UPDATE T_coll_settings SET cset_value = 1
							 WHERE cset_coll_ID = '.$DB->quote($lbid).'
							 AND cset_name = "cache_enabled"' ) )
			{
				$Messages->add( 'Cache setting updated for blog #'.$lbid, 'success' );
			}
		}
		else
		{	// Create cache setting
			if( $DB->query( 'INSERT INTO T_coll_settings ( cset_coll_ID, cset_name, cset_value )
							 VALUES ( '.$DB->quote($lbid).', "cache_enabled", 1 )' ) )
			{
				$Messages->add( 'Cache enabled for blog #'.$lbid, 'success' );
			}
        }
        
        // Create cache directory
		mkdir_r( $cache_path.'c'.$lbid.'/', NULL );
    }
} 


Form is loading...