Comment 0 for bug 1359109

Revision history for this message
Daniel Parejo (danielparejom) wrote :

When you delete a group, it concatenates '.deleted.'.time() that is about 19 characters. Hence, if your group name is longer than 108 characters it will throw a DB exception for exceeding the 128 characters field for the group name. To avoid this, I've added the following code to function group_delete($groupid, $shortname=null, $institution=null, $notifymembers=true):

//Daniel Parejo
    $delete_name = $group->name;
    if (strlen($delete_name) > 100) {
        $delete_name = substr($delete_name, 0, 100) . '(...)';
    }
//End added code

    update_record('group',
        array(
            'deleted' => 1,
            'name' => $delete_name . '.deleted.' . time(), //modified code
            'shortname' => null,
            'institution' => null,
            'category' => null,
            'urlid' => null,
        ),
        array(
            'id' => $group->id,
        )
    );
    db_commit();

This solution is not perfect since it will fail if two groups that are not different in their 101 first characters are tried to remove in the same time instant. Still, way better than before, though I think a more solid solution should be implemented.