Converting Drupal Acidfree module to mySQL 3.x

See here for an explanation. Basically, this is how thepoorhouse.org.uk converted the Drupal module "Acidfree" which is designed for mySQL 4 and above to run on mySQL 3.

It's an easy one, well it was after reviewing the old version of Acidfree discussed here.

The deal is to replace the function _acidfree_get_offset_in_parent with the below version.

function _acidfree_get_offset_in_parent(&$parent, &$node) {
    $query = "SELECT nid FROM {node} n ".
        "INNER JOIN {acidfree} ON {acidfree}.aid = n.nid ".
        "INNER JOIN {acidfree_hierarchy} ON child = aid ".
        "WHERE class <> 'album' AND parent=%d ".
        _acidfree_content_sort_clause();
    $query = db_rewrite_sql($query);
    $res = db_query($query, $parent->nid);
    if (db_num_rows($res) == 0)
        return 0;
    // A loop is pretty much the only way to reliable locate the node in a set if the sort order is anything
    // other than a single unique column for mysql 3.x. This should be pretty quick for but 100's of rows.
    $count = 0;
    while ($row = db_fetch_object($res)) {
      if ($row->nid == $node->nid) {
        break;
      }
      $count++;
    }
    return $count;
}
?>

A working copy of the module file is attached below. Beware that the reason that this function got changed is because it is very processor intensive so may well cause problems if you have big galleries. As far as the Poorhouse can tell, it works fine for nice small ones though.


AttachmentSize
acidfree.zip26.64 KB