Skip to content

Commit

Permalink
Merge pull request pencilblue#862 from pencilblue/issue/859
Browse files Browse the repository at this point in the history
Fixes pencilblue#589 - Provides mechanism to pass context to onInstall function…
  • Loading branch information
brianhyder committed Nov 17, 2015
2 parents bcb847e + 066b5dc commit 4d67612
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions include/service/jobs/plugins/plugin_install_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,16 @@ module.exports = function PluginInstallJobModule(pb) {
function(callback) {

var mainModule = pb.PluginService.loadMainModule(pluginUid, details.main_module.path);
if (!util.isNullOrUndefined(mainModule) && util.isFunction(mainModule.onInstall)) {
var hasBasicOnInstall = util.isFunction(mainModule.onInstall);
var hasContextOnInstall = util.isFunction(mainModule.onInstallWithContext);
if (!util.isNullOrUndefined(mainModule) && (hasBasicOnInstall || hasContextOnInstall)) {
self.log("Executing %s 'onInstall' function", details.uid);
mainModule.onInstall(callback);

if (hasBasicOnInstall) {
return mainModule.onInstall(callback);
}

mainModule.onInstallWithContext({ site: site }, callback);
}
else {
self.log("WARN: Plugin %s did not provide an 'onInstall' function.", details.uid);
Expand Down
5 changes: 3 additions & 2 deletions plugins/sample/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ module.exports = function SamplePluginModule(pb) {

/**
* Called when the application is being installed for the first time.
*
* @static
* @method onInstallWithContext
* @param cb A callback that must be called upon completion. cb(Error, Boolean).
* The result should be TRUE on success and FALSE on failure
*/
SamplePlugin.onInstall = function(cb) {
SamplePlugin.onInstallWithContext = function(context, cb) {
cb(null, true);
};

Expand Down

0 comments on commit 4d67612

Please sign in to comment.