Skip to content

Commit 91fe2cf

Browse files
committed
fix #3 rename table and change sql in upgrade for compatibility with mysql
1 parent abef0d4 commit 91fe2cf

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

classes/lifecycle/log_table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($filterdata = []) {
6464
f.filename as filename, f.filesize as filesize, f.timecreated as createdat';
6565
$from = '{files} f
6666
JOIN {context} c ON c.id = f.contextid
67-
LEFT JOIN {tool_lcbackupcourselogstep_metadata} md ON f.id = md.fileid';
67+
LEFT JOIN {tool_lcbackupcourselogstep_m} md ON f.id = md.fileid';
6868

6969
$where = ["f.component = :component AND filename <> '.'"];
7070
$params = ['component' => 'tool_lcbackupcourselogstep'];

classes/lifecycle/step.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function process_course($processid, $instanceid, $course) {
131131
// Write data to file.
132132
$newfile = dataformat::write_data_to_filearea($filerecord, $fileformat, $columns, $logs);
133133

134-
$DB->insert_record('tool_lcbackupcourselogstep_metadata', [
134+
$DB->insert_record('tool_lcbackupcourselogstep_m', [
135135
'shortname' => $course->shortname,
136136
'fullname' => $course->fullname,
137137
'oldcourseid' => $course->id,

db/install.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
55
>
66
<TABLES>
7-
<TABLE NAME="tool_lcbackupcourselogstep_metadata" COMMENT="Metadata for course logs.">
7+
<TABLE NAME="tool_lcbackupcourselogstep_m" COMMENT="Metadata for course logs.">
88
<FIELDS>
99
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
10-
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true"/>
11-
<FIELD NAME="fullname" TYPE="char" LENGTH="255" NOTNULL="true"/>
12-
<FIELD NAME="oldcourseid" TYPE="int" LENGTH="10" NOTNULL="true"/>
13-
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true"/>
14-
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Timestamp when the log file was created"/>
10+
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
11+
<FIELD NAME="fullname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
12+
<FIELD NAME="oldcourseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
13+
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
14+
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Timestamp when the log file was created" SEQUENCE="false"/>
1515
</FIELDS>
1616
<KEYS>
1717
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

db/upgrade.php

+19-9
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
*/
3131
function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
3232
global $DB;
33+
$dbman = $DB->get_manager();
3334

3435
if ($oldversion < 2024102000) {
3536

36-
$table = new xmldb_table('tool_lcbackupcourselogstep_metadata');
37+
$table = new xmldb_table('tool_lcbackupcourselogstep_m');
3738

3839
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3940
$table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
@@ -50,7 +51,7 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
5051
}
5152

5253
$sql1 = "
53-
INSERT INTO {tool_lcbackupcourselogstep_metadata} (shortname, fullname, oldcourseid, fileid, timecreated)
54+
INSERT INTO {tool_lcbackupcourselogstep_m} (shortname, fullname, oldcourseid, fileid, timecreated)
5455
SELECT crs.shortname,
5556
crs.fullname,
5657
crs.id AS oldcourseid,
@@ -74,13 +75,15 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
7475
UPDATE {files}
7576
SET contextid = :contextid
7677
WHERE id IN (
77-
SELECT f.id
78-
FROM {files} f
79-
JOIN {context} ctx ON ctx.id = f.contextid
80-
WHERE ctx.contextlevel = :contextlevel
81-
AND f.component = :component
82-
AND f.filearea = :filearea
83-
)
78+
SELECT id FROM (
79+
SELECT f.id
80+
FROM {files} f
81+
JOIN {context} ctx ON ctx.id = f.contextid
82+
WHERE ctx.contextlevel = :contextlevel
83+
AND f.component = :component
84+
AND f.filearea = :filearea
85+
) as fs
86+
)
8487
";
8588
$DB->execute($sql2, [
8689
'contextid' => \context_system::instance()->id,
@@ -91,6 +94,13 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
9194

9295
upgrade_plugin_savepoint(true, 2024102000, 'tool', 'lcbackupcourselogstep');
9396
}
97+
if ($oldversion < 2025022000) {
98+
$table = new xmldb_table('tool_lcbackupcourselogstep_metadata');
99+
if ($dbman->table_exists($table)) {
100+
$dbman->rename_table($table, 'tool_lcbackupcourselogstep_m');
101+
}
102+
upgrade_plugin_savepoint(true, 2025022000, 'tool', 'lcbackupcourselogstep');
103+
}
94104

95105
return true;
96106
}

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2024102000;
27+
$plugin->version = 2025022000;
2828
$plugin->requires = 2022041200;
2929
$plugin->component = 'tool_lcbackupcourselogstep';
3030

0 commit comments

Comments
 (0)