Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Version details
19
 *
20
 * Configurable Reports - A Moodle block for creating customizable reports
21
 *
22
 * @package     block_configurable_reports
23
 * @author:     Juan leyva <http://www.twitter.com/jleyvadelgado>
24
 * @date:       2013-09-07
25
 *
26
 * @copyright  Juan leyva <http://www.twitter.com/jleyvadelgado>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
 
30
defined('MOODLE_INTERNAL') || die();
31
 
32
function xmldb_block_configurable_reports_upgrade($oldversion) {
33
    global $DB, $CFG;
34
 
35
    $dbman = $DB->get_manager();
36
 
37
    if ($oldversion < 2011040103) {
38
 
39
        $table = new xmldb_table('block_configurable_reports_report');
40
        $dbman->rename_table($table, 'block_configurable_reports');
41
        upgrade_plugin_savepoint(true, 2011040103, 'block', 'configurable_reports');
42
    }
43
 
44
    if ($oldversion < 2011040106) {
45
 
46
        $table = new xmldb_table('block_configurable_reports');
47
 
48
        $field = new xmldb_field('global', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
49
        if (!$dbman->field_exists($table, $field)) {
50
            $dbman->add_field($table, $field);
51
        }
52
 
53
        $field = new xmldb_field('lastexecutiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', null);
54
        if (!$dbman->field_exists($table, $field)) {
55
            $dbman->add_field($table, $field);
56
        }
57
 
58
        $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', null);
59
        if (!$dbman->field_exists($table, $field)) {
60
            $dbman->add_field($table, $field);
61
        }
62
        upgrade_plugin_savepoint(true, 2011040106, 'block', 'configurable_reports');
63
    }
64
 
65
    if ($oldversion < 2011040115) {
66
 
67
        $table = new xmldb_table('block_configurable_reports');
68
 
69
        $field = new xmldb_field('remote', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', null);
70
        if (!$dbman->field_exists($table, $field)) {
71
            $dbman->add_field($table, $field);
72
        }
73
        upgrade_plugin_savepoint(true, 2011040115, 'block', 'configurable_reports');
74
    }
75
 
76
    if ($oldversion < 2019020600) {
77
        $table = new xmldb_table('block_configurable_reports');
78
        $field = new xmldb_field('summaryformat');
79
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'summary');
80
 
81
        if (!$dbman->field_exists($table, $field)) {
82
            $dbman->add_field($table, $field);
83
        }
84
 
85
        // Conditionally migrate to html format in summary.
86
        if ($CFG->texteditors !== 'textarea') {
87
            $rs = $DB->get_recordset('block_configurable_reports', array('summaryformat'=>FORMAT_MOODLE), '', 'id, summary, summaryformat');
88
            foreach ($rs as $f) {
89
                $f->summary = text_to_html($f->summary, false, false, true);
90
                $f->summaryformat = FORMAT_HTML;
91
                $DB->update_record('block_configurable_reports', $f);
92
                upgrade_set_timeout();
93
            }
94
            $rs->close();
95
        }
96
 
97
        upgrade_plugin_savepoint(true, 2019020600, 'block', 'configurable_reports');
98
    }
99
 
100
    if ($oldversion < 2019062001) {
101
 
102
        // Change NULL to 0.
103
        $rs = $DB->get_recordset('block_configurable_reports', null, '', 'id, global, lastexecutiontime, cron');
104
        foreach ($rs as $f) {
105
            $update = false;
106
            if (is_null($f->global)) {
107
                $update = true;
108
                $f->global = 0;
109
            }
110
            if (is_null($f->lastexecutiontime)) {
111
                $update = true;
112
                $f->lastexecutiontime = 0;
113
            }
114
            if (is_null($f->cron)) {
115
                $update = true;
116
                $f->cron = 0;
117
            }
118
            if ($update) {
119
                $DB->update_record('block_configurable_reports', $f);
120
            }
121
        }
122
        $rs->close();
123
 
124
        $table = new xmldb_table('block_configurable_reports');
125
 
126
        // Make sure these fields match install.xml.
127
        $field = new xmldb_field('global', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
128
        if ($dbman->field_exists($table, $field)) {
129
            $dbman->change_field_default($table, $field);
130
            $dbman->change_field_notnull($table, $field);
131
        }
132
 
133
        $field = new xmldb_field('lastexecutiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
134
        if ($dbman->field_exists($table, $field)) {
135
            $dbman->change_field_default($table, $field);
136
            $dbman->change_field_notnull($table, $field);
137
        }
138
 
139
        $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
140
        if ($dbman->field_exists($table, $field)) {
141
            $dbman->change_field_precision($table, $field);
142
            $dbman->change_field_notnull($table, $field);
143
        }
144
        upgrade_plugin_savepoint(true, 2019062001, 'block', 'configurable_reports');
145
    }
146
 
147
    return true;
148
}