MDL-76083 mod_data: Fix preset importer

* We should delete fields that have not been marked as to preserve.
This commit is contained in:
Laurent David
2022-11-16 13:15:28 +01:00
committed by Amaia Anabitarte
parent ce4bdc144e
commit 09ed58c5a1
4 changed files with 80 additions and 10 deletions
+8 -10
View File
@@ -2704,17 +2704,15 @@ abstract class data_preset_importer {
}
/* Get rid of all old unused data */
if (!empty($preservedfields)) {
foreach ($currentfields as $cid => $currentfield) {
if (!array_key_exists($cid, $preservedfields)) {
/* Data not used anymore so wipe! */
print "Deleting field $currentfield->name<br />";
foreach ($currentfields as $cid => $currentfield) {
if (!array_key_exists($cid, $preservedfields)) {
/* Data not used anymore so wipe! */
echo "Deleting field $currentfield->name<br />";
$id = $currentfield->id;
//Why delete existing data records and related comments/ratings??
$DB->delete_records('data_content', array('fieldid'=>$id));
$DB->delete_records('data_fields', array('id'=>$id));
}
$id = $currentfield->id;
// Why delete existing data records and related comments/ratings??
$DB->delete_records('data_content', ['fieldid' => $id]);
$DB->delete_records('data_fields', ['id' => $id]);
}
}