Commit b2f2365b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Delete all comments on artefacts before deleting the artefact (bug #629156)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 154e4c31
......@@ -194,6 +194,12 @@ class ArtefactTypeComment extends ArtefactType {
self::bulk_delete($ids);
}
public static function delete_comments_onartefacts($artefactids) {
$idstr = join(',', array_map('intval', $artefactids));
$commentids = get_column_sql("SELECT artefact FROM {artefact_comment_comment} WHERE onartefact IN ($idstr)");
self::bulk_delete($commentids);
}
public static function get_links($id) {
return array(
'_default' => get_config('wwwroot') . 'artefact/comment/view.php?id=' . $id,
......
......@@ -479,6 +479,10 @@ abstract class ArtefactType {
db_begin();
// Call delete() on comments (if there are any)
safe_require('artefact', 'comment');
ArtefactTypeComment::delete_comments_onartefacts(array($this->id));
// Call delete() on children (if there are any)
if ($children = $this->get_children_instances()) {
foreach ($children as $child) {
......@@ -519,6 +523,10 @@ abstract class ArtefactType {
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)) . ')',
......
......@@ -1082,7 +1082,10 @@ function delete_user($userid) {
$view->delete();
}
}
$artefactids = get_column('artefact', 'id', 'owner', $userid);
// @todo: test all artefact bulk_delete stuff, then replace the one-by-one
// artefact deletion below with ArtefactType::delete_by_artefacttype($artefactids);
if ($artefactids) {
foreach ($artefactids as $artefactid) {
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment