Index: lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/data/lib.php,v retrieving revision 1.137.2.57 diff -u -r1.137.2.57 lib.php --- lib.php 27 Oct 2009 11:24:56 -0000 1.137.2.57 +++ lib.php 27 Sep 2010 18:17:31 -0000 @@ -669,35 +669,35 @@ * deletes an instance of a data * ************************************************************************/ function data_delete_instance($id) { // takes the dataid - global $CFG; + if (! $data = get_record('data', 'id', $id)) { return false; } - // Delete all the associated information + // delete all the files + require_once($CFG->libdir.'/filelib.php'); + $dir = $CFG->dataroot . '/' . $data->course . '/' . $CFG->moddata . '/data/' . $data->id; + fulldelete($dir); + // get all the records in this data - $sql = 'SELECT c.* FROM '.$CFG->prefix.'data_records r LEFT JOIN '. - $CFG->prefix.'data_content c ON c.recordid = r.id WHERE r.dataid = '.$id; + $sql = "SELECT r.id + FROM {$CFG->prefix}data_records r + WHERE r.dataid = $id"; - if ($contents = get_records_sql($sql)) { - foreach($contents as $content) { - $field = get_record('data_fields','id',$content->fieldid); - if ($g = data_get_field($field, $data)) { - $g->delete_content_files($id, $content->recordid, $content->content); - } - //delete the content itself - delete_records('data_content','id', $content->id); - } - } + // delete contents + delete_records_select('data_content', "recordid IN ($sql)"); - // delete all the records and fields + // delete records and fields delete_records('data_records', 'dataid', $id); - delete_records('data_fields','dataid',$id); + delete_records('data_fields', 'dataid', $id); // Delete the instance itself $result = delete_records('data', 'id', $id); + + // cleanup gradebook data_grade_item_delete($data); + return $result; }