30
30
*/
31
31
function xmldb_tool_lcbackupcourselogstep_upgrade ($ oldversion ) {
32
32
global $ DB ;
33
+ $ dbman = $ DB ->get_manager ();
33
34
34
35
if ($ oldversion < 2024102000 ) {
35
36
36
- $ table = new xmldb_table ('tool_lcbackupcourselogstep_metadata ' );
37
+ $ table = new xmldb_table ('tool_lcbackupcourselogstep_m ' );
37
38
38
39
$ table ->add_field ('id ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , XMLDB_SEQUENCE , null );
39
40
$ table ->add_field ('shortname ' , XMLDB_TYPE_CHAR , '255 ' , null , XMLDB_NOTNULL , null , null );
@@ -50,7 +51,7 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
50
51
}
51
52
52
53
$ sql1 = "
53
- INSERT INTO {tool_lcbackupcourselogstep_metadata } (shortname, fullname, oldcourseid, fileid, timecreated)
54
+ INSERT INTO {tool_lcbackupcourselogstep_m } (shortname, fullname, oldcourseid, fileid, timecreated)
54
55
SELECT crs.shortname,
55
56
crs.fullname,
56
57
crs.id AS oldcourseid,
@@ -74,13 +75,15 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
74
75
UPDATE {files}
75
76
SET contextid = :contextid
76
77
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
+ )
84
87
" ;
85
88
$ DB ->execute ($ sql2 , [
86
89
'contextid ' => \context_system::instance ()->id ,
@@ -91,6 +94,13 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
91
94
92
95
upgrade_plugin_savepoint (true , 2024102000 , 'tool ' , 'lcbackupcourselogstep ' );
93
96
}
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
+ }
94
104
95
105
return true ;
96
106
}
0 commit comments