diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 6a66e3f7e93..4178d887429 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -1250,7 +1250,7 @@ class backup_groups_structure_step extends backup_structure_step { $group = new backup_nested_element('group', array('id'), array( 'name', 'idnumber', 'description', 'descriptionformat', 'enrolmentkey', - 'picture', 'hidepicture', 'timecreated', 'timemodified')); + 'picture', 'timecreated', 'timemodified')); $members = new backup_nested_element('group_members'); diff --git a/group/group_form.php b/group/group_form.php index b92dcec58d9..15b638870de 100644 --- a/group/group_form.php +++ b/group/group_form.php @@ -77,9 +77,6 @@ class group_form extends moodleform { $mform->addElement('checkbox', 'deletepicture', get_string('delete')); $mform->setDefault('deletepicture', 0); - $options = array(get_string('no'), get_string('yes')); - $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options); - $mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group')); $mform->addHelpButton('imagefile', 'newpicture', 'group'); diff --git a/group/upgrade.txt b/group/upgrade.txt new file mode 100644 index 00000000000..894ffc4efbc --- /dev/null +++ b/group/upgrade.txt @@ -0,0 +1,7 @@ +This files describes API changes in /group/*, +information provided here is intended especially for developers. + +=== 3.11 === + +* The groups do not support 'hidepicture' any more, and so the column 'hidepicture' + from the table {groups} has be dropped. diff --git a/lib/db/install.xml b/lib/db/install.xml index 87a8826c2fd..581661e6432 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2245,7 +2245,6 @@ - diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index d501baaee48..74ad1836dc7 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2397,5 +2397,56 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2021013100.00); } + if ($oldversion < 2021021600.00) { + + // We are going to remove the field 'hidepicture' from the groups + // so we need to remove the pictures from those groups. But we prevent + // the execution twice because this could be executed again when upgrading + // to different versions. + if ($dbman->field_exists('groups', 'hidepicture')) { + + $sql = "SELECT g.id, g.courseid, ctx.id AS contextid + FROM {groups} g + JOIN {context} ctx + ON ctx.instanceid = g.courseid + AND ctx.contextlevel = :contextlevel + WHERE g.hidepicture = 1"; + + // Selecting all the groups that have hide picture enabled, and organising them by context. + $groupctx = []; + $records = $DB->get_recordset_sql($sql, ['contextlevel' => CONTEXT_COURSE]); + foreach ($records as $record) { + if (!isset($groupctx[$record->contextid])) { + $groupctx[$record->contextid] = []; + } + $groupctx[$record->contextid][] = $record->id; + } + $records->close(); + + // Deleting the group files. + $fs = get_file_storage(); + foreach ($groupctx as $contextid => $groupids) { + list($in, $inparams) = $DB->get_in_or_equal($groupids, SQL_PARAMS_NAMED); + $fs->delete_area_files_select($contextid, 'group', 'icon', $in, $inparams); + } + + // Updating the database to remove picture from all those groups. + $sql = "UPDATE {groups} SET picture = :pic WHERE hidepicture = :hide"; + $DB->execute($sql, ['pic' => 0, 'hide' => 1]); + } + + // Define field hidepicture to be dropped from groups. + $table = new xmldb_table('groups'); + $field = new xmldb_field('hidepicture'); + + // Conditionally launch drop field hidepicture. + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2021021600.00); + } + return true; } diff --git a/lib/weblib.php b/lib/weblib.php index a2ba0c34d91..34ba16b7b2c 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2576,11 +2576,6 @@ function get_group_picture_url($group, $courseid, $large = false, $includetoken return; } - // If picture is hidden, only show to those with course:managegroups. - if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) { - return; - } - if ($large) { $file = 'f1'; } else { diff --git a/mod/forum/lib.php b/mod/forum/lib.php index e9089555fd1..579c9414cb2 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -2450,7 +2450,7 @@ function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring // Group picture if ($group !== -1) { // Groups are active - group is a group data object or NULL echo ''; - if (!empty($group->picture) and empty($group->hidepicture)) { + if (!empty($group->picture)) { if ($canviewparticipants && $COURSE->groupmode) { $picturelink = true; } else { diff --git a/version.php b/version.php index 2aa5e104ef7..3a26d029149 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021021100.00; // 20201109 = branching date YYYYMMDD - do not modify! +$version = 2021021600.00; // 20201109 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.11dev (Build: 20210211)';// Human-friendly version name