Skip to content

Commit 0970f99

Browse files
Merge pull request #2445 from adaptlearning/issue/2439
Find or create assets tags on import, fixes #2439
2 parents 2d3ee07 + e24bf59 commit 0970f99

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

plugins/filestorage/localfs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ LocalFileStorage.prototype.processFileUpload = function (file, newPath, options,
232232
if (options.createMetadata) {
233233
return self.inspectFile(newPath, file.type, function (err, withMeta) {
234234
if (withMeta) {
235-
data = _.extend(data, withMeta);
235+
Object.assign(data, withMeta);
236236
}
237237
nextFunc();
238238
});

plugins/output/adapt/helpers.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ function importAsset(fileMetadata, metadata, assetImported) {
167167
}
168168

169169
var asset = _.extend(fileMetadata, storedFile);
170-
_.each(asset.tags, function iterator(tag, index) {
171-
if (metadata.idMap[tag]) {
172-
asset.tags[index] = metadata.idMap[tag];
173-
}
174-
});
175170

176171
origin.assetmanager.createAsset(asset, function onAssetCreated(createError, assetRec) {
177172
if (createError) {

plugins/output/adapt/importsource.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,26 @@ function ImportSource(req, done) {
169169
var fileStat = fs.statSync(assetPath);
170170
var assetTitle = assetName;
171171
var assetDescription = assetName;
172-
var tags = formTags.slice();
172+
var assetJson = assetsJson[assetName];
173+
var tags = [];
173174

174-
if (assetsJson[assetName]) {
175-
assetTitle = assetsJson[assetName].title;
176-
assetDescription = assetsJson[assetName].description;
175+
if (assetJson) {
176+
assetTitle = assetJson.title;
177+
assetDescription = assetJson.description;
177178

178-
assetsJson[assetName].tags.forEach(function(tag) {
179-
tags.push(tag._id);
179+
assetJson.tags.forEach(function(tag) {
180+
const tagTitle = tag.title;
181+
const warn = (error) => logger.log('warn', `Failed to create asset tag '${tagTitle}' ${error}`);
182+
183+
if(!tagTitle) return warn(new Error('Tag has no title'));
184+
185+
app.contentmanager.getContentPlugin('tag', function(error, plugin) {
186+
if(error) return warn(error);
187+
plugin.create({ title: tagTitle }, function(error, record) { // @note retrieves if tag already exists
188+
if(error) return warn(error);
189+
tags.push(record._id);
190+
});
191+
});
180192
});
181193
}
182194
var fileMeta = {

0 commit comments

Comments
 (0)