moodle-filter_bibleversesnwt/db/upgrade.php
2024-03-08 09:16:19 +01:00

93 lines
3.6 KiB
PHP

<?php
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
* Database upgrade script
* @package filter_bibleversesnwt
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Hook to upgrade database upon plugin upgrade
* @param mixed $oldversion Version of plugin database before upgrade
* @return bool Upgrade success status
*
*/
function xmldb_filter_bibleversesnwt_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2024030800) {
// Define table filter_bibleversesnwt to be created.
$table = new xmldb_table('filter_bibleversesnwt');
// Adding fields to table filter_bibleversesnwt.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('book', XMLDB_TYPE_INTEGER, '5', null, null, null, null);
$table->add_field('ch', XMLDB_TYPE_INTEGER, '5', null, null, null, null);
$table->add_field('verse', XMLDB_TYPE_INTEGER, '5', null, null, null, null);
$table->add_field('book_end', XMLDB_TYPE_INTEGER, '5', null, null, null, null);
$table->add_field('ch_end', XMLDB_TYPE_INTEGER, '5', null, null, null, null);
$table->add_field('verse_end', XMLDB_TYPE_INTEGER, '5', null, null, null, null);
$table->add_field('content', XMLDB_TYPE_TEXT, null, null, null, null, null);
// Adding keys to table filter_bibleversesnwt.
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
// Conditionally launch create table for filter_bibleversesnwt.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Bibleversesnwt savepoint reached.
upgrade_plugin_savepoint(true, 2024030800, 'filter', 'bibleversesnwt');
}
if ($oldversion < 2024030801) {
// Define field time_retrieved to be added to filter_bibleversesnwt.
$table = new xmldb_table('filter_bibleversesnwt');
$field = new xmldb_field('time_retrieved', XMLDB_TYPE_INTEGER, '20', null, null, null, null, 'content');
// Conditionally launch add field time_retrieved.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Bibleversesnwt savepoint reached.
upgrade_plugin_savepoint(true, 2024030801, 'filter', 'bibleversesnwt');
}
if ($oldversion < 2024030802) {
// Define field lang to be added to filter_bibleversesnwt.
$table = new xmldb_table('filter_bibleversesnwt');
$field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '12', null, null, null, null, 'time_retrieved');
// Conditionally launch add field lang.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Bibleversesnwt savepoint reached.
upgrade_plugin_savepoint(true, 2024030802, 'filter', 'bibleversesnwt');
}
return true;
}