Removing CVS directories from Subversion

It’s time for a cleanout. A couple of servers here have Drupal 7 installed from CVS. As CVS is no longer used by Drupal, it’s time to clean those unneeded directories out of SVN with a mass SVN delete command

svn delete `find . -type d | grep 'CVS$'`

The command in the backticks finds everything of type directory, and then it’s passed (piped) to grep which filters the results. The $ at the end of the CVS tells us to only show root CVS directories, nothing inside them.

Filed under  //   cvs   drupal   drupal 7   subversion  

Improving performance for Drupal development on localhost

I usually use virtual machines for development if I am on Windows. On this machine I have several VM's with different flavours of Linux for that purpose. However, I also have a WAMP installation which I use if I want to muck with a test Drupal site or just try out some stuff.

As a lot of people out there know, WAMP and XAMPP can really suck at performance. I remember in the past waiting 40 seconds for a page load on a Drupal site which was pretty clean, which of course is enough to make you want to rip your own hair out. After firing WAMP up today for the first time in months, I thought I'd have a hunt around to see if there were any solutions to this problem. Here are two things I found that made quite a difference on my system.

1. Adjust the realpath_cache_size in php.ini, and set it to a reasonable level. I set mine to 24 meg which is probably a bit too high, some people are saying that even 2 meg gives them improvements. In WAMP you can edit the php.ini file by clicking on the WAMP icon in your toolbar, scrolling up to the PHP section, and clicking on php.ini. Find the line that starts with ;realpath_cache_size, and uncomment it out, so it should now read:

realpath_cache_size=24M

2. Disable the IPv6 line in your Windows hosts file (note this will only work on Vista and 7, not XP). You will need to do this as adminstrator, so you may need to right click on the hosts file and choose 'open as administrator'. The file is located at C:\Windows\System32\drivers\etc
Change the line:

::1             localhost

to

#::1             localhost

and save the file. Basically all you are doing is commenting the line out with a hash (#) so it's not used.
See if that makes any difference. I noticed it made an improvement to my overall system, not just WAMP. If you see no difference, then you can always re-edit the hosts file and remove the hash to enable the line again.

 

Filed under  //   development   drupal   localhost   performance   php   server  

Theming Drupal blocks dependent on the region

The other day I was working with the menu_block module (http://drupal.org/project/menu_block), and I was trying to theme the block dependent on the region it was assigned to, to get sets of different looking menus for different page types. The hooks that are in menu_block don’t use any region info, just block ID, block name, and whether you are actually using the menu block module. So, here is an easy way to pass the block region into other dependant hooks:

Firstly, override the theme_block function, and create a global variable called $_current_region. It’s also a good idea to set the variable to null just before closing the function. Here is the standard theme_blocks function overridden in template.php:

function phptemplate_blocks($region) {
    // pass the current block region so we can use it in other hooks later
    global $_current_region;
    $_current_region = $region;

    // start of standard theme_block hook
    $output = '';

    if ($list = block_list($region)) {
        foreach ($list as $key => $block) {
            $output .= theme('block', $block);
        }
    }

    // Add any content assigned to this region through drupal_set_content() calls.
    $output .= drupal_get_content($region);

    // set region to NULL seen as we have now passed it on
    $_current_region = NULL;

    return $output;
}

So now, we can make that variable available in other functions, for example theme_menu_tree, and theme_menu_item, and you can style the menus dependant on the region. Here is theme_menu_tree:

function phptemplate_menu_tree($tree) {
    global $_current_region;

    switch ($_current_region) {
        case 'front_menu':
            return $tree;
            break;
        case 'content_page_menu':
            return '<ul class="subnavigation">' . $tree . '</ul>';
            break;
    }
}

Filed under  //   blocks   drupal   theming