php

Switching OG (drupal organic groups) view depending on node type

Sometimes you need to use a different drupal view when you're displaying different group types with Drupal's organic groups (OG) module, for example you might have a group thats mostly about files, and a group that's mostly about posting other items or something.

OG doesn't let you have different configurations for each node type (yet) so you can do this with a little hack, simply hit up the global $conf variable and replace it with what you need, and ensure this executes before OG does.

Zend IDE not listening on port 10137, fixed with disabled ipv6

Zend IDE mysteriously stopped debugging, firefox toolbar just would not start the debugger and always said Zend was not detected no matter what i done, turns out, it was listening on ipv6 ports

Zend Debugger requires Zend Engine API version 220060519. errors

"Zend Debugger requires Zend Engine API version 220060519."

From what i've gathered, looks like Zend dont fully support the latest php 5.3, so downgrade unfortunately is the answer!

Fivestar voting.. Do you even need it? Or is it just a cool idea

I came across this article about youtube ditching its fivestar rating basically because users treat it as a binary thing, either they love it (5 stars) or hate it (0 stars) or simply dont bother voting, there are some edge cases where users DO bother voting however.

more here... http://youtube-global.blogspot.com/2009/09/five-stars-dominate-ratings.h...

Drupal buddylist2 to friendlist importer

A quick and dirty way to import buddylist (from d5) to friendlist (d6)
/**
 * Brute force import buddylist into friendlist
 * the friendlist import sucks pretty bad and emails everyone when they import
 */
function buddylist_import_to_friendlist() {
  $ret=array();
  $result = db_query("SELECT * FROM {buddylist} where received=1;");
  while($row = db_fetch_array($result)) {
    // friendlist can be two way so we need to insert twice with opposing uids so they handshake
    db    
  

Drupal friendlist module, every relationship is 4 DB rows

ouch!

mysql> select * from friendlist_statuses;
+-----+--------------+--------------+------+---------+------------+------+------------------+
| sid | requester_id | requestee_id | rtid | status  | rid_origin | rid  | last_update_time |
+-----+--------------+--------------+------+---------+------------+------+------------------+
|   7 |            1 |         5484 |    1 | TW_BOTH |        232 |  232 |       1259898195 |
|   8 |         5484 |            1 |    1 | TW_BOTH |        233 |  233 |       1259898195 |
+-----+--------------+--------------+------+---------+------------    
  

Backup your LAMP DB externally

Simple script you could drop into /etc/cron.daily/backup_db , handy for testing the exit level of mysqldump and rsync, and then rsyncing to your external server, keeps a rolling month's worth of backups.

error checked from mysqldump by testing for info in the STDERR output, and rsync tested by examining the return code ($?)


#!/bin/bash

# keeps a rolling 30 days of DB snapshots

mysqldump -uroot -pxxx mydrupal 2> /tmp/mysql-dump-fail.log |grep -v "INSERT INTO .cache"| bzip2 > /root/db_drupal-`date +%d`.sql.bz2
if [ -s /tmp/mysql-dump-fail.log ]
then

Saving Drupal CCK node, drupal_execute is a dog, use node_save instead

Interesting benchmark, saving 100 CCK nodes in a loop, nearly 5 seconds difference between drupal_execute method and going straight for node_save, i guess this indicates how much overhead is in the form handling (which is not a bad thing!)

heres the output!

time node object based insert: 0.00971524078067 each average, total 0.981767416
time node drupal_execute based insert: 0.0454754971042 each average, total 5    
  

BitCache distributed storage - distributed it is NOT!!

Thought i'de give the Drupal BitCache module a spin for a new project as it offers all the promises of Content Addressable Storage (CAS).

Yes, OK, so you can use the FileFramework that uses the BitCache module to present CCk fields, but there is still nothing distributed about the BitCache project.

There is no support for memcached for Drupal BitCache (And, more so, why would you want to store blobs in memcached? it does not handle object persistance so well)

Pushing your content into Drupal's pre-page bootstrapless cache for fast content!

A hindy tip, good if you have something tricky like custom RSS feeds from modules etc, use this to push your content into Drupal's pre-page cache, Takes about 0.02s on a decent server to pull cache from here, instead of 0.200s if you bootstrap drupal (with ACP!) basically, just ripping off the cache code, gzip'ing the content with the right key.. content goes in $output..
global $base_root;
$data = gzencode($output, 9, FORCE_GZIP);
cache_set($base_root . request_uri(), 'cache_page', $data, CACHE_TEMPORARY, drupal_get_headers());
Syndicate content