function elluminate_check_for_orphaned_group_records($elluminate)
{
    global $DB;
    $group_meetings = $DB->get_records('elluminate', array('groupparentid' => $elluminate->id));
    foreach ($group_meetings as $group_meeting) {
        $DB->delete_records('elluminate_attendance', array('elluminateid' => $group_meeting->id));
        elluminate_grade_item_delete($group_meeting);
        if (!empty($group_meeting->meetingid)) {
            elluminate_delete_meeting($group_meeting->meetingid);
        }
        if (!empty($group_meeting->meetingid)) {
            $group_recordings = $DB->get_records('elluminate_recordings', array('meetingid' => $group_meeting->meetingid));
            foreach ($group_recordings as $group_recording) {
                elluminate_delete_recording($group_recording->recordingid);
            }
            $DB->delete_records('elluminate_recordings', array('meetingid' => $group_meeting->meetingid));
        }
        $DB->delete_records('elluminate', array('id' => $group_meeting->id));
    }
    if (!empty($elluminate->meetingid)) {
        $group_recordings = $DB->get_records('elluminate_recordings', array('meetingid' => $elluminate->meetingid));
        foreach ($group_recordings as $group_recording) {
            elluminate_delete_recording($group_recording->recordingid);
        }
        elluminate_delete_meeting($elluminate->meetingid);
    }
}
function elluminate_check_for_orphaned_group_records($elluminate)
{
    $group_meetings = get_records('elluminate', 'groupparentid', $elluminate->id);
    foreach ($group_meetings as $group_meeting) {
        delete_records('elluminate_attendance', 'elluminateid', $group_meeting->id);
        elluminate_grade_item_delete($group_meeting);
        if (!empty($group_meeting->meetingid)) {
            elluminate_delete_meeting($group_meeting->meetingid);
        }
        if (!empty($group_meeting->meetingid)) {
            $group_recordings = get_records('elluminate_recordings', 'meetingid', $group_meeting->meetingid);
            foreach ($group_recordings as $group_recording) {
                elluminate_delete_recording($group_recording->recordingid);
            }
            delete_records('elluminate_recordings', 'meetingid', $group_meeting->meetingid);
        }
        delete_records('elluminate', 'id', $group_meeting->id);
    }
    if (!empty($elluminate->meetingid)) {
        $group_recordings = get_records('elluminate_recordings', 'meetingid', $elluminate->meetingid);
        foreach ($group_recordings as $group_recording) {
            elluminate_delete_recording($group_recording->recordingid);
        }
        elluminate_delete_meeting($elluminate->meetingid);
    }
}