Skip to content

Commit a18b9e2

Browse files
authored
Merge pull request #1679 from adaptlearning/issue/1427-fixes
Issue/1427 fixes
2 parents 0c6649d + c6ba6ef commit a18b9e2

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

plugins/content/courseasset/index.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function initialize() {
6666
if (articles && articles.length !== 0) {
6767
criteria._courseId = itemForDeletion._courseId;
6868
parentIds = _.pluck(articles, '_id');
69+
// add the contentObject id as parent for assets on articles
70+
parentIds.push(itemForDeletion._id);
6971
}
7072
async.each(articles, function(article, cb) {
7173
db.retrieve('block', {_courseId: article._courseId, _parentId: article._id}, function(err, blocks) {
@@ -83,8 +85,14 @@ function initialize() {
8385
} else {
8486
criteria._contentTypeId = itemForDeletion._id;
8587
}
86-
callback(null, 'Child content objects added to criteria object');
88+
cb();
8789
});
90+
}, function(error) {
91+
if (error) {
92+
callback(error);
93+
} else {
94+
callback(null, 'Child content objects added to criteria object');
95+
}
8896
});
8997
});
9098
},
@@ -99,9 +107,15 @@ function initialize() {
99107
}
100108
// Formulate the block search criteria.
101109
if (blocks && blocks.length !== 0) {
102-
// We have enough information to start removing course assets.
103-
criteria._contentTypeParentId = { $in: [_.pluck(blocks, '_id')] };
104110
criteria._courseId = itemForDeletion._courseId;
111+
// find any assets associated with the blocks as parent
112+
var parentArray = _.pluck(blocks, '_id');
113+
114+
parentArray.push(itemForDeletion._id);
115+
criteria.$or = [
116+
{ _contentTypeParentId: { $in: parentArray } },
117+
{ _contentTypeId: itemForDeletion._id }
118+
];
105119
}
106120
callback(null, 'Blocks added to criteria object');
107121
});
@@ -115,8 +129,11 @@ function initialize() {
115129
break;
116130
case 'block':
117131
criteria._courseId = itemForDeletion._courseId;
118-
criteria._contentTypeParentId = itemForDeletion._id;
119-
criteria._contentType = 'component';
132+
// Find assets directly associated with the block or with block as parent
133+
criteria.$or = [
134+
{ _contentTypeId: itemForDeletion._id },
135+
{ _contentTypeParentId: itemForDeletion._id }
136+
]
120137
break;
121138
case 'component':
122139
criteria._courseId = itemForDeletion._courseId;

0 commit comments

Comments
 (0)