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
 * Label module upgrade
19
 *
20
 * @package mod_label
21
 * @copyright  2006 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
// This file keeps track of upgrades to
26
// the label module
27
//
28
// Sometimes, changes between versions involve
29
// alterations to database structures and other
30
// major things that may break installations.
31
//
32
// The upgrade function in this file will attempt
33
// to perform all the necessary actions to upgrade
34
// your older installation to the current version.
35
//
36
// If there's something it cannot do itself, it
37
// will tell you what you need to do.
38
//
39
// The commands in here will all be database-neutral,
40
// using the methods of database_manager class
41
//
42
// Please do not forget to use upgrade_set_timeout()
43
// before any action that may take longer time to finish.
44
 
45
function xmldb_label_upgrade($oldversion) {
46
    global $CFG, $DB;
47
 
48
    // Automatically generated Moodle v4.1.0 release upgrade line.
49
    // Put any upgrade step following this.
50
 
51
    if ($oldversion < 2022112801) {
52
        $prevlang = force_current_language($CFG->lang);
53
 
54
        $select = $DB->sql_like('name', ':tofind');
55
        $params = ['tofind' => '%@@PLUGINFILE@@%'];
56
        $total = $DB->count_records_select('label', $select, $params);
57
        if ($total > 0) {
58
            $labels = $DB->get_recordset_select('label', $select, $params, '', 'id, name, intro');
59
 
60
            // Show a progress bar.
61
            $pbar = new progress_bar('upgrademodlabelpluginfile', 500, true);
62
            $current = 0;
63
 
64
            $defaultname = get_string('modulename', 'label');
65
            foreach ($labels as $label) {
66
                $originalname = $label->name;
67
                // Make sure that all labels have now the same name according to the new convention.
68
                // Note this is the same (and duplicated) code as in get_label_name as we cannot call any API function
69
                // during upgrade.
70
                $name = html_to_text(format_string($label->intro, true));
71
                $name = preg_replace('/@@PLUGINFILE@@\/[[:^space:]]+/i', '', $name);
72
                // Remove double space and also nbsp; characters.
73
                $name = preg_replace('/\s+/u', ' ', $name);
74
                $name = trim($name);
75
                if (core_text::strlen($name) > LABEL_MAX_NAME_LENGTH) {
76
                    $name = core_text::substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
77
                }
78
                if (empty($name)) {
79
                    $name = $defaultname;
80
                }
81
                $label->name = $name;
82
                if ($originalname !== $name) {
83
                    $DB->update_record('label', $label);
84
                }
85
                $current++;
86
                $pbar->update($current, $total, "Upgrading label activity names - $current/$total.");
87
            }
88
            $labels->close();
89
        }
90
        force_current_language($prevlang);
91
        upgrade_mod_savepoint(true, 2022112801, 'label');
92
    }
93
 
94
    // Automatically generated Moodle v4.2.0 release upgrade line.
95
    // Put any upgrade step following this.
96
 
97
    // Automatically generated Moodle v4.3.0 release upgrade line.
98
    // Put any upgrade step following this.
99
 
100
    // Automatically generated Moodle v4.4.0 release upgrade line.
101
    // Put any upgrade step following this.
102
 
103
    return true;
104
}