API Docs for: 0.8.0
Show:

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

Methods

activatePlugin

(
  • pluginUid
  • pluginSpec
  • site
)
Boolean static

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:

Boolean:

TRUE if the site is set as active and FALSE when the site is already active

deactivatePlugin

(
  • pluginUid
  • site
)
Boolean static

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:

Boolean:

genPublicPath

(
  • plugin
  • relativePathToMedia
)
String static

Generates a URL path to a public resource for a plugin.

Parameters:

  • plugin String

    The UID of the plugin

  • relativePathToMedia String

    The relative path to the resource from the plugin's public directory.

Returns:

String:

URL path to the resource

genSettingsService

(
  • objType
  • useMemory
  • useCache
  • serviceName
  • site
)
SimpleLayeredService static

Convenience function to generate a service to handle settings for a plugin.

Parameters:

  • objType Object

    The type of object that will be dealt with. (plugin_settings, theme_settings)

  • useMemory Boolean

    Indicates if the generated layered service should use an in memory service.

  • useCache Boolean

    Indicates if the generated layered service should use a cache service.

  • serviceName Object

    The name of the service

  • site String

getActiveContentTemplates

(
  • targetSite
)
Array static

Retrieves the content templates for all of the active plugins

Parameters:

  • targetSite Object

Returns:

Array:

An array of objects

getActiveIcon

(
  • cb
)

Retrieves the path to the active fav icon.

Parameters:

  • cb Function

    A callback that provides two parameters: cb(Error, URL_PATH_TO_ICON)

getActiveMainModule

(
  • pluginUid
  • site
)
Function static

Retrieves the main module prototype for the specified active plugin

Parameters:

  • pluginUid String
  • site String

Returns:

Function:

The prototype that is the plugin's main module.

getActivePluginDir

(
  • pluginUid
)
String static

Retrieves the file path to the public directory for the specified plugin.

Parameters:

  • pluginUid String

    A plugin's UID value

Returns:

String:

File path to the plugin's public directory

getActivePluginNames

() Array

Retrieves the names of the active plugins for this instance

Returns:

Array:

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 Function

    A 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:

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 Array

    An array of plugin detail objects. Each object is required to have a uid property that is a string.

  • inactive Array

    An array of plugin details objects. Each object is required to have a uid property that is a string.

  • cb Function

    A callback that provides two parameters: cb(Error, Array)

getDetailsPath

(
  • pluginDirName
)
String static

Constructs the path to a specific plugin's details.json file

Parameters:

  • pluginDirName String

    The name of the directory that the plugin is contained within.

Returns:

String:

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 Function

    A callback that provides two parameters: cb(Error, Array)

getLocalizations

(
  • pluginDirName
  • cb
)
deprecated

Defined in include/service/entities/plugin_service.js:1141

Deprecated: since 0.6.0

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 String

    The name of the plugin directory

  • cb Function

    A callback that provides two parameters: cb(Error, Object). When the directory does not exist NULL is returned as the result parameter.

getPermissionsForRole

(
  • role
)
Object static

Retrieves the permission set for a given role. All active plugins are inspected.

Parameters:

  • role Integer | String

    The role to get permissions for

Returns:

Object:

A hash of the permissions

getPlugin

(
  • pluginIdentifier
  • cb
)

Retrieves a plugin descriptor (plugin document)

Parameters:

  • pluginIdentifier String

    The identifier can either be an ObjectID or the plugin name

  • cb Function

    A 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 Function

    A callback that provides two parameters: cb(Error, Object)

getPluginsDir

() String static

Returns:

String:

The absolute file path to the plugins directory

getPluginsWithThemes

(
  • cb
)

Retrieves the plugins that have themes associated with them

Parameters:

  • cb Function

    Provides two parameters: Error, Array

getPluginsWithThemesBySite

(
  • cb
)

Get plugins that contain a theme on a site level.

Parameters:

  • cb Function
    • callback function

getPublicPath

(
  • pluginDirName
)
String static

Retrieves the absolute file path to a plugin's public directory

Parameters:

  • pluginDirName Object

    The name of the directory that contains the intended plugin

Returns:

String:

the absolute file path to a plugin's public directory

getService

