Skip to content

Commit ef4c832

Browse files
Merge pull request #2526 from adaptlearning/issue/2316
Fix automatic plugin update
2 parents aa3cd1d + 410a091 commit ef4c832

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

lib/bowermanager.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,43 @@ BowerManager.prototype.installLatestCompatibleVersion = function (pluginName, ca
173173
}
174174
var requiredFrameworkVersion;
175175
var index = -1;
176+
var pluginType;
176177
async.doUntil(function iterator(cb) {
177178
bower.commands.info(bowerPackage.url + '#' + latestInfo.versions[++index])
178179
.on('error', cb)
179180
.on('end', function (result) {
180181
requiredFrameworkVersion = result.framework;
182+
pluginType = Object.keys(result).find(key => {
183+
return [ 'component', 'extension', 'menu', 'theme' ].includes(key);
184+
});
181185
cb();
182186
});
183187
}, async function isCompatible() {
184188
return semver.satisfies(installedFrameworkVersion, requiredFrameworkVersion);
185-
}, function(error, version) {
189+
}, error => {
186190
if(error) {
187191
return callback(error);
188192
}
189-
self.installPlugin(pluginName, latestInfo.versions[index], callback);
193+
app.contentmanager.getContentPlugin(pluginType, (error, plugin) => {
194+
if (error) {
195+
return callback(error);
196+
}
197+
app.db.retrieve(plugin.getPluginType(), {
198+
name: pluginName
199+
}, (error, results) => {
200+
if (error) {
201+
return callback(error);
202+
}
203+
var installedPlugin = results[0];
204+
var version = latestInfo.versions[index];
205+
if (installedPlugin &&
206+
semver.gte(installedPlugin.version, version) &&
207+
semver.satisfies(installedFrameworkVersion, installedPlugin.framework)) {
208+
return callback('Skipping as no newer compatible version found');
209+
}
210+
self.installPlugin(pluginName, version, callback);
211+
});
212+
});
190213
});
191214
});
192215
});
@@ -278,19 +301,29 @@ BowerManager.prototype.importPackage = function (plugin, packageInfo, options, c
278301

279302
// Add the package to the collection.
280303
// Check if a plugin with this name and version already exists.
281-
db.retrieve(plugin.getPluginType(), { name: package.name, version: package.version }, function (err, results) {
304+
db.retrieve(plugin.getPluginType(), {
305+
name: package.name
306+
}, function (err, results) {
282307
if (err) {
283308
logger.log('error', err);
284309
return callback(err);
285310
}
286311

287312
if (results && results.length !== 0) {
288-
// Don't add a duplicate.
289-
if (options.strict) {
290-
return callback("Can't add " + pluginString + ": verion already exists");
313+
var installedPlugin = results[0];
314+
315+
if (installedPlugin.version === package.version) {
316+
// Don't add a duplicate.
317+
if (options.strict) {
318+
return callback("Can't add " + pluginString + ": verion already exists");
319+
}
320+
321+
return callback(null);
291322
}
292323

293-
return callback(null);
324+
var keysToPersist = [ '_isAvailableInEditor', '_isAddedByDefault' ];
325+
326+
keysToPersist.forEach(key => package[key] = installedPlugin[key]);
294327
}
295328

296329
// Add the new plugin.

plugins/content/bower/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,10 @@ function addPackage (plugin, packageInfo, options, cb) {
879879
});
880880

881881
// Persist the _isAvailableInEditor flag.
882-
db.update(plugin.type, {_id: newPlugin._id}, {_isAvailableInEditor: oldPlugin._isAvailableInEditor}, function(err, results) {
882+
db.update(plugin.type, {_id: newPlugin._id}, {
883+
_isAvailableInEditor: oldPlugin._isAvailableInEditor,
884+
_isAddedByDefault: oldPlugin._isAddedByDefault
885+
}, function(err, results) {
883886
if (err) {
884887
logger.log('error', err);
885888
return addCb(err);

0 commit comments

Comments
 (0)