Commit a989b7af authored by Robert Lyon's avatar Robert Lyon Committed by Son Nguyen

Bug 1582039: Show submissions by default for 'allow submissions' groups

This patch does 2 things:
1) Changes all groupviews blocks on groups that allow group
submissions but don't have showsubmitted set to set it as true
2) When creating a new group that allows submissions to set the
showsubmitted = true at that time.

behatnotneeded

Change-Id: I8dbc7f9f4919fbb21aded3ff0f2637152b4d3480
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c25cf821
......@@ -4127,5 +4127,37 @@ function xmldb_core_upgrade($oldversion=0) {
change_field_precision($table, $field);
}
if ($oldversion < 2015030431) {
// Get all the group view blocks from groups that have 'Allow submissions' set to true.
$sql = "SELECT bi.id, bi.configdata
FROM {block_instance} bi
INNER JOIN {view} v ON v.id = bi.view
INNER JOIN {group} g ON g.id = v.group
WHERE bi.blocktype = 'groupviews'
AND v.type = 'grouphomepage'
AND g.submittableto = 1";
$groupviews = get_records_sql_array($sql, array());
if ($groupviews) {
log_debug("Processing 'Group page' blocks to set the allow submitted configuration if not already set");
$count = 0;
$limit = 1000;
$total = count($groupviews);
foreach ($groupviews as $groupview) {
$configdata = unserialize($groupview->configdata);
if (!isset($configdata['showsubmitted'])) {
$configdata['showsubmitted'] = 1;
set_field('block_instance', 'configdata', serialize($configdata), 'id', $groupview->id);
}
$count++;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -516,6 +516,24 @@ function group_create($data) {
'type' => 'grouphomepage',
), $t->id, 0, false);
}
// If 'Allow submissions' is true we need to update the 'Group pages' block to show
// the 'Submissions to this group' section by default
if ($data['submittableto']) {
$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($homepage->get('id')));
if ($groupview) {
$configdata = unserialize($groupview->configdata);
if (!isset($configdata['showsubmitted'])) {
$configdata['showsubmitted'] = 1;
set_field('block_instance', 'configdata', serialize($configdata), 'id', $groupview->id);
}
}
}
insert_record('view_access', (object) array(
'view' => $homepage->get('id'),
'accesstype' => $data['public'] ? 'public' : 'loggedin',
......
......@@ -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 = 2015030430;
$config->version = 2015030431;
$config->series = '15.04';
$config->release = '15.04.8testing';
$config->minupgradefrom = 2009022600;
......
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