source: moodle/trunk/fuentes/lib/editor/atto/db/upgrade.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 3 years ago

Ported code to xenial

File size: 3.9 KB
Line 
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 * Atto upgrade script.
19 *
20 * @package    editor_atto
21 * @copyright  2014 Damyon Wiese
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Run all Atto upgrade steps between the current DB version and the current version on disk.
29 * @param int $oldversion The old version of atto in the DB.
30 * @return bool
31 */
32function xmldb_editor_atto_upgrade($oldversion) {
33    global $CFG, $DB;
34
35    $dbman = $DB->get_manager();
36
37    if ($oldversion < 2014032800) {
38        // Make Atto the default.
39        $currenteditors = $CFG->texteditors;
40        $neweditors = array();
41
42        $list = explode(',', $currenteditors);
43        array_push($neweditors, 'atto');
44        foreach ($list as $editor) {
45            if ($editor != 'atto') {
46                array_push($neweditors, $editor);
47            }
48        }
49
50        set_config('texteditors', implode(',', $neweditors));
51        upgrade_plugin_savepoint(true, 2014032800, 'editor', 'atto');
52    }
53
54    // Moodle v2.7.0 release upgrade line.
55    // Put any upgrade step following this.
56    if ($oldversion < 2014081400) {
57
58        // Define table editor_atto_autosave to be created.
59        $table = new xmldb_table('editor_atto_autosave');
60
61        // Adding fields to table editor_atto_autosave.
62        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
63        $table->add_field('elementid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
64        $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
65        $table->add_field('pagehash', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
66        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
67        $table->add_field('drafttext', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
68        $table->add_field('draftid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
69        $table->add_field('pageinstance', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
70
71        // Adding keys to table editor_atto_autosave.
72        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
73        $table->add_key('autosave_uniq_key', XMLDB_KEY_UNIQUE, array('elementid', 'contextid', 'userid', 'pagehash'));
74
75        // Conditionally launch create table for editor_atto_autosave.
76        if (!$dbman->table_exists($table)) {
77            $dbman->create_table($table);
78        }
79
80        // Atto savepoint reached.
81        upgrade_plugin_savepoint(true, 2014081400, 'editor', 'atto');
82    }
83
84    if ($oldversion < 2014081900) {
85
86        // Define field timemodified to be added to editor_atto_autosave.
87        $table = new xmldb_table('editor_atto_autosave');
88        $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'pageinstance');
89
90        // Conditionally launch add field timemodified.
91        if (!$dbman->field_exists($table, $field)) {
92            $dbman->add_field($table, $field);
93        }
94
95        // Atto savepoint reached.
96        upgrade_plugin_savepoint(true, 2014081900, 'editor', 'atto');
97    }
98
99    // Moodle v2.8.0 release upgrade line.
100    // Put any upgrade step following this.
101
102    return true;
103}
Note: See TracBrowser for help on using the repository browser.