Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Database upgrade steps definition.
19
 *
20
 * @package    block_point_view
21
 * @copyright  2021 Astor Bizard
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
/**
26
 * Performs database actions to upgrade from older versions, if required.
27
 * @param int $oldversion Plugin version we are upgrading from.
28
 * @param object $block Block version information.
29
 * @return boolean
30
 */
31
function xmldb_block_point_view_upgrade($oldversion, $block) {
32
    global $DB, $OUTPUT;
33
 
34
    $v1x6 = 2021092308; // Block v1.6.
35
    if ($oldversion < $v1x6) {
36
        // Inform capability changes.
37
        echo $OUTPUT->notification('Some capabilities have changed
38
            (block/point_view:view -> X,
39
            block/point_view:access_menu -> block/point_view:access_overview),
40
            please check permissions on administration tab.', \core\output\notification::NOTIFY_INFO);
41
 
42
        $blockrecords = $DB->get_records('block_instances', [ 'blockname' => 'point_view' ]);
43
        foreach ($blockrecords as $blockrecord) {
44
            if (!empty($blockrecord->configdata)) {
45
                $blockinstance = block_instance('point_view', $blockrecord);
46
 
47
                // Rename some settings.
48
                $config = clone($blockinstance->config);
49
                if (isset($config->enable_point_views_checkbox)) {
50
                    $config->enable_point_views = $config->enable_point_views_checkbox;
51
                    unset($config->enable_point_views_checkbox);
52
                }
53
 
54
                if (isset($config->enable_difficulties_checkbox)) {
55
                    $config->enable_difficultytracks = $config->enable_difficulties_checkbox;
56
                    unset($config->enable_difficulties_checkbox);
57
                }
58
 
59
                // Emoji selection has changed, update corresponding settings.
60
                if (!isset($config->pixselect)) {
61
                    $custompix = isset($config->enable_pix_checkbox) && $config->enable_pix_checkbox;
62
                    if ($custompix) {
63
                        $config->pixselect = 'custom';
64
                    } else if (get_config('block_point_view', 'enable_pix_admin')) {
65
                        $config->pixselect = 'admin';
66
                    } else {
67
                        $config->pixselect = 'default';
68
                    }
69
                }
70
                unset($config->enable_pix_checkbox);
71
 
72
                $DB->update_record('block_instances', [
73
                        'id' => $blockrecord->id,
74
                        'configdata' => base64_encode(serialize($config)),
75
                        'timemodified' => time(),
76
                ]);
77
            }
78
        }
79
        upgrade_block_savepoint( true , $v1x6, 'point_view');
80
    }
81
 
82
    return true;
83
}