Writings Photos Code Contact Resume
Drupal

You are here

The drupal database optimization day.

Submitted by msameer on Wed, 22/11/2006 - 1:07pm

The server was really screaming yesterday. I was trying to understand why.
I thought it was the aggregator module. I did some profiling for the aggregator SQL queries and while I'm at it, I did the same for some other modules and here we go: Here, here, here and here.
I'll be applying them too to the drupal sites I'm hosting whether they like it or not!


This is how you can fix your utf8 b0rked drupal database.

Submitted by msameer on Tue, 29/08/2006 - 7:21pm

The problem:

You are on a shared hosting. Your host upgrades MySQL. Your drupal 4.7 installation is boom broken!

The reason:

Drupal 4.7 sets the database connection to utf8 if you are running MySQL 4.1+
When you upgrade drupal from 4.6 to 4.7 and you are using MySQL 4.1+, drupal will convert the tables to utf8. But it won't if you are running MySQL 4.0.
Your host upgrades MySQL from 4.0 to 4.1+ and drupal will start setting the connection to utf8 BUT MySQL "knows" that the tables are in latin1 encoding. He doesnt know that the data is really utf8 but the tables are latin1. It'll convert the data from latin1 to utf8 and send it to drupal. You'll end up with a broken website due to the double utf8 conversion.

The solution:

Use his script to convert the tables to utf8.

The instructions are near the top.



Drupal, The rules, Start with 3...

Submitted by msameer on Sun, 14/05/2006 - 2:27pm

Rule #1: When you create a module, Never do

<?php
function foo_menu($may_cache) {
$links = array();
 if (
$may_cache)
  {
  
$links[] = array(
                
'path' => 'foo/foo',
                
'title' => 'FOO Title',
                 
'callback' => 'foo_page',
                 
'access' => TRUE
                 
);
}
 if ((
arg(0) == 'node') && (is_numeric(arg(1)) && (user_access('administer foo'))))
{
 
$links[] = array(
          
'path' => 'node/'.arg(1).'/foo',
          
'title' => 'Foo 2',
          
'callback' => 'foo_2_page',
          
'callback arguments' => array(arg(1)),
          
'access' => user_access('administer foo'),
          
'type' => MENU_LOCAL_TASK,
    );
}
return
$links;
}
?>

Always do:

<?php
function foo_menu($may_cache) {
$links = array();
  if (
$may_cache)
    {
     
$links[] = array(
                      
'path' => 'foo/foo',
                      
'title' => 'FOO Title',
                      
'callback' => 'foo_page',
                      
'access' => TRUE
                      
);
}
else {
    if ((
arg(0) == 'node') && (is_numeric(arg(1)) && (user_access('administer foo'))))
{
    
$links[] = array(
               
'path' => 'node/'.arg(1).'/foo',
               
'title' => 'Foo 2',
               
'callback' => 'foo_2_page',
               
'callback arguments' => array(arg(1)),
               
'access' => user_access('administer foo'),
               
'type' => MENU_LOCAL_TASK,
                 );
}
}
return
$links;
}
?>

Rule #2:
NEVER EVER have a module called foo and a theme called foo, The module foo_help will be called without an argument and you'll get a warning.

Rule #3: The ultimate: Screw Amr, Drupal 4.7 is not buggy, The problem is between your keyboard and monitor.



Drupal patch monkey, Remember me patch to drupal HEAD

Submitted by msameer on Fri, 03/03/2006 - 1:10am

Well, I ported the patch to drupal CVS HEAD which 4.7 ATM per moshe's request. Looks like I did hit another thing. Might be my stupidity, Might be something wrong. We'll see!

PS. Patch is also in my CVS ;-)


A new theme...

Submitted by msameer on Fri, 24/02/2006 - 7:56pm

Probably you can notice that ;-)

I still have to do a few things with javascript, Maybe I won't.

I guess I like the new colors, Someone deserves a big thank you for the basic logo especially when you know that she did the drawing on my iPAQ using the stylus. The rest was created using The GIMP and emacs. Emacs, The past, Present and future.

I wanted the theme to be pure CSS but I failed, I had to do the top part using tables and I'm telling you that it's UGLY.

Finally. IE, You suck *** *** ****, All various problems from float drops to breaking the semi-transparent PNG logo and forcing me to use a GIF one to doubling a div margin. While the first one was triggered by a resolution of 800*600, The last one was always happening.
Opera for windows had a very tiny problem with the small image in the top right of the footer but I'm ignoring it.

Drupal, I raise my non-Red Hat to everyone behind you. Easy theming, There might be problems due to the default drupal CSS but I was able to iron them out in a snap!

Windows, You suck, The colors aren't being displayed correctly, I don't know how or why but I don't really care.

I still need to reorganize a few things here and there but it takes time.


Drupal authentication backend for dokuwiki.

Submitted by msameer on Tue, 13/12/2005 - 10:41am
This authentication backend'll enable your DokuWiki to authenticate using the drupal database.
This code is pulled from my svn which means that whenever I update it, It'll reflect the file displayed here ;-)
Or get the file directly from here.
Can't open the file!

The status block!

Submitted by msameer on Sat, 03/12/2005 - 3:34pm

That's the script.

You can run it using cron every hour or so, It should generate an HTML page like this.

Simply include it in a block like the one down there on the left and you have a basic status monitor.

Sure it needs tweaking as it's reporting that MySQL is down while it's not because you are reading this thing now, But I won't do it now since I know that both MySQL and Apache are up on Naboo!

Actually this inspired me to create a full set of server/services and network monitoring tools based on drupal and the SMS gateway API module for drupal. Not sure that I'll do it since I already have a script that should SMS me whenever the server is about to run out of disk space.

Another thing is that All the drupal modules'll depend on both Apache and MySQL being up.

I guess we'll then need another PERL script to check for them.

But If I'll create the perl script then I can extend it to do all the checks and SMS me upon a problem. So we don't need the drupal modules ?;-)


My projects section.

Submitted by msameer on Wed, 16/11/2005 - 7:35pm
I did it at last.

I aways wanted to create this section since I had foolab.

It's not exactly what I wanted it to be, But It's the best I can do at the moment.

I still need to populate it.

I've created the form using flexinode, Creaed the vocabolary hierarchy.
Overriding the node in my theme so I can display the tags like want.
Now how did I create the page itself ?
Here's the php code, It's not the best but it works:


BTW: The code above'll be updated automatically whenever the original one changes.

Pages