/** * Does a bulk_delete on a list of artefacts, grouping artefacts of * the same type. * * Currently only tested for folders and their contents. */ public static function delete_by_artefacttype($artefactids) { if (empty($artefactids)) { return; } db_begin(); artefact_watchlist_notification($artefactids); // Delete comments first safe_require('artefact', 'comment'); ArtefactTypeComment::delete_comments_onartefacts($artefactids); $records = get_records_select_assoc('artefact', 'id IN (' . join(',', array_map('intval', $artefactids)) . ')', null, 'artefacttype', 'id,parent,artefacttype,container'); $containers = array(); $leaves = array(); foreach ($records as $r) { if ($r->container) { $containers[$r->artefacttype][] = (int) $r->id; } else { $leaves[$r->artefacttype][] = $r->id; } } // Delete non-containers grouped by artefacttype foreach ($leaves as $artefacttype => $ids) { $classname = generate_artefact_class_name($artefacttype); call_static_method($classname, 'bulk_delete', $ids); } // Delete containers grouped by artefacttype foreach ($containers as $artefacttype => $ids) { $classname = generate_artefact_class_name($artefacttype); if (is_mysql()) { set_field_select('artefact', 'parent', null, 'id IN (' . join(',', $ids) . ')', array()); } call_static_method($classname, 'bulk_delete', $ids); } handle_event('deleteartefacts', $artefactids); db_commit(); }