From 93d0c5a3c6e616962bf9df539a5c6a3352e77119 Mon Sep 17 00:00:00 2001 From: charles Date: Wed, 17 May 2017 11:55:55 +1000 Subject: [PATCH] do a check for existing value in passed through data object --- fields/types/embedly/EmbedlyType.js | 41 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/fields/types/embedly/EmbedlyType.js b/fields/types/embedly/EmbedlyType.js index b0e2cad1a7..2bfa7d9a3a 100644 --- a/fields/types/embedly/EmbedlyType.js +++ b/fields/types/embedly/EmbedlyType.js @@ -221,24 +221,29 @@ embedly.prototype.inputIsValid = function () { embedly.prototype.updateItem = function (item, data, callback) { // TODO: This could be more granular and check for actual changes to values, // see the Location field for an example - item.set(item.set(this.path, { - exists: data[this.paths.exists], - type: data[this.paths.type], - title: data[this.paths.title], - url: data[this.paths.url], - width: data[this.paths.width], - height: data[this.paths.height], - version: data[this.paths.version], - description: data[this.paths.description], - html: data[this.paths.html], - authorName: data[this.paths.authorName], - authorUrl: data[this.paths.authorUrl], - providerName: data[this.paths.providerName], - providerUrl: data[this.paths.providerUrl], - thumbnailUrl: data[this.paths.thumbnailUrl], - thumbnailWidth: data[this.paths.thumbnailWidth], - thumbnailHeight: data[this.paths.thumbnailHeight], - })); + + // This field type is never editable, so to ensure that we don't inadvertently reset the fields on this item with a null value + // A conditional has been added to negate updating this item should the fromPath on the passed in data object be the same as that on the item. + if (data[this.fromPath] !== item[this.fromPath]) { + item.set(item.set(this.path, { + exists: data[this.paths.exists], + type: data[this.paths.type], + title: data[this.paths.title], + url: data[this.paths.url], + width: data[this.paths.width], + height: data[this.paths.height], + version: data[this.paths.version], + description: data[this.paths.description], + html: data[this.paths.html], + authorName: data[this.paths.authorName], + authorUrl: data[this.paths.authorUrl], + providerName: data[this.paths.providerName], + providerUrl: data[this.paths.providerUrl], + thumbnailUrl: data[this.paths.thumbnailUrl], + thumbnailWidth: data[this.paths.thumbnailWidth], + thumbnailHeight: data[this.paths.thumbnailHeight], + })); + } process.nextTick(callback); };