Commit 7d6192f8 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Fixing up group homepage problem (Bug #1396565)

A mistake was made where a user was allowed to add more than one
"group pages" block to the group homepage. This wasn't a problem until
we added pagination to the "group pages" block.

This patch attempts to clean up that error and merge any existing
multiple block instances into one "group pages" block instance.

Change-Id: I38acada835a4c245c97f0008543519a9dd2072a3
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 2649e660
......@@ -24,7 +24,7 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
}
public static function single_only() {
return false;
return true;
}
public static function get_categories() {
......
......@@ -3773,5 +3773,69 @@ function xmldb_core_upgrade($oldversion=0) {
$todb->sort = '0';
insert_record('blocktype_category', $todb);
}
if ($oldversion < 2014112700) {
// Need to find the group homepages that have more than one groupview on them
// and merge their data into one groupview as we shouldn't allow more than one groupview block
// as it breaks pagination
// First get any pages that have more than one groupview on them
// and find the status of the groupview blocks
if ($records = get_records_sql_array("SELECT v.id AS view, bi.id AS block FROM {view} v
INNER JOIN {block_instance} bi ON v.id = bi.view
WHERE v.id IN (
SELECT v.id FROM {view} v
INNER JOIN {block_instance} bi ON v.id = bi.view
WHERE bi.blocktype = 'groupviews'
AND v.type = 'grouphomepage'
GROUP BY v.id
HAVING COUNT(v.id) > 1
)
AND bi.blocktype='groupviews'
ORDER BY v.id, bi.id", array())) {
require_once(get_config('docroot') . 'blocktype/lib.php');
$lastview = 0;
// set default
$info = array();
$x = -1;
foreach ($records as $record) {
if ($lastview != $record->view) {
$x++;
$info[$x]['in']['showgroupviews'] = 0;
$info[$x]['in']['showsharedviews'] = 0;
$info[$x]['in']['view'] = $record->view;
$info[$x]['in']['block'] = $record->block;
$lastview = $record->view;
}
else {
$info[$x]['out'][] = $record->block;
}
$bi = new BlockInstance($record->block);
$configdata = $bi->get('configdata');
if (!empty($configdata['showgroupviews'])) {
$info[$x]['in']['showgroupviews'] = 1;
}
if (!empty($configdata['showsharedviews'])) {
$info[$x]['in']['showsharedviews'] = 1;
}
}
// now that we have info on the state of play we need to save one of the blocks
// with correct data and delete the not needed blocks
foreach ($info as $item) {
$bi = new BlockInstance($item['in']['block']);
$configdata = $bi->get('configdata');
$configdata['showgroupviews'] = $item['in']['showgroupviews'];
$configdata['showsharedviews'] = $item['in']['showsharedviews'];
$bi->set('configdata', $configdata);
$bi->commit();
foreach ($item['out'] as $old) {
$bi = new BlockInstance($old);
$bi->delete();
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014110700;
$config->version = 2014112700;
$config->series = '15.04';
$config->release = '15.04dev';
$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