PluginService Class
PluginService - Provides functions for interacting with plugins. Install/uninstall, setting retrieval, plugin retrieval, etc.
Constructor
PluginService
-
options
Parameters:
-
options
Object-
[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:
-
pluginUid
String -
pluginSpec
Object-
main_module
Function -
public_dir
String -
permissions
Object -
templates
Array -
icon
String -
services
Object
-
-
site
String
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:
-
pluginUid
String -
site
String
Returns:
genPublicPath
-
plugin
-
relativePathToMedia
Generates a URL path to a public resource for a plugin.
Parameters:
-
plugin
StringThe UID of the plugin
-
relativePathToMedia
StringThe 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:
-
objType
ObjectThe type of object that will be dealt with. (plugin_settings, theme_settings)
-
useMemory
BooleanIndicates if the generated layered service should use an in memory service.
-
useCache
BooleanIndicates if the generated layered service should use a cache service.
-
serviceName
ObjectThe name of the service
-
site
String
Returns:
getActiveContentTemplates
-
targetSite
Retrieves the content templates for all of the active plugins
Parameters:
-
targetSite
Object
Returns:
An array of objects
getActiveIcon
-
cb
Retrieves the path to the active fav icon.
Parameters:
-
cb
FunctionA 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:
-
pluginUid
String -
site
String
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:
-
pluginUid
StringA 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:
-
cb
FunctionA 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:
-
active
ArrayAn array of plugin detail objects. Each object is required to have a uid property that is a string.
-
inactive
ArrayAn array of plugin details objects. Each object is required to have a uid property that is a string.
-
cb
FunctionA callback that provides two parameters: cb(Error, Array)
getDetailsPath
-
pluginDirName
Constructs the path to a specific plugin's details.json file
Parameters:
-
pluginDirName
StringThe 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:
-
cb
FunctionA 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:
-
pluginDirName
StringThe name of the plugin directory
-
cb
FunctionA 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:
-
role
Integer | StringThe role to get permissions for
Returns:
A hash of the permissions
getPlugin
-
pluginIdentifier
-
cb
Retrieves a plugin descriptor (plugin document)
Parameters:
-
pluginIdentifier
StringThe identifier can either be an ObjectID or the plugin name
-
cb
FunctionA callback that provides two parameters: cb(error, plugin). If the plugin does exist null is provided.
getPluginBySite
-
pluginIdentifier
-
cb
Parameters:
-
pluginIdentifier
String -
cb
Function
getPluginMap
-
cb
Retrieves a map of the system's plugin. The map provides three properties: active, inactive, available.
Parameters:
-
cb
FunctionA 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:
-
cb
FunctionProvides two parameters: Error, Array
getPluginsWithThemesBySite
-
cb
Get plugins that contain a theme on a site level.
Parameters:
-
cb
Function- callback function
getPublicPath
-
pluginDirName
Retrieves the absolute file path to a plugin's public directory
Parameters:
-
pluginDirName
ObjectThe 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:
-
serviceName
String -
pluginUid
StringThe unique plugin identifier
-
site
String
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:
-
serviceName
String -
pluginUid
StringThe 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:
-
pathToService
ObjectThe file path to the service
-
service
ObjectThe service prototype
Returns:
The derived service name
getServices
-
pathToPlugin
-
cb
Retrieves all services (initialized). The services are provided in the callback.
Parameters:
-
pathToPlugin
StringThe absolute file path to the specific plugin directory.
-
cb
FunctionA callback that provides two parameters: cb(error, servicesHash);
getSetting
-
settingName
-
pluginName
-
cb
Retrieves a single setting for the specified plugin.
Parameters:
-
settingName
StringThe name of the setting to retrieve
-
pluginName
StringThe name of the plugin who owns the setting
-
cb
FunctionA 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:
-
pluginName
ObjectThe name of the plugin who's settings are being requested
-
cb
ObjectA 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:
-
pluginName
StringThe unique ID of the plugin who settings are to be retrieved
-
cb
FunctionA 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:
-
settingName
ObjectThe uid of the setting
-
pluginName
ObjectThe plugin to retrieve the setting from
-
cb
ObjectA callback that provides two parameters: cb(error, settingValue)
getThemeSettings
-
pluginName
-
cb
Retrieves the theme settings for the specified plugin
Parameters:
-
pluginName
ObjectThe uid of the plugin
-
cb
ObjectA 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:
-
pluginName
Object -
cb
Object
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:
-
pluginName
StringThe unique ID of the plugin who settings are to be retrieved
-
cb
FunctionA 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:
-
plugin
Object -
cb
Function
init
()
static
initPlugin
-
plugin
-
cb
Initializes a plugin during startup or just after a plugin has been installed.
Parameters:
-
plugin
ObjectThe plugin details
-
cb
FunctionA callback that provides two parameters: cb(Error, Boolean)
initPlugins
-
cb
Attempts to initialize all installed plugins.
Parameters:
-
cb
FunctionA 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:
-
pluginDirName
StringThe 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:
-
pluginDirName
String -
dependencies
Object -
plugin
Object -
cb
Function
isActivePlugin
-
uid
-
site
Indicates if the specified plugin is active in this instance of PB.
Parameters:
-
uid
StringThe unique identifier for a plugin
-
site
String
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:
-
uid
StringThe unique identifier for a plugin
-
site
String
Returns:
TRUE if the plugin is active, FALSE if not
isInstalled
-
pluginIdentifier
-
cb
Indicates if a plugin by the specified identifier is installed.
Parameters:
-
pluginIdentifier
StringThe identifier can either be an ObjectID or the plugin name
-
cb
ObjectA 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:
-
pathToController
StringThe absolute file path to the controller
-
pluginUid
StringThe unique identifier for the plugin
-
site
String -
cb
FunctionA 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:
-
pathToPlugin
StringThe absolute file path to the plugin =
-
pluginUid
StringThe unique identifier for the plugin
-
site
String -
cb
FunctionA callback that provides two parameters: cb(Error, Array)
loadDetailsFile
-
filePath
-
cb
Attempts to load and parse the details.json file for a plugin.
Parameters:
-
filePath
StringThe absolute path to the details.json file
-
cb
FunctionA callback that provides two parameters: cb(error, detailsObject)
loadMainModule
-
pluginDirName
-
pathToModule
Attempts to require the main module file for a plugin.
Parameters:
-
pluginDirName
StringThe name of the directory that the plugin is contained within.
-
pathToModule
StringThe 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:
-
pathToService
StringThe absolute file path to the service javascript file.
-
cb
FunctionA 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:
-
command
Object-
jobId
StringThe 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:
-
command
Object-
jobId
StringThe 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:
-
command
Object-
jobId
StringThe 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:
-
command
Object-
jobId
StringThe 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:
-
pluginUid
String- the plugin unique id
-
cb
Function- callback function
purgeThemeSettings
-
pluginUid
-
cb
Deletes the theme settings for when plugin uninstalls.
Parameters:
-
pluginUid
String- the plugin unique id
-
cb
Function- callback function
require
-
pluginDirName
-
moduleName
Loads a module dependencies for the specified plugin.
Parameters:
-
pluginDirName
String -
moduleName
String
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:
-
details
ObjectThe details object to extract the settings from
-
cb
ObjectA 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:
-
details
ObjectThe details object to extract the settings from
-
cb
ObjectA 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:
-
details
ObjectThe details object to extract the settings from
-
cb
FunctionA 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:
-
details
ObjectThe details object to extract the settings from
-
cb
ObjectA 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:
-
name
ObjectThe name of the setting to change
-
value
ObjectThe new value for the setting
-
pluginName
ObjectThe plugin who's setting is being changed.
-
cb
ObjectA 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:
-
settings
ObjectThe settings object to be validated and persisted
-
pluginName
ObjectThe name of the plugin who's settings are being represented
-
cb
ObjectA 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:
-
name
ObjectThe name of the setting to change
-
value
ObjectThe new value for the setting
-
pluginName
ObjectThe plugin who's setting is being changed.
-
cb
ObjectA 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:
-
settings
ObjectThe settings object to be validated and persisted
-
pluginName
ObjectThe uid of the plugin who's settings are being represented
-
cb
ObjectA 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:
-
plugin
ObjectThe plugin object
-
details
ObjectThe details object to extract the settings from
-
cb
ObjectA 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:
-
pluginUid
StringThe 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.
-
-
cb
FunctionA callback that provides two parameters: cb(Error, Boolean)
validateDetails
-
details
-
pluginDirName
-
cb
Validates a plugin's details.json file.
Parameters:
-
details
ObjectThe details object to validate
-
[theme]
Object optional -
permissions
Object -
uid
String -
description
String -
version
String -
pb_version
String -
icon
String -
[contributors]
Array optional -
[author]
Object optional -
[settings]
Array optional
-
-
pluginDirName
StringThe name of the directory containing the original details.json file that the details object was derived from.
-
cb
FunctionA 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:
-
iconPath
ObjectThe path to the icon (image) file
-
pluginDirName
ObjectThe 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:
-
mmPath
ObjectThe relative or absolute path to the main module file
-
pluginDirName
ObjectThe 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:
-
setting
ObjectThe setting to validate
-
position
ObjectThe 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:
-
value
Boolean | 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