The drupal database optimization day.
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.
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+
Dipping my nose more into drupal.
I've got my Drupal CVS account. I'll give the article module some love.
And My first commit!
Drupal, The rules, Start with 3...
Rule #1: When you create a module, Never do
Drupal patch monkey, Remember me patch to drupal HEAD
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...
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.
Drupal authentication backend for dokuwiki.
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.
<?php
/**
* Drupal authentication backend
*
* Use drupal as an authentication backend.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Mohammed Sameer <msameer@foolab.org>
*/
// TODO: Currently, Each time we have to connct to the db twice, one to auth the
// user and the 2nd to get the info ??
// Groups with spaces'll screw us.
// ChangeLog:
// 2005-12-23: Use header(); instead of redirect();
// 2006-07-23: Ported to the new dokuwiki auth code.
// use mysql_real_escape_string()
// We now get the groups using a join instead of multiple queries.
// 2006-08-24: in getUserData(): Check that we have results when we try to get
// the user details from the database (Thanks Matthew Robinson of fone-me.com)
// 2006-08-30: Check that the user isn't blocked. Thanks alienbrain of EGLUG for the note.
// 2007-01-29: urldecode the username, password, hostname and path (Thanks Walter G).
// 2007-06-29: $db_url for drupal can be an array, we now account for this.
class auth_drupal extends auth_basic {
var $url = array();
// Constructor.
function auth_drupal() {
global $conf;
// This is a hack because drupal is using ini_set in the $drupal_file
// and php'll complain
$ini = ini_get("error_reporting");
ini_set("error_reporting", 0);
$drupal_file = $conf['auth']['drupal']['file'];
include ($drupal_file);
ini_set("error_reporting", $ini);
// http://drupal.org/node/18429
$this->url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
$this->url['path'] = substr($this->url['path'], 1);
$this->url['db_prefix'] = $db_prefix;
//Adapted from the Drupal database.mysql.inc code
//Decode url-encoded information in the db connection string
$this->url['user'] = urldecode($this->url['user']);
// Test if database url has a password.
if(isset($this->url['pass'])) {
$this->url['pass'] = urldecode($this->url['pass']);
} else {
$this->url['pass'] = '';
}
$this->url['host'] = urldecode($this->url['host']);
$this->url['path'] = urldecode($this->url['path']);
// Establish the connection.
$this->url['link'] = mysql_connect($this->url['host'], $this->url['user'], $this->url['pass']);
if (!$this->url['link']) {
msg('Could not connect: ' . mysql_error());
$this->success = false;
return;
}
if (!mysql_select_db($this->url['path'], $this->url['link'])) {
msg('Can\'t select the database: ' . mysql_error());
$this->success = false;
return;
}
// Note: No capabilities. We only handle authentication.
// Fuck php4. No Destructor.
register_shutdown_function("auth_drupal_disconnect", $this);
}
/**
* Check user+password [required auth function]
*
* Checks if the given user exists and the given
* plaintext password is correct
*
* @author Mohammed Sameer <msameer@foolab.org>
* @return bool
*/
function checkPass($user,$pass)
{
$user = mysql_real_escape_string($user, $this->url['link']);
$password = mysql_real_escape_string(md5($pass), $this->url['link']);
$result = mysql_query("SELECT uid FROM ".$url['db_prefix']."users WHERE name = \"$user\" AND pass = \"$password\" AND status=1");
if (!$result)
{
msg('Invalid query: ' . mysql_error());
$this->disconnect();
return false;
}
$num = mysql_num_rows($result);
//$this->disconnect();
return ($num == 0 ? false : true);
}
/**
* Return user info [required auth function]
* at least these fields:
*
* name string full name of the user
* mail string email addres of the user
* grps array list of groups the user is in
*
* @author Mohammed Sameer <msameer@foolab.org>
*/
function getUserData($user) {
$info['name'] = $user;
$result = mysql_query("SELECT uid, mail FROM ".$url['db_prefix']."users WHERE name = \"".mysql_real_escape_string($user, $this->url['link'])."\"");
if (!$result)
{
msg('Invalid query: ' . mysql_error());
$this->disconnect();
return false;
}
// This shouldn't fail but who knows ?
$tmp = mysql_fetch_row($result);
if (!$tmp)
return false;
$uid = $tmp[0];
// FILL THE EMAIL.
$info['mail'] = $tmp[1];
// Now let's get the groups of the user.
$result = mysql_query("select r.name from role r inner join users_roles u on u.rid=r.rid and u.uid=$uid");
if (!$result)
{
msg('Invalid query: ' . mysql_error());
$this->disconnect();
return false;
}
while($tmp = mysql_fetch_row($result))
$info['grps'][] = $tmp[0];
// $this->disconnect();
return $info;
}
}
/**
* Disconnect from the database.
* @author Mohammed Sameer <msameer@foolab.org>
*/
function auth_drupal_disconnect($obj) {
mysql_close($obj->url['link']);
}
?>
The status block!
My projects section.
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:
<?php
echo "<br />";
$arr = taxonomy_get_tree(5,0,-1,1);
$y = count($arr);
for ($x = 0; $x < $y; $x++)
{
$count = 0;
$ch = taxonomy_get_children($arr[$x]->tid, 5);
//print_r($ch);
$j = count($ch);
$_ch = array();
for ($i = 0; $i < $j; $i++)
{
$ch_a = array_shift($ch);
$_url = "/taxonomy/term/" . $ch_a->tid;
$_count = taxonomy_term_count_nodes($ch_a->tid);
$count += $_count;
$_name = $ch_a->name . " (" . $_count . ")";
$_ch[] = l($_name, $_url);
}
$url = "/taxonomy/term/" . $arr[$x]->tid;
$name = $arr[$x]->name . " (" . $count . ")";
echo l($name, $url);
echo theme_item_list($_ch);
echo "<br />";
}
?>
BTW: The code above'll be updated automatically whenever the original one changes.








