87 lines
		
	
	
	
		
			3.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
	
		
			3.2 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    local_treestudyplan
 | 
						|
 * @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_tool_sptoolboxmgr_upgrade($oldversion) {
 | 
						|
    global $DB;
 | 
						|
    $dbman = $DB->get_manager();
 | 
						|
 | 
						|
    if ($oldversion < 2024051201) {
 | 
						|
 | 
						|
        // Define table tool_sptoolboxmgr to be created.
 | 
						|
        $table = new xmldb_table('tool_sptoolboxmgr');
 | 
						|
 | 
						|
        // Adding fields to table tool_sptoolboxmgr.
 | 
						|
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 | 
						|
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '12', null, null, null, null);
 | 
						|
        $table->add_field('enrolled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
 | 
						|
        $table->add_field('track', XMLDB_TYPE_CHAR, '250', null, null, null, null);
 | 
						|
 | 
						|
        // Adding keys to table tool_sptoolboxmgr.
 | 
						|
        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
 | 
						|
 | 
						|
        // Conditionally launch create table for tool_sptoolboxmgr.
 | 
						|
        if (!$dbman->table_exists($table)) {
 | 
						|
            $dbman->create_table($table);
 | 
						|
        }
 | 
						|
 | 
						|
        // Sptoolboxmgr savepoint reached.
 | 
						|
        upgrade_plugin_savepoint(true, 2024051201, 'tool', 'sptoolboxmgr');
 | 
						|
    }
 | 
						|
 | 
						|
    if ($oldversion < 2024051202) {
 | 
						|
 | 
						|
        // Define field coach to be added to tool_sptoolboxmgr.
 | 
						|
        $table = new xmldb_table('tool_sptoolboxmgr');
 | 
						|
        $field = new xmldb_field('coach', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'track');
 | 
						|
 | 
						|
        // Conditionally launch add field coach.
 | 
						|
        if (!$dbman->field_exists($table, $field)) {
 | 
						|
            $dbman->add_field($table, $field);
 | 
						|
        }
 | 
						|
 | 
						|
        // Sptoolboxmgr savepoint reached.
 | 
						|
        upgrade_plugin_savepoint(true, 2024051202, 'tool', 'sptoolboxmgr');
 | 
						|
    }
 | 
						|
 | 
						|
    if ($oldversion < 2024051203) {
 | 
						|
 | 
						|
        // Define field toolboxid to be added to tool_sptoolboxmgr.
 | 
						|
        $table = new xmldb_table('tool_sptoolboxmgr');
 | 
						|
        $field = new xmldb_field('toolboxid', XMLDB_TYPE_INTEGER, '12', null, null, null, null, 'coach');
 | 
						|
 | 
						|
        // Conditionally launch add field toolboxid.
 | 
						|
        if (!$dbman->field_exists($table, $field)) {
 | 
						|
            $dbman->add_field($table, $field);
 | 
						|
        }
 | 
						|
 | 
						|
        // Sptoolboxmgr savepoint reached.
 | 
						|
        upgrade_plugin_savepoint(true, 2024051203, 'tool', 'sptoolboxmgr');
 | 
						|
    }
 | 
						|
 | 
						|
    return true;
 | 
						|
}
 |