From: skodak Date: Mon, 2 Apr 2007 09:10:26 +0000 (+0000) Subject: MDL-9155 Error when creating an "image gallery" preset database when only some fields... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=651268e00eba0a6d1eb0b3cbbd181e8c79d80085;p=moodle.git MDL-9155 Error when creating an "image gallery" preset database when only some fields exist and do not remove existing data, comments and ratings when applying preset; merged from MOODLE_18_STABLE --- diff --git a/mod/data/preset.php b/mod/data/preset.php index 07d0c0b940..ae63537edb 100644 --- a/mod/data/preset.php +++ b/mod/data/preset.php @@ -656,7 +656,7 @@ class PresetImporter { $cid = optional_param("field_$nid", -1, PARAM_INT); /* A mapping. Just need to change field params. Data kept. */ - if ($cid != -1) { + if ($cid != -1 and isset($currentfields[$cid])) { $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data); foreach ($newfield as $param => $value) { if ($param != "id") { @@ -688,15 +688,17 @@ class PresetImporter { if (!array_key_exists($cid, $preservedfields)) { /* Data not used anymore so wipe! */ print "Deleting field $currentfield->name
"; - $id = $currentfield->id; + $id = $currentfield->id; + //Why delete existing data records and related comments/ratings?? +/* if ($content = get_records('data_content', 'fieldid', $id)) { foreach ($content as $item) { delete_records('data_ratings', 'recordid', $item->recordid); delete_records('data_comments', 'recordid', $item->recordid); delete_records('data_records', 'id', $item->recordid); } - } + }*/ delete_records('data_content', 'fieldid', $id); delete_records('data_fields', 'id', $id); }