Commit 4b4deb91 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1644386: Update block on group homepage if allowsubmissions change



Added db upgrade where we update only the existing groupviews blocks where:
1) the group is submittable to
2) no choice has been selected to view submissions

This way we don't accidentially overwrite a user's choice

behatnotneeded

Change-Id: Idd50fe3a75a7434cbbd5ff30d755708c9f855e7b
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 5fc762eb
......@@ -5015,5 +5015,34 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2017062000) {
if ($records = get_records_sql_array("SELECT bi.id AS blockid
FROM {group} g
JOIN {view} v ON (v.group = g.id AND v.type = 'grouphomepage')
JOIN {block_instance} bi ON (bi.view = v.id AND bi.blocktype = 'groupviews')
WHERE g.submittableto = 1
AND bi.configdata NOT LIKE '%showsubmitted%'", array())) {
safe_require('blocktype', 'groupviews');
log_debug('Update submittable groups to display submissions in block by default');
// We can only update those blocks where a decision hasn't yet been made rather than include blocks
// that have showsubmitted set to false as that may be a valid choice by the group administrator.
$count = 0;
$limit = 1000;
$total = count($records);
foreach ($records as $record) {
$bi = new BlockInstance($record->blockid);
$configdata = $bi->get('configdata');
$configdata['showsubmitted'] = 1;
$bi->set('configdata', $configdata);
$bi->commit();
$count++;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -724,8 +724,8 @@ function group_update($new, $create=false) {
// When a group changes from public -> private or vice versa, set the
// appropriate access permissions on the group homepage view.
$homepageid = get_field('view', 'id', 'type', 'grouphomepage', 'group', $new->id);
if ($old->public != $new->public) {
$homepageid = get_field('view', 'id', 'type', 'grouphomepage', 'group', $new->id);
if ($old->public && !$new->public) {
delete_records('view_access', 'view', $homepageid, 'accesstype', 'public');
insert_record('view_access', (object) array(
......@@ -773,6 +773,23 @@ function group_update($new, $create=false) {
}
}
// If 'Allow submissions' is changed we need to update the 'Group pages' block
// to reflect the change
$cansubmitto = 0;
if (isset($new->submittableto) && !empty($new->submittableto)) {
$cansubmitto = 1;
}
$groupview = get_record_sql("SELECT bi.id, bi.configdata
FROM {block_instance} bi
INNER JOIN {view} v ON v.id = bi.view
WHERE bi.blocktype = 'groupviews'
AND v.id = ?", array($homepageid));
if ($groupview) {
$configdata = unserialize($groupview->configdata);
$configdata['showsubmitted'] = $cansubmitto;
set_field('block_instance', 'configdata', serialize($configdata), 'id', $groupview->id);
}
db_commit();
return $diff;
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017061200;
$config->version = 2017062000;
$config->series = '17.10';
$config->release = '17.10dev';
$config->minupgradefrom = 2012080604;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment