Skip to content

Commit 33108b9

Browse files
committed
Find or create assets tags on import, fixes #2439
1 parent 08cef6f commit 33108b9

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

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: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,27 @@ 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 tags = [];
173173

174174
if (assetsJson[assetName]) {
175175
assetTitle = assetsJson[assetName].title;
176176
assetDescription = assetsJson[assetName].description;
177177

178178
assetsJson[assetName].tags.forEach(function(tag) {
179-
tags.push(tag._id);
179+
dbInstance.retrieve('tag', { title: tag.title}, { fields: '_id' }, function(error, results) {
180+
if (results && results.length > 0) {
181+
tags.push(results[0]._id);
182+
} else {
183+
app.contentmanager.getContentPlugin('tag', function(error, plugin) {
184+
if(!error) {
185+
plugin.create({ title: tag.title}, function(error, record) {
186+
if(error) logger.log('warn', 'Failed to create asset tag: ' + (tag.title || '') + ' ' + error);
187+
tags.push(record._id);
188+
});
189+
};
190+
});
191+
}
192+
});
180193
});
181194
}
182195
var fileMeta = {

0 commit comments

Comments
 (0)