upgrade.php 2.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 *
 * @package    mahara
 * @subpackage blocktype-groupviews
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

defined('INTERNAL') || die();

safe_require('blocktype', 'groupviews');

function xmldb_blocktype_groupviews_upgrade($oldversion=0) {
    if ($oldversion < 2015090300) {

        $sql = "SELECT id, configdata FROM {block_instance} WHERE blocktype='groupviews'";
        $records = get_records_sql_array($sql, array());

        if ($records) {
            log_debug("Processing 'Group pages' blocks so they continue to display full list of pages/collections");
            $count = 0;
            $limit = 500;
            $total = count($records);
            foreach ($records as $r) {
                $configdata = unserialize($r->configdata);
                $updateconfig = false;
                // Do we need to update the setting for shared views
                if (!isset($configdata['showsharedviews']) || $configdata['showsharedviews'] == 1) {
                    $updateconfig = true;
                    $configdata['showsharedviews'] = 2;
                }
                // Do we need to update the setting for shared collections
                if (!isset($configdata['showsharedcollections']) || $configdata['showsharedcollections'] == 1) {
                    $updateconfig = true;
                    $configdata['showsharedcollections'] = 2;
                }

                if ($updateconfig) {
                    set_field('block_instance', 'configdata', serialize($configdata), 'id', $r->id);
                }
                $count++;
                if (($count % $limit) == 0 || $count == $total) {
                    log_debug("$count/$total");
                    set_time_limit(30);
                }
            }
        }
    }

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    if ($oldversion < 2016032300) {

        // Get the group view block from the default group home page view.
        $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.type = 'grouphomepage'
                       AND v.owner = 0";
        $defaultgrouppage = get_record_sql($sql, array());

        if ($defaultgrouppage) {
            log_debug("Processing default 'Group page' block to set the right shared pages/collections configurations");

            $configdata = unserialize($defaultgrouppage->configdata);
            $configdata['showsharedviews'] = 1;
            $configdata['showsharedcollections'] = 1;
            set_field('block_instance', 'configdata', serialize($configdata), 'id', $defaultgrouppage->id);
        }
    }

74
75
    return true;
}