@@ -89,12 +89,13 @@ protected function process_cms_types(array $data) {
89
89
90
90
$ typeid = $ this ->find_existing_cms_type ($ data );
91
91
92
+ // TODO: Ignoring a missing CMS type currently causes a crash during the restore process.
92
93
if ($ typeid === false ) {
93
- $ typeid = $ DB -> insert_record ( ' cms_types ' , $ data );
94
+ throw new moodle_exception ( ' CMS type not found for idnumber ' . $ data-> idnumber );
94
95
}
95
96
97
+ // If we can find a type ID, we can restore the mapping.
96
98
$ this ->set_mapping ('cms_types ' , $ oldid , $ typeid , true );
97
-
98
99
$ DB ->update_record ('cms ' , (object ) ['id ' => $ this ->get_new_parentid ('cms ' ), 'typeid ' => $ typeid ]);
99
100
}
100
101
@@ -111,33 +112,8 @@ protected function find_existing_cms_type(\stdClass $data) {
111
112
return $ typeid ;
112
113
}
113
114
114
- if ($ this ->task ->is_samesite ()) {
115
- if ($ DB ->record_exists ('cms_types ' , ['id ' => $ data ->id ])) {
116
- return $ data ->id ;
117
- }
118
- }
119
-
120
- // Try to find a CMS type is that is a match for content. Returns false if none found.
121
- $ sqltitlemustache = $ DB ->sql_compare_text ('title_mustache ' );
122
- $ sqltitlemustacheparam = $ DB ->sql_compare_text (':title_mustache ' );
123
- $ sqlmustache = $ DB ->sql_compare_text ('mustache ' );
124
- $ sqlmustacheparam = $ DB ->sql_compare_text (':mustache ' );
125
-
126
- $ sql = "SELECT id
127
- FROM {cms_types}
128
- WHERE name = :name
129
- AND idnumber = :idnumber
130
- AND datasources = :datasources
131
- AND $ sqltitlemustache = $ sqltitlemustacheparam
132
- AND $ sqlmustache = $ sqlmustacheparam " ;
133
- $ params = [
134
- 'name ' => $ data ->name ,
135
- 'idnumber ' => $ data ->idnumber ,
136
- 'datasources ' => $ data ->datasources ,
137
- 'title_mustache ' => $ data ->title_mustache ,
138
- 'mustache ' => $ data ->mustache ,
139
- ];
140
- $ record = $ DB ->get_record_sql ($ sql , $ params );
115
+ // Try to find a CMS type that matches idnumber. Returns false if none found.
116
+ $ record = $ DB ->get_record ('cms_types ' , ['idnumber ' => $ data ->idnumber ]);
141
117
142
118
return $ record ->id ?? false ;
143
119
}
0 commit comments