9 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
function xmldb_block_openai_chat_upgrade($oldversion): bool {
|
|
|
4 |
global $CFG, $DB;
|
|
|
5 |
|
|
|
6 |
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
|
|
|
7 |
|
|
|
8 |
if ($oldversion < 2024040800) {
|
|
|
9 |
|
|
|
10 |
// Define table block_openai_chat_log to be created.
|
|
|
11 |
$table = new xmldb_table('block_openai_chat_log');
|
|
|
12 |
|
|
|
13 |
// Adding fields to table block_openai_chat_log.
|
|
|
14 |
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
|
|
15 |
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
16 |
$table->add_field('usermessage', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
|
|
|
17 |
$table->add_field('airesponse', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
|
|
18 |
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
19 |
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
|
|
20 |
|
|
|
21 |
// Adding keys to table block_openai_chat_log.
|
|
|
22 |
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
|
|
23 |
$table->add_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
|
|
|
24 |
|
|
|
25 |
// Adding indexes to table block_openai_chat_log.
|
|
|
26 |
$table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, ['timecreated']);
|
|
|
27 |
$table->add_index('user-time', XMLDB_INDEX_NOTUNIQUE, ['userid', 'timecreated']);
|
|
|
28 |
|
|
|
29 |
// Conditionally launch create table for block_openai_chat_log.
|
|
|
30 |
if (!$dbman->table_exists($table)) {
|
|
|
31 |
$dbman->create_table($table);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
// Openai_chat savepoint reached.
|
|
|
35 |
upgrade_block_savepoint(true, 2024040401, 'openai_chat');
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
// Everything has succeeded to here. Return true.
|
|
|
39 |
return true;
|
|
|
40 |
}
|