(
  • serviceName
  • pluginUid
  • site
)
Object deprecated

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 String

    The unique plugin identifier

  • site String

Returns:

Object:

Service prototype

getService

(
  • serviceName
  • pluginUid
  • [site=global]
)
Object static

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 String

    The unique plugin identifier

  • [site=global] String optional
    • The site UID

Returns:

Object:

Service prototype

getServiceName

(
  • pathToService
  • service
)
String deprecated static

Defined in include/service/entities/plugin_service.js:1568

Deprecated: since 0.6.0

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 Object

    The file path to the service

  • service Object

    The service prototype

Returns:

String:

The derived service name

getServices

(
  • pathToPlugin
  • cb
)
deprecated static

Retrieves all services (initialized). The services are provided in the callback.

Parameters:

  • pathToPlugin String

    The absolute file path to the specific plugin directory.

  • cb Function

    A callback that provides two parameters: cb(error, servicesHash);

getSetting

(
  • settingName
  • pluginName
  • cb
)

Retrieves a single setting for the specified plugin.

Parameters:

  • settingName String

    The name of the setting to retrieve

  • pluginName String

    The name of the plugin who owns the setting

  • cb Function

    A 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 Object

    The name of the plugin who's settings are being requested

  • cb Object

    A 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 String

    The unique ID of the plugin who settings are to be retrieved

  • cb Function

    A 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 Object

    The uid of the setting

  • pluginName Object

    The plugin to retrieve the setting from

  • cb Object

    A callback that provides two parameters: cb(error, settingValue)

getThemeSettings

(
  • pluginName
  • cb
)

Retrieves the theme settings for the specified plugin

Parameters:

  • pluginName Object

    The uid of the plugin

  • cb Object

    A 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 String

    The unique ID of the plugin who settings are to be retrieved

  • cb Function

    A 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

initPlugin

(
  • plugin
  • cb
)

Initializes a plugin during startup or just after a plugin has been installed.

Parameters:

  • plugin Object

    The plugin details

  • cb Function

    A callback that provides two parameters: cb(Error, Boolean)

initPlugins

(
  • cb
)

Attempts to initialize all installed plugins.

Parameters:

  • cb Function

    A callback that provides two parameters: cb(Error, Boolean)

installPlugin

(
  • pluginDirName
  • [cb]
)
String

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:

  1. Load and parse the plugin's details.json file
  2. Pass validation
  3. Must not already be installed
  4. Successfully register itself with the system
  5. Successfully load any plugin settings
  6. Successfully load any theme settings
  7. Successfully execute the plugin's onInstall function
  8. Successfully initialize the plugin for runtime

Parameters:

  • pluginDirName String

    The name of the directory that contains the plugin and its details.json file.

  • [cb] Function optional

    A callback that provides two parameters: cb(err, TRUE/FALSE)

Returns:

String:

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
)
Boolean static

Indicates if the specified plugin is active in this instance of PB.

Parameters:

  • uid String

    The unique identifier for a plugin

  • site String

Returns:

Boolean:

TRUE if the plugin is active, FALSE if not

isActivePlugin

(
  • uid
  • site
)
Boolean static

Indicates if the specified plugin is active for a given site in this instance of PB.

Parameters:

  • uid String

    The unique identifier for a plugin

  • site String

Returns:

Boolean:

TRUE if the plugin is active, FALSE if not

isInstalled

(
  • pluginIdentifier
  • cb
)

Indicates if a plugin by the specified identifier is installed.

Parameters:

  • pluginIdentifier String

    The identifier can either be an ObjectID or the plugin name

  • cb Object

    A callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the plugin is installed, FALSE if not.

loadController

(
  • pathToController
  • pluginUid
  • site
  • cb
)
static

Loads a controller for a plugin and attempts to register the route with the RequestHandler.

Parameters:

  • pathToController String

    The absolute file path to the controller

  • pluginUid String

    The unique identifier for the plugin

  • site String
  • cb Function

    A callback that provides two parameters: cb(Error, Boolean)

loadControllers

(
  • pathToPlugin
  • pluginUid
  • site
  • cb
)
deprecated static

Loads the controllers for a plugin by iterating through the files in the plugin's controllers directory.

