Group_update doesn't create groups

Bug #1355761 reported by Daniel Parejo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Expired
Undecided
Unassigned

Bug Description

Mahara version 1.9.1:

According to the doc:

/**
 * Update details of an existing group.
 *
 * @param array $new New values for the group table.
 * @param bool $create Create the group if it doesn't exist yet
 */
function group_update($new, $create=false)

the $create boolean determines if Mahra should create the group if the id provided doesn't match any other but everytime it doesnt find one, it directly throws the "group_update: group not found"

I think it's because the following code:

if (!empty($new->id)) {
        $old = get_record_select('group', 'id = ? AND deleted = 0', array($new->id));
    }
    else if (!empty($new->institution) && isset($new->shortname) && strlen($new->shortname)) {
        $old = get_record_select(
            'group',
            'shortname = ? AND institution = ? AND deleted = 0',
            array($new->shortname, $new->institution)
        );

        if (!$old && $create) {
            return group_create((array)$new);
        }
    }

    if (!$old) {
        throw new NotFoundException("group_update: group not found");
    }

should look like this:

if (!empty($new->id)) {
        $old = get_record_select('group', 'id = ? AND deleted = 0', array($new->id));
    }
    else if (!empty($new->institution) && isset($new->shortname) && strlen($new->shortname)) {
        $old = get_record_select(
            'group',
            'shortname = ? AND institution = ? AND deleted = 0',
            array($new->shortname, $new->institution)
        );

    }

if (!$old && $create) {
            return group_create((array)$new);
        }
    if (!$old) {
        throw new NotFoundException("group_update: group not found");
    }

with the "if (!$old && $create)" conditional OUT of the previous one. I tried it and it works fine now.

Also, I don't know if this is another bug or intentional but, when an id is provided, and create is "true", shouldn't it create it with the ID PROVIDED, instead of an arbitrary one? Because right now it gives you an arbitrary one (since that's what group_create() does).

Tags: db group
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Daniel, for Mahara 16.10 we made a bunch of changes to the group updates. Now all groups will have short names and can be updated via a CSV file. If your problem still persists, please let us know.

Changed in mahara:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for Mahara because there has been no activity for 60 days.]

Changed in mahara:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.