PluginService Class
PluginService - Provides functions for interacting with plugins. Install/uninstall, setting retrieval, plugin retrieval, etc.
Constructor
PluginService
-
options
Parameters:
-
optionsObject-
[site]String optional
-
Item Index
Methods
- activatePlugin static
- deactivatePlugin static
- genPublicPath static
- genSettingsService static
- getActiveContentTemplates static
- getActiveIcon
- getActiveMainModule static
- getActivePluginDir static
- getActivePluginNames
- getActivePlugins
- getAllActivePluginNames
- getAvailablePlugins
- getDetailsPath static
- getInactivePlugins
- getLocalizations deprecated
- getPermissionsForRole static
- getPlugin
- getPluginBySite
- getPluginMap
- getPluginsDir static
- getPluginsWithThemes
- getPluginsWithThemesBySite
- getPublicPath static
- getService deprecated
- getService static
- getServiceName static deprecated
- getServices static deprecated
- getSetting
- getSettings
- getSettingsKV
- getThemeSetting
- getThemeSettings
- getThemeSettingsBySite
- getThemeSettingsKV
- hasDependencies
- init static
- initPlugin
- initPlugins
- installPlugin
- installPluginDependencies
- isActivePlugin static
- isActivePlugin static
- isInstalled
- loadController static
- loadControllers static deprecated
- loadDetailsFile static
- loadMainModule static
- loadService static deprecated
- onIsPluginAvailableCommandReceived static
- onIsPluginAvailableCommandReceived static
- onIsPluginAvailableCommandReceived static
- onUninstallPluginCommandReceived static
- purgePluginSettings
- purgeThemeSettings
- require static deprecated
- resetSettings
- resetSettings
- resetThemeSettings
- resetThemeSettings
- setSetting
- setSettings
- setThemeSetting
- setThemeSettings
- syncSettings
- uninstallPlugin
- validateDetails static deprecated
- validateIconPath static deprecated
- validateMainModulePath static deprecated
- validateSetting deprecated
- validateSettingValue static deprecated
Methods
activatePlugin
-
pluginUid -
pluginSpec -
site
Activates a plugin based on the UID and the provided spec
Parameters:
-
pluginUidString -
pluginSpecObject-
main_moduleFunction -
public_dirString -
permissionsObject -
templatesArray -
iconString -
servicesObject
-
-
siteString
Returns:
TRUE if the site is set as active and FALSE when the site is already active
deactivatePlugin
-
pluginUid -
site
Remove the active plugin entry from the current PB process. NOTE: it is not recommended to call this directly.
Parameters:
-
pluginUidString -
siteString
Returns:
genPublicPath
-
plugin -
relativePathToMedia
Generates a URL path to a public resource for a plugin.
Parameters:
-
pluginStringThe UID of the plugin
-
relativePathToMediaStringThe relative path to the resource from the plugin's public directory.
Returns:
URL path to the resource
genSettingsService
-
objType -
useMemory -
useCache -
serviceName -
site
Convenience function to generate a service to handle settings for a plugin.
Parameters:
-
objTypeObjectThe type of object that will be dealt with. (plugin_settings, theme_settings)
-
useMemoryBooleanIndicates if the generated layered service should use an in memory service.
-
useCacheBooleanIndicates if the generated layered service should use a cache service.
-
serviceNameObjectThe name of the service
-
siteString
Returns:
getActiveContentTemplates
-
targetSite
Retrieves the content templates for all of the active plugins
Parameters:
-
targetSiteObject
Returns:
An array of objects
getActiveIcon
-
cb
Retrieves the path to the active fav icon.
Parameters:
-
cbFunctionA callback that provides two parameters: cb(Error, URL_PATH_TO_ICON)
getActiveMainModule
-
pluginUid -
site
Retrieves the main module prototype for the specified active plugin
Parameters:
-
pluginUidString -
siteString
Returns:
The prototype that is the plugin's main module.
getActivePluginDir
-
pluginUid
Retrieves the file path to the public directory for the specified plugin.
Parameters:
-
pluginUidStringA plugin's UID value
Returns:
File path to the plugin's public directory
getActivePluginNames
()
Array
Retrieves the names of the active plugins for this instance
Returns:
An array that contain the names of the plugins that initialized successfully within this instance.
getActivePlugins
-
cb
Retrieves the details for the active plugins.
Parameters:
-
cbFunctionA callback that provides two parameters: cb(Error, Array)
getAllActivePluginNames
()
Array
Get a array of active plugin names with site name as a prefix: site_name_plugin_name
Returns:
array of active plugin names with site name prefix.
getAvailablePlugins
-
active -
inactive -
cb
Retrieves the available plugins. An available plugin is one who is uninstalled but available to be installed.
Parameters:
-
activeArrayAn array of plugin detail objects. Each object is required to have a uid property that is a string.
-
inactiveArrayAn array of plugin details objects. Each object is required to have a uid property that is a string.
-
cbFunctionA callback that provides two parameters: cb(Error, Array)
getDetailsPath
-
pluginDirName
Constructs the path to a specific plugin's details.json file
Parameters:
-
pluginDirNameStringThe name of the directory that the plugin is contained within.
Returns:
The absolute file path to the details.json file for a plugin
getInactivePlugins
-
cb
Retrieves the inactive plugins for this instance of PencilBlue. An inactive plugin is considered one who failed to install or one that failed to start properly.
Parameters:
-
cbFunctionA callback that provides two parameters: cb(Error, Array)
getLocalizations
-
pluginDirName -
cb
Loads the localization files from the specified plugin directory and places them into a hash where the key is the name of the localization file.
Parameters:
-
pluginDirNameStringThe name of the plugin directory
-
cbFunctionA callback that provides two parameters: cb(Error, Object). When the directory does not exist NULL is returned as the result parameter.
getPermissionsForRole
-
role
Retrieves the permission set for a given role. All active plugins are inspected.
Parameters:
-
roleInteger | StringThe role to get permissions for
Returns:
A hash of the permissions
getPlugin
-
pluginIdentifier -
cb
Retrieves a plugin descriptor (plugin document)
Parameters:
-
pluginIdentifierStringThe identifier can either be an ObjectID or the plugin name
-
cbFunctionA callback that provides two parameters: cb(error, plugin). If the plugin does exist null is provided.
getPluginBySite
-
pluginIdentifier -
cb
Parameters:
-
pluginIdentifierString -
cbFunction
getPluginMap
-
cb
Retrieves a map of the system's plugin. The map provides three properties: active, inactive, available.
Parameters:
-
cbFunctionA callback that provides two parameters: cb(Error, Object)
getPluginsDir
()
String
static
Returns:
The absolute file path to the plugins directory
getPluginsWithThemes
-
cb
Retrieves the plugins that have themes associated with them
Parameters:
-
cbFunctionProvides two parameters: Error, Array
getPluginsWithThemesBySite
-
cb
Get plugins that contain a theme on a site level.
Parameters:
-
cbFunction- callback function
getPublicPath
-
pluginDirName
Retrieves the absolute file path to a plugin's public directory
Parameters:
-
pluginDirNameObjectThe name of the directory that contains the intended plugin
Returns:
the absolute file path to a plugin's public directory
getService
-
serviceName -
pluginUid -
site
Retrieves a plugin service prototype. It is expected to be a prototype but it may also be an instance as along as that instance fulfills all responsibilities of the service interface. When the desired service does not exist NULL is returned.
Parameters:
-
serviceNameString -
pluginUidStringThe unique plugin identifier
-
siteString
Returns:
Service prototype
getService
-
serviceName -
pluginUid -
[site=global]
Retrieves a plugin service prototype. It is expected to be a prototype but it may also be an instance as along as that instance fulfills all responsibilities of the service interface. When the desired service does not exist NULL is returned.
Parameters:
-
serviceNameString -
pluginUidStringThe unique plugin identifier
-
[site=global]String optional- The site UID
Returns:
Service prototype
getServiceName
-
pathToService -
service
Derives the name of a plugin service instance. The function attempts to get the name of the service by looking to see if the service has implemented the getName function. If it has not then the service name is set to be the file name minus any extension.
Parameters:
-
pathToServiceObjectThe file path to the service
-
serviceObjectThe service prototype
Returns:
The derived service name
getServices
-
pathToPlugin -
cb
Retrieves all services (initialized). The services are provided in the callback.
Parameters:
-
pathToPluginStringThe absolute file path to the specific plugin directory.
-
cbFunctionA callback that provides two parameters: cb(error, servicesHash);
getSetting
-
settingName -
pluginName -
cb
Retrieves a single setting for the specified plugin.
Parameters:
-
settingNameStringThe name of the setting to retrieve
-
pluginNameStringThe name of the plugin who owns the setting
-
cbFunctionA callback that provides two parameters: cb(error, settingValue). Null is returned if the setting does not exist or the specified plugin is not installed.
getSettings
-
pluginName -
cb
Retrieves all of the settings for the specfied plugin.
Parameters:
-
pluginNameObjectThe name of the plugin who's settings are being requested
-
cbObjectA callback that provides two parameters: cb(error, settings). Null is provided in the event that the plugin is not installed.
getSettingsKV
-
pluginName -
cb
Retrieves the settings for a plugin as hash of key/value pairs. This differs from the getSettings function because the getSettings function provides the settings in their raw form as an array of objects containing multiple properties. In most circumstances just the k/v pair is needed and not any additional information about the property. The function takes the raw settings array and transforms it into an object where the setting name is the property and the setting value is the value.
Parameters:
-
pluginNameStringThe unique ID of the plugin who settings are to be retrieved
-
cbFunctionA callback that takes two parameters. A error, if exists, and a hash of of the plugin's settings' names/values.
getThemeSetting
-
settingName -
pluginName -
cb
Retrieves a single theme setting value.
Parameters:
-
settingNameObjectThe uid of the setting
-
pluginNameObjectThe plugin to retrieve the setting from
-
cbObjectA callback that provides two parameters: cb(error, settingValue)
getThemeSettings
-
pluginName -
cb
Retrieves the theme settings for the specified plugin
Parameters:
-
pluginNameObjectThe uid of the plugin
-
cbObjectA callback that provides two parameters: cb(err, settingsObject)
getThemeSettingsBySite
-
pluginName -
cb
Retrieves the theme settings for the specified plugin only for the site set in the current plugin service
Parameters:
-
pluginNameObject -
cbObject
getThemeSettingsKV
-
pluginName -
cb
Retrieves the theme settings for a plugin as hash of key/value pairs. This differs from the getThemeSettings function because the getThemeSettings function provides the settings in their raw form as an array of objects containing multiple properties. In most circumstances just the k/v pair is needed and not any additional information about the property. The function takes the raw settings array and transforms it into an object where the setting name is the property and the setting value is the value.
Parameters:
-
pluginNameStringThe unique ID of the plugin who settings are to be retrieved
-
cbFunctionA callback that takes two parameters. A error, if exists, and a hash of of the plugin's settings' names/values.
hasDependencies
-
plugin -
cb
Verifies that a plugin has all of the required dependencies installed from NPM
Parameters:
-
pluginObject -
cbFunction
init
()
static
initPlugin
-
plugin -
cb
Initializes a plugin during startup or just after a plugin has been installed.
Parameters:
-
pluginObjectThe plugin details
-
cbFunctionA callback that provides two parameters: cb(Error, Boolean)
initPlugins
-
cb
Attempts to initialize all installed plugins.
Parameters:
-
cbFunctionA callback that provides two parameters: cb(Error, Boolean)
installPlugin
-
pluginDirName -
[cb]
Installs a plugin by stepping through a series of steps that must be completed in order. There is currently no fallback plan for a failed install. In order for a plugin to be fully installed it must perform the following actions without error:
- Load and parse the plugin's details.json file
- Pass validation
- Must not already be installed
- Successfully register itself with the system
- Successfully load any plugin settings
- Successfully load any theme settings
- Successfully execute the plugin's onInstall function
- Successfully initialize the plugin for runtime
Parameters:
-
pluginDirNameStringThe name of the directory that contains the plugin and its details.json file.
-
[cb]Function optionalA callback that provides two parameters: cb(err, TRUE/FALSE)
Returns:
The job ID
installPluginDependencies
-
pluginDirName -
dependencies -
plugin -
cb
Installs the dependencies for a plugin via NPM.
Parameters:
-
pluginDirNameString -
dependenciesObject -
pluginObject -
cbFunction
isActivePlugin
-
uid -
site
Indicates if the specified plugin is active in this instance of PB.
Parameters:
-
uidStringThe unique identifier for a plugin
-
siteString
Returns:
TRUE if the plugin is active, FALSE if not
isActivePlugin
-
uid -
site
Indicates if the specified plugin is active for a given site in this instance of PB.
Parameters:
-
uidStringThe unique identifier for a plugin
-
siteString
Returns:
TRUE if the plugin is active, FALSE if not
isInstalled
-
pluginIdentifier -
cb
Indicates if a plugin by the specified identifier is installed.
Parameters:
-
pluginIdentifierStringThe identifier can either be an ObjectID or the plugin name
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the plugin is installed, FALSE if not.
loadController
-
pathToController -
pluginUid -
site -
cb
Loads a controller for a plugin and attempts to register the route with the RequestHandler.
Parameters:
-
pathToControllerStringThe absolute file path to the controller
-
pluginUidStringThe unique identifier for the plugin
-
siteString -
cbFunctionA callback that provides two parameters: cb(Error, Boolean)
loadControllers
-
pathToPlugin -
pluginUid -
site -
cb
Loads the controllers for a plugin by iterating through the files in the plugin's controllers directory.
Parameters:
-
pathToPluginStringThe absolute file path to the plugin =
-
pluginUidStringThe unique identifier for the plugin
-
siteString -
cbFunctionA callback that provides two parameters: cb(Error, Array)
loadDetailsFile
-
filePath -
cb
Attempts to load and parse the details.json file for a plugin.
Parameters:
-
filePathStringThe absolute path to the details.json file
-
cbFunctionA callback that provides two parameters: cb(error, detailsObject)
loadMainModule
-
pluginDirName -
pathToModule
Attempts to require the main module file for a plugin.
Parameters:
-
pluginDirNameStringThe name of the directory that the plugin is contained within.
-
pathToModuleStringThe name of the main module file. It is also to pass this parameter as the absolute file path to the module. The function first checks if the parameter is just the file name then checks to see if it is an absolute path.
Returns:
The main-module prototype
loadService
-
pathToService -
cb
Loads a plugin service and initializes it. The service is required to implement an "init" function. The service is then provided as a parameter in the callback.
Parameters:
-
pathToServiceStringThe absolute file path to the service javascript file.
-
cbFunctionA callback that provides two parameters: cb(error, initializedService)
onIsPluginAvailableCommandReceived
-
command
NOTE: DO NOT CALL THIS DIRECTLY
The function is called when a command is recevied to install plugin
dependencies. The result is then sent back to the calling process via the
CommandService.
Parameters:
-
commandObject-
jobIdStringThe ID of the in-progress job that this process is intended to join.
-
onIsPluginAvailableCommandReceived
-
command
NOTE: DO NOT CALL THIS DIRECTLY
The function is called when a command is recevied to initialize a plugin.
The result is then sent back to the calling process via the
CommandService.
Parameters:
-
commandObject-
jobIdStringThe ID of the in-progress job that this process is intended to join.
-
onIsPluginAvailableCommandReceived
-
command
NOTE: DO NOT CALL THIS DIRECTLY
The function is called when a command is recevied to validate that a plugin is available to this process for install.
The function builds out the appropriate options then calls the
uninstallPlugin function. The result is then sent back to the calling
process via the CommandService.
Parameters:
-
commandObject-
jobIdStringThe ID of the in-progress job that this process is intended to join.
-
onUninstallPluginCommandReceived
-
command
NOTE: DO NOT CALL THIS DIRECTLY
The function is called when a command is recevied to uninstall a plugin.
The function builds out the appropriate options then calls the
uninstallPlugin function. The result is then sent back to the calling
process via the CommandService.
Parameters:
-
commandObject-
jobIdStringThe ID of the in-progress job that this process is intended to join.
-
purgePluginSettings
-
pluginUid -
cb
Deletes the plugin settings for when plugin uninstalls.
Parameters:
-
pluginUidString- the plugin unique id
-
cbFunction- callback function
purgeThemeSettings
-
pluginUid -
cb
Deletes the theme settings for when plugin uninstalls.
Parameters:
-
pluginUidString- the plugin unique id
-
cbFunction- callback function
require
-
pluginDirName -
moduleName
Loads a module dependencies for the specified plugin.
Parameters:
-
pluginDirNameString -
moduleNameString
Returns:
The entity returned by the "require" call.
resetSettings
-
details -
cb
Loads the settings from a details object and persists them in the DB. Any existing settings for the plugin are deleted before the new settings are persisted.
Parameters:
-
detailsObjectThe details object to extract the settings from
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the settings were successfully cleared and reloaded. FALSE if not.
resetSettings
-
details -
cb
Loads the settings from a details object and persists them in the DB. Any existing settings for the plugin are deleted before the new settings are persisted.
Parameters:
-
detailsObjectThe details object to extract the settings from
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the settings were successfully cleared and reloaded. FALSE if not.
resetThemeSettings
-
details -
cb
Loads the Theme settings from a details object and persists them in the DB. Any existing theme settings for the plugin are deleted before the new settings are persisted. If the plugin does not have a theme then false is provided in the callback.
Parameters:
-
detailsObjectThe details object to extract the settings from
-
cbFunctionA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the settings were successfully cleared and reloaded. FALSE if not.
resetThemeSettings
-
details -
cb
Loads the Theme settings from a details object and persists them in the DB. Any existing theme settings for the plugin are deleted before the new settings are persisted. If the plugin does not have a theme then false is provided in the callback.
Parameters:
-
detailsObjectThe details object to extract the settings from
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the settings were successfully cleared and reloaded. FALSE if not.
setSetting
-
name -
value -
pluginName -
cb
Replaces a single setting for the specified plugin
Parameters:
-
nameObjectThe name of the setting to change
-
valueObjectThe new value for the setting
-
pluginNameObjectThe plugin who's setting is being changed.
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the setting was persisted successfully, FALSE if not.
setSettings
-
settings -
pluginName -
cb
Replaces the settings for the specified plugin.
Parameters:
-
settingsObjectThe settings object to be validated and persisted
-
pluginNameObjectThe name of the plugin who's settings are being represented
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the settings were persisted successfully, FALSE if not.
setThemeSetting
-
name -
value -
pluginName -
cb
Replaces a single theme setting for the specified plugin
Parameters:
-
nameObjectThe name of the setting to change
-
valueObjectThe new value for the setting
-
pluginNameObjectThe plugin who's setting is being changed.
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the setting was persisted successfully, FALSE if not.
setThemeSettings
-
settings -
pluginName -
cb
Replaces the theme settings for the specified plugin.
Parameters:
-
settingsObjectThe settings object to be validated and persisted
-
pluginNameObjectThe uid of the plugin who's settings are being represented
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the settings were persisted successfully, FALSE if not.
syncSettings
-
plugin -
details -
cb
Compares the details loaded from the plugin config (details.json) with the database values pulled from getSettingsKV(). If a discrepancy is detected, the plugin settings are updated in the database so future calls to getSettingsKV() will have the latest values.
Parameters:
-
pluginObjectThe plugin object
-
detailsObjectThe details object to extract the settings from
-
cbObjectA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE/FALSE if an error occured.
uninstallPlugin
-
pluginUid -
[options] -
cb
Uninstalls the plugin with the specified UID.
Parameters:
-
pluginUidStringThe unique plugin identifier
-
[options]Object optional-
[jobId]String optionalRequired when uninstalling from the executing process instead of calling upon the cluster.
-
[forCluster=true]Boolean optionalWhen true or not provided the function instructs the cluster to uninstall the plugin. When explicitly FALSE the function installs the plugin from the executing process.
-
-
cbFunctionA callback that provides two parameters: cb(Error, Boolean)
validateDetails
-
details -
pluginDirName -
cb
Validates a plugin's details.json file.
Parameters:
-
detailsObjectThe details object to validate
-
[theme]Object optional -
permissionsObject -
uidString -
descriptionString -
versionString -
pb_versionString -
iconString -
[contributors]Array optional -
[author]Object optional -
[settings]Array optional
-
-
pluginDirNameStringThe name of the directory containing the original details.json file that the details object was derived from.
-
cbFunctionA callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the details object passes validation, FALSE if not.
validateIconPath
-
iconPath -
pluginDirName
Validates the path to the plugin's icon file. The path is considered valid if the path to a valid file. The path may be absolute or relative to the plugin's public directory.
Parameters:
-
iconPathObjectThe path to the icon (image) file
-
pluginDirNameObjectThe name of the directory housing the plugin
Returns:
TRUE if the path is valid, FALSE if not
validateMainModulePath
-
mmPath -
pluginDirName
Validates the path of a main module file. The path is considered valid if the path points to JS file. The path may be absolute or relative to the specific plugin directory.
Parameters:
-
mmPathObjectThe relative or absolute path to the main module file
-
pluginDirNameObjectThe name of the directory housing the plugin
Returns:
TRUE if the path is valid, FALSE if not
validateSetting
-
setting -
position
Validates a setting from a details.json file.
Parameters:
-
settingObjectThe setting to validate
-
positionObjectThe position in the settings array where the setting resides as a 0 based index.
Returns:
The array of errors that were generated. If no errors were produced an empty array is returned.
validateSettingValue
-
value
Validates a details.json file's setting value. The value is required to be a string or a number. Null, undefined, Arrays, Objects, and prototypes are NOT allowed.
Parameters:
-
valueBoolean | Integer | Number | StringThe value to validate
Returns:
TRUE if the value is valid, FALSE if not
Properties
ACTIVE_PLUGINS
Object
A hash of the plugins that are installed and active in this instance of PB.
DETAILS_FILE_NAME
String
The name of the file that defines the plugin's properties
GLOBAL_SITE
String
private
static
PLUGIN_INIT_CACHE;
Object
A hash of shared plugin information used during plugin initialization
PLUGINS_DIR
String
The absolute path to the plugins directory for this PecilBlue installation
pluginSettingsService
SimpleLayeredService
A setting service that sets and retrieves the settings for plugins
pluginSettingsService
SimpleLayeredService
A setting service that sets and retrieves the settings for plugins
PUBLIC_DIR_NAME
String
The name of the directory for each plugin that contains the public resources