Parameters:

  • pathToPlugin String

    The absolute file path to the plugin =

  • pluginUid String

    The unique identifier for the plugin

  • site String
  • cb Function

    A callback that provides two parameters: cb(Error, Array)

loadDetailsFile

(
  • filePath
  • cb
)
static

Attempts to load and parse the details.json file for a plugin.

Parameters:

  • filePath String

    The absolute path to the details.json file

  • cb Function

    A callback that provides two parameters: cb(error, detailsObject)

loadMainModule

(
  • pluginDirName
  • pathToModule
)
Function static

Attempts to require the main module file for a plugin.

Parameters:

  • pluginDirName String

    The name of the directory that the plugin is contained within.

  • pathToModule String

    The 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:

Function:

The main-module prototype

loadService

(
  • pathToService
  • cb
)
deprecated static

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 String

    The absolute file path to the service javascript file.

  • cb Function

    A callback that provides two parameters: cb(error, initializedService)

onIsPluginAvailableCommandReceived

(
  • command
)
static

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 String

      The ID of the in-progress job that this process is intended to join.

onIsPluginAvailableCommandReceived

(
  • command
)
static

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 String

      The ID of the in-progress job that this process is intended to join.

onIsPluginAvailableCommandReceived

(
  • command
)
static

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 String

      The ID of the in-progress job that this process is intended to join.

onUninstallPluginCommandReceived

(
  • command
)
static

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 String

      The 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
)
deprecated static

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 Object

    The details object to extract the settings from

  • cb Object

    A 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 Object

    The details object to extract the settings from

  • cb Object

    A 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 Object

    The details object to extract the settings from

  • cb Function

    A 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 Object

    The details object to extract the settings from

  • cb Object

    A 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 Object

    The name of the setting to change

  • value Object

    The new value for the setting

  • pluginName Object

    The plugin who's setting is being changed.

  • cb Object

    A 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 Object

    The settings object to be validated and persisted

  • pluginName Object

    The name of the plugin who's settings are being represented

  • cb Object

    A 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 Object

    The name of the setting to change

  • value Object

    The new value for the setting

  • pluginName Object

    The plugin who's setting is being changed.

  • cb Object

    A 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 Object

    The settings object to be validated and persisted

  • pluginName Object

    The uid of the plugin who's settings are being represented

  • cb Object

    A 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 Object

    The plugin object

  • details Object

    The details object to extract the settings from

  • cb Object

    A 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 String

    The unique plugin identifier

  • [options] Object optional
    • [jobId] String optional

      Required when uninstalling from the executing process instead of calling upon the cluster.

    • [forCluster=true] Boolean optional

      When 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 Function

    A callback that provides two parameters: cb(Error, Boolean)

validateDetails

(
  • details
  • pluginDirName
  • cb
)
deprecated static

Validates a plugin's details.json file.

Parameters:

  • details Object

    The 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 String

    The name of the directory containing the original details.json file that the details object was derived from.

  • cb Function

    A callback that provides two parameters: cb(error, TRUE/FALSE). TRUE if the details object passes validation, FALSE if not.

validateIconPath

(
  • iconPath
  • pluginDirName
)
Boolean deprecated static

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 Object

    The path to the icon (image) file

  • pluginDirName Object

    The name of the directory housing the plugin

Returns:

Boolean:

TRUE if the path is valid, FALSE if not

validateMainModulePath

(
  • mmPath
  • pluginDirName
)
Boolean deprecated static

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 Object

    The relative or absolute path to the main module file

  • pluginDirName Object

    The name of the directory housing the plugin

Returns:

Boolean:

TRUE if the path is valid, FALSE if not

validateSetting

(
  • setting
  • position
)
Array deprecated

Validates a setting from a details.json file.

Parameters:

  • setting Object

    The setting to validate

  • position Object

    The position in the settings array where the setting resides as a 0 based index.

Returns:

Array:

The array of errors that were generated. If no errors were produced an empty array is returned.

validateSettingValue

(
  • value
)
Boolean deprecated static

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 | String

    The value to validate

Returns:

Boolean:

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

Provided by the Services module.

Defined in include/service/entities/plugin_service.js:30

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