updated rules
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file Extendable Object Faces API. Provided by the faces module.
|
||||
* @file
|
||||
* Extendable Object Faces API. Provided by the faces module.
|
||||
*/
|
||||
|
||||
if (!interface_exists('FacesExtenderInterface', FALSE)) {
|
||||
@@ -14,12 +15,13 @@ if (!interface_exists('FacesExtenderInterface', FALSE)) {
|
||||
/**
|
||||
* Constructs an instance of the extender.
|
||||
*/
|
||||
function __construct(FacesExtendable $object);
|
||||
public function __construct(FacesExtendable $object);
|
||||
|
||||
/**
|
||||
* Returns the extended object.
|
||||
*/
|
||||
public function getExtendable();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,9 +33,10 @@ if (!interface_exists('FacesExtenderInterface', FALSE)) {
|
||||
|
||||
if (!class_exists('FacesExtender', FALSE)) {
|
||||
/**
|
||||
* A common base class for FacesExtenders. Extenders may access protected
|
||||
* methods and properties of the extendable using the property() and call()
|
||||
* methods.
|
||||
* A common base class for FacesExtenders.
|
||||
*
|
||||
* Extenders may access protected methods and properties of the extendable
|
||||
* using the property() and call() methods.
|
||||
*/
|
||||
abstract class FacesExtender implements FacesExtenderInterface {
|
||||
|
||||
@@ -42,8 +45,7 @@ if (!class_exists('FacesExtender', FALSE)) {
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
|
||||
function __construct(FacesExtendable $object) {
|
||||
public function __construct(FacesExtendable $object) {
|
||||
$this->object = $object;
|
||||
}
|
||||
|
||||
@@ -63,17 +65,17 @@ if (!class_exists('FacesExtender', FALSE)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes any method on the extended object. May be used to invoke
|
||||
* protected methods.
|
||||
* Invokes any method on the extended object, including protected methods.
|
||||
*
|
||||
* @param $name
|
||||
* @param string $name
|
||||
* The method name.
|
||||
* @param $arguments
|
||||
* @param array $args
|
||||
* An array of arguments to pass to the method.
|
||||
*/
|
||||
protected function call($name, array $args = array()) {
|
||||
return $this->object->call($name, $args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +110,7 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
/**
|
||||
* Magic method: Invoke the dynamically implemented methods.
|
||||
*/
|
||||
function __call($name, $arguments = array()) {
|
||||
public function __call($name, $arguments = array()) {
|
||||
if (isset($this->facesMethods[$name])) {
|
||||
$method = $this->facesMethods[$name];
|
||||
// Include code, if necessary.
|
||||
@@ -134,9 +136,11 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extender object for the given class. May be used to
|
||||
* explicitly invoke a specific extender, e.g. a function overriding a
|
||||
* method may use that to explicitly invoke the original extender.
|
||||
* Returns the extender object for the given class.
|
||||
*
|
||||
* May be used to explicitly invoke a specific extender, e.g. a function
|
||||
* overriding a method may use that to explicitly invoke the original
|
||||
* extender.
|
||||
*/
|
||||
public function extender($class) {
|
||||
if (!isset($this->facesClassInstances[$class])) {
|
||||
@@ -146,14 +150,17 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the object can face as the given interface.
|
||||
*
|
||||
* Returns whether the object can face as the given interface, thus it
|
||||
* returns TRUE if this oject has been extended by an appropriate
|
||||
* returns TRUE if this object has been extended by an appropriate
|
||||
* implementation.
|
||||
*
|
||||
* @param $interface
|
||||
* Optional. A interface to test for. If it's omitted, all interfaces that
|
||||
* the object can be faced as are returned.
|
||||
* @return
|
||||
* Optional. An interface to test for. If it's omitted, all interfaces
|
||||
* that the object can be faced as are returned.
|
||||
*
|
||||
* @return bool
|
||||
* Whether the object can face as the interface or an array of interface
|
||||
* names.
|
||||
*/
|
||||
@@ -169,9 +176,9 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
*
|
||||
* @param $interface
|
||||
* The interface name or an array of interface names.
|
||||
* @param $class
|
||||
* @param $className
|
||||
* The extender class, which has to implement the FacesExtenderInterface.
|
||||
* @param $include
|
||||
* @param array $includes
|
||||
* An optional array describing the file to include before invoking the
|
||||
* class. The array entries known are 'type', 'module', and 'name'
|
||||
* matching the parameters of module_load_include(). Only 'module' is
|
||||
@@ -206,10 +213,10 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
* @param $interface
|
||||
* The interface name or FALSE to extend the object without a given
|
||||
* interface.
|
||||
* @param $methods
|
||||
* @param array $callbacks
|
||||
* An array, where the keys are methods of the given interface and the
|
||||
* values the callback functions to use.
|
||||
* @param $includes
|
||||
* @param array $includes
|
||||
* An optional array to describe files to include before invoking the
|
||||
* callbacks. You may pass a single array describing one include for all
|
||||
* callbacks or an array of arrays, keyed by the method names. Look at the
|
||||
@@ -234,11 +241,11 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
/**
|
||||
* Override the implementation of an extended method.
|
||||
*
|
||||
* @param $methods
|
||||
* An array of methods of the interface, that should be overriden, where
|
||||
* @param array $callbacks
|
||||
* An array of methods of the interface, that should be overridden, where
|
||||
* the keys are methods to override and the values the callback functions
|
||||
* to use.
|
||||
* @param $includes
|
||||
* @param array $includes
|
||||
* An optional array to describe files to include before invoking the
|
||||
* callbacks. You may pass a single array describing one include for all
|
||||
* callbacks or an array of arrays, keyed by the method names. Look at the
|
||||
@@ -257,6 +264,7 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
|
||||
/**
|
||||
* Adds in include files for the given methods while removing any old files.
|
||||
*
|
||||
* If a single include file is described, it's added for all methods.
|
||||
*/
|
||||
protected function addIncludes($methods, $includes) {
|
||||
@@ -272,6 +280,8 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys all references to created instances.
|
||||
*
|
||||
* Destroys all references to created instances so that PHP's garbage
|
||||
* collection can do its work. This is needed as PHP's gc has troubles with
|
||||
* circular references until PHP < 5.3.
|
||||
@@ -296,9 +306,9 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
* This also allows to pass arguments by reference, so it may be used to
|
||||
* pass arguments by reference to dynamically extended methods.
|
||||
*
|
||||
* @param $name
|
||||
* @param string $name
|
||||
* The method name.
|
||||
* @param $arguments
|
||||
* @param array $args
|
||||
* An array of arguments to pass to the method.
|
||||
*/
|
||||
public function call($name, array $args = array()) {
|
||||
@@ -307,5 +317,7 @@ if (!class_exists('FacesExtendable', FALSE)) {
|
||||
}
|
||||
return $this->__call($name, $args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
421
sites/all/modules/rules/includes/rules.event.inc
Normal file
421
sites/all/modules/rules/includes/rules.event.inc
Normal file
@@ -0,0 +1,421 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains event handler interface and base classes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for handling rules events.
|
||||
*
|
||||
* Configurable events (i.e. events making use of settings) have a custom
|
||||
* event suffix, which gets appended to the base event name. The configured
|
||||
* event name of, e.g. the event for viewing an article node, would be
|
||||
* node_view--article, whereas "node_view" is the base event name and "article"
|
||||
* the event suffix as returned from
|
||||
* RulesEventHandlerInterface::getEventNameSuffix(). The event suffix is
|
||||
* generated based upon the event settings and must map to this settings, i.e.
|
||||
* each set of event settings must always generate the same suffix.
|
||||
* For a configurable event to be invoked, rules_invoke_event() has to be called
|
||||
* with the configured event name, e.g.
|
||||
* @code
|
||||
* rules_invoke_event('node_view--' . $node->type, $node, $view_mode);
|
||||
* @endcode
|
||||
* If the event settings are optional, both events have to be invoked whereas
|
||||
* usually the more general event is invoked last. E.g.:
|
||||
* @code
|
||||
* rules_invoke_event('node_view--' . $node->type, $node, $view_mode);
|
||||
* rules_invoke_event('node_view', $node, $view_mode);
|
||||
* @endcode
|
||||
*
|
||||
* Rules event handlers have to be declared using the 'class' key in
|
||||
* hook_rules_event_info(), or may be discovered automatically, see
|
||||
* rules_discover_plugins() for details.
|
||||
*
|
||||
* @see RulesEventHandlerBase
|
||||
* @see RulesEventDefaultHandler
|
||||
*/
|
||||
interface RulesEventHandlerInterface {
|
||||
|
||||
/**
|
||||
* Constructs the event handler.
|
||||
*
|
||||
* @param string $event_name
|
||||
* The base event string.
|
||||
* @param array $info
|
||||
* The event info of the given event.
|
||||
*/
|
||||
public function __construct($event_name, $info);
|
||||
|
||||
/**
|
||||
* Sets the event settings.
|
||||
*
|
||||
* @param array $settings
|
||||
* An array of settings to set.
|
||||
*
|
||||
* @return RulesEventHandlerInterface
|
||||
* The handler itself for chaining.
|
||||
*/
|
||||
public function setSettings(array $settings);
|
||||
|
||||
/**
|
||||
* Gets the event settings.
|
||||
*
|
||||
* @return array
|
||||
* The array of settings.
|
||||
*/
|
||||
public function getSettings();
|
||||
|
||||
/**
|
||||
* Returns an array of default settings.
|
||||
*
|
||||
* @return array
|
||||
* The array of default settings.
|
||||
*/
|
||||
public function getDefaults();
|
||||
|
||||
/**
|
||||
* Returns a user-facing summary of the settings.
|
||||
*
|
||||
* @return string
|
||||
* The summary in HTML, i.e. properly escaped or filtered.
|
||||
*/
|
||||
public function summary();
|
||||
|
||||
/**
|
||||
* Builds the event settings form.
|
||||
*
|
||||
* @param array $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* The form structure.
|
||||
*/
|
||||
public function buildForm(array &$form_state);
|
||||
|
||||
/**
|
||||
* Validate the event settings independent from a form submission.
|
||||
*
|
||||
* @throws RulesIntegrityException
|
||||
* In case of validation errors, RulesIntegrityExceptions are thrown.
|
||||
*/
|
||||
public function validate();
|
||||
|
||||
/**
|
||||
* Extract the form values and update the event settings.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param array $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
*/
|
||||
public function extractFormValues(array &$form, array &$form_state);
|
||||
|
||||
/**
|
||||
* Returns the suffix to be added to the base event named based upon settings.
|
||||
*
|
||||
* If event settings are used, the event name Rules uses for the configured
|
||||
* event is {EVENT_NAME}--{SUFFIX}.
|
||||
*
|
||||
* @return string
|
||||
* The suffix string. Return an empty string for not appending a suffix.
|
||||
*/
|
||||
public function getEventNameSuffix();
|
||||
|
||||
/**
|
||||
* Returns info about the variables provided by this event.
|
||||
*
|
||||
* @return array
|
||||
* An array of provided variables, keyed by variable names and with the
|
||||
* variable info array as value.
|
||||
*/
|
||||
public function availableVariables();
|
||||
|
||||
/**
|
||||
* Returns the base name of the event the event handler belongs to.
|
||||
*
|
||||
* @return string
|
||||
* The name of the event the event handler belongs to.
|
||||
*/
|
||||
public function getEventName();
|
||||
|
||||
/**
|
||||
* Returns the info array of the event the event handler belongs to.
|
||||
*
|
||||
* @return string
|
||||
* The info array of the event the event handler belongs to.
|
||||
*/
|
||||
public function getEventInfo();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for event dispatchers.
|
||||
*/
|
||||
interface RulesEventDispatcherInterface extends RulesEventHandlerInterface {
|
||||
|
||||
/**
|
||||
* Starts the event watcher.
|
||||
*/
|
||||
public function startWatching();
|
||||
|
||||
/**
|
||||
* Stops the event watcher.
|
||||
*/
|
||||
public function stopWatching();
|
||||
|
||||
/**
|
||||
* Returns whether the event dispatcher is currently active.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the event dispatcher is currently active, FALSE otherwise.
|
||||
*/
|
||||
public function isWatching();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for event handler.
|
||||
*/
|
||||
abstract class RulesEventHandlerBase implements RulesEventHandlerInterface {
|
||||
|
||||
/**
|
||||
* The event name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eventName;
|
||||
|
||||
/**
|
||||
* The event info.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $eventInfo;
|
||||
|
||||
/**
|
||||
* The event settings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $settings = array();
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::__construct().
|
||||
*/
|
||||
public function __construct($event_name, $info) {
|
||||
$this->eventName = $event_name;
|
||||
$this->eventInfo = $info;
|
||||
$this->settings = $this->getDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getSettings().
|
||||
*/
|
||||
public function getSettings() {
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::setSettings().
|
||||
*/
|
||||
public function setSettings(array $settings) {
|
||||
$this->settings = $settings + $this->getDefaults();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::validate().
|
||||
*/
|
||||
public function validate() {
|
||||
// Nothing to check by default.
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::extractFormValues().
|
||||
*/
|
||||
public function extractFormValues(array &$form, array &$form_state) {
|
||||
foreach ($this->getDefaults() as $key => $setting) {
|
||||
$this->settings[$key] = isset($form_state['values'][$key]) ? $form_state['values'][$key] : $setting;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::availableVariables().
|
||||
*/
|
||||
public function availableVariables() {
|
||||
return isset($this->eventInfo['variables']) ? $this->eventInfo['variables'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getEventName().
|
||||
*/
|
||||
public function getEventName() {
|
||||
return $this->eventName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getEventInfo().
|
||||
*/
|
||||
public function getEventInfo() {
|
||||
return $this->eventInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A handler for events having no settings. This is the default handler.
|
||||
*/
|
||||
class RulesEventDefaultHandler extends RulesEventHandlerBase {
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::buildForm().
|
||||
*/
|
||||
public function buildForm(array &$form_state) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getConfiguredEventName().
|
||||
*/
|
||||
public function getEventNameSuffix() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::summary().
|
||||
*/
|
||||
public function summary() {
|
||||
return check_plain($this->eventInfo['label']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getDefaults().
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getSettings().
|
||||
*/
|
||||
public function getSettings() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposes the bundle of an entity as event setting.
|
||||
*/
|
||||
class RulesEventHandlerEntityBundle extends RulesEventHandlerBase {
|
||||
|
||||
protected $entityType;
|
||||
protected $entityInfo;
|
||||
protected $bundleKey;
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::__construct().
|
||||
*/
|
||||
public function __construct($event_name, $info) {
|
||||
parent::__construct($event_name, $info);
|
||||
// Cut off the suffix, e.g. remove 'view' from node_view.
|
||||
$this->entityType = implode('_', explode('_', $event_name, -1));
|
||||
$this->entityInfo = entity_get_info($this->entityType);
|
||||
if (!$this->entityInfo) {
|
||||
throw new InvalidArgumentException('Unsupported event name passed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::summary().
|
||||
*/
|
||||
public function summary() {
|
||||
$bundle = &$this->settings['bundle'];
|
||||
$bundle_label = isset($this->entityInfo['bundles'][$bundle]['label']) ? $this->entityInfo['bundles'][$bundle]['label'] : $bundle;
|
||||
$suffix = isset($bundle) ? ' ' . t('of @bundle-key %name', array('@bundle-key' => $this->getBundlePropertyLabel(), '%name' => $bundle_label)) : '';
|
||||
return check_plain($this->eventInfo['label']) . $suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::buildForm().
|
||||
*/
|
||||
public function buildForm(array &$form_state) {
|
||||
$form['bundle'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Restrict by @bundle', array('@bundle' => $this->getBundlePropertyLabel())),
|
||||
'#description' => t('If you need to filter for multiple values, either add multiple events or use the "Entity is of bundle" condition instead.'),
|
||||
'#default_value' => $this->settings['bundle'],
|
||||
'#empty_value' => '',
|
||||
'#options' => array(),
|
||||
);
|
||||
foreach ($this->entityInfo['bundles'] as $name => $bundle_info) {
|
||||
$form['bundle']['#options'][$name] = $bundle_info['label'];
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label to use for the bundle property.
|
||||
*
|
||||
* @return string
|
||||
* The label to use for the bundle property.
|
||||
*/
|
||||
protected function getBundlePropertyLabel() {
|
||||
return $this->entityInfo['entity keys']['bundle'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::extractFormValues().
|
||||
*/
|
||||
public function extractFormValues(array &$form, array &$form_state) {
|
||||
$this->settings['bundle'] = !empty($form_state['values']['bundle']) ? $form_state['values']['bundle'] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::validate().
|
||||
*/
|
||||
public function validate() {
|
||||
if ($this->settings['bundle'] && empty($this->entityInfo['bundles'][$this->settings['bundle']])) {
|
||||
throw new RulesIntegrityException(t('The @bundle %bundle of %entity_type is not known.',
|
||||
array(
|
||||
'%bundle' => $this->settings['bundle'],
|
||||
'%entity_type' => $this->entityInfo['label'],
|
||||
'@bundle' => $this->getBundlePropertyLabel(),
|
||||
)), array(NULL, 'bundle'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getConfiguredEventName().
|
||||
*/
|
||||
public function getEventNameSuffix() {
|
||||
return $this->settings['bundle'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::getDefaults().
|
||||
*/
|
||||
public function getDefaults() {
|
||||
return array(
|
||||
'bundle' => NULL,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesEventHandlerInterface::availableVariables().
|
||||
*/
|
||||
public function availableVariables() {
|
||||
$variables = $this->eventInfo['variables'];
|
||||
if ($this->settings['bundle']) {
|
||||
// Add the bundle to all variables of the entity type.
|
||||
foreach ($variables as $name => $variable_info) {
|
||||
if ($variable_info['type'] == $this->entityType) {
|
||||
$variables[$name]['bundle'] = $this->settings['bundle'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $variables;
|
||||
}
|
||||
|
||||
}
|
@@ -1,15 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file Contains plugin info and implementations not needed for rule evaluation.
|
||||
* @file
|
||||
* Contains plugin info and implementations not needed for rule evaluation.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements a rules action.
|
||||
*/
|
||||
class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'action';
|
||||
|
||||
/**
|
||||
@@ -69,6 +72,7 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +80,14 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
|
||||
*/
|
||||
class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'condition';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $negate = FALSE;
|
||||
|
||||
public function providesVariables() {
|
||||
@@ -132,19 +143,28 @@ class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterf
|
||||
|
||||
public function label() {
|
||||
$label = parent::label();
|
||||
return $this->negate ? t('NOT @condition', array('@condition' => $label)) : $label;
|
||||
return $this->negate ? t('NOT !condition', array('!condition' => $label)) : $label;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An actual rule.
|
||||
*
|
||||
* Note: A rule also implements the RulesActionInterface (inherited).
|
||||
*/
|
||||
class Rule extends RulesActionContainer {
|
||||
|
||||
protected $conditions = NULL;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'rule';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $label = 'unlabeled';
|
||||
|
||||
public function __construct($variables = array(), $providesVars = array()) {
|
||||
@@ -159,8 +179,9 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator over all contained conditions. Note that this iterator also
|
||||
* implements the ArrayAcces interface.
|
||||
* Gets an iterator over all contained conditions.
|
||||
*
|
||||
* Note that this iterator also implements the ArrayAccess interface.
|
||||
*
|
||||
* @return RulesRecursiveElementIterator
|
||||
*/
|
||||
@@ -183,8 +204,9 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator over all contained actions. Note that this iterator also
|
||||
* implements the ArrayAcces interface.
|
||||
* Gets an iterator over all contained actions.
|
||||
*
|
||||
* Note that this iterator also implements the ArrayAccess interface.
|
||||
*
|
||||
* @return RulesRecursiveElementIterator
|
||||
*/
|
||||
@@ -193,11 +215,12 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a condition. Pass either an instance of the RulesConditionInterface
|
||||
* or the arguments as needed by rules_condition().
|
||||
* Adds a condition.
|
||||
*
|
||||
* @return Rule
|
||||
* Returns $this to support chained usage.
|
||||
* Pass either an instance of the RulesConditionInterface or the arguments as
|
||||
* needed by rules_condition().
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function condition($name, $settings = array()) {
|
||||
$this->conditions->condition($name, $settings);
|
||||
@@ -309,7 +332,9 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rules may not provided any variable info assertions, as Rules are only
|
||||
* Overrides RulesPlugin::variableInfoAssertions().
|
||||
*
|
||||
* Rules may not provide any variable info assertions, as Rules are only
|
||||
* conditionally executed.
|
||||
*/
|
||||
protected function variableInfoAssertions() {
|
||||
@@ -324,7 +349,7 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to expose the variables of all actions for embedded rules.
|
||||
* Overridden to expose the variables of all actions for embedded rules.
|
||||
*/
|
||||
public function providesVariables() {
|
||||
$provides = parent::providesVariables();
|
||||
@@ -340,6 +365,7 @@ class Rule extends RulesActionContainer {
|
||||
parent::resetInternalCache();
|
||||
$this->conditions->resetInternalCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,22 +373,30 @@ class Rule extends RulesActionContainer {
|
||||
*/
|
||||
class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'reaction rule';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $events = array();
|
||||
|
||||
/**
|
||||
* Returns the array of events associated with that Rule.
|
||||
* @var array
|
||||
*/
|
||||
public function &events() {
|
||||
protected $eventSettings = array();
|
||||
|
||||
/**
|
||||
* Implements RulesTriggerableInterface::events().
|
||||
*/
|
||||
public function events() {
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event from the rule configuration.
|
||||
*
|
||||
* @param $event
|
||||
* The name of the event to remove.
|
||||
* @return RulesReactionRule
|
||||
* Implements RulesTriggerableInterface::removeEvent().
|
||||
*/
|
||||
public function removeEvent($event) {
|
||||
if (($id = array_search($event, $this->events)) !== FALSE) {
|
||||
@@ -372,10 +406,43 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RulesReactionRule
|
||||
* Implements RulesTriggerableInterface::event().
|
||||
*/
|
||||
public function event($event) {
|
||||
$this->events[] = $event;
|
||||
public function event($event_name, array $settings = NULL) {
|
||||
// Process any settings and determine the configured event's name.
|
||||
if ($settings) {
|
||||
$handler = rules_get_event_handler($event_name, $settings);
|
||||
if ($suffix = $handler->getEventNameSuffix()) {
|
||||
$event_name .= '--' . $suffix;
|
||||
$this->eventSettings[$event_name] = $settings;
|
||||
}
|
||||
else {
|
||||
// Do not store settings if there is no suffix.
|
||||
unset($this->eventSettings[$event_name]);
|
||||
}
|
||||
}
|
||||
if (array_search($event_name, $this->events) === FALSE) {
|
||||
$this->events[] = $event_name;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RulesTriggerableInterface::getEventSettings().
|
||||
*/
|
||||
public function getEventSettings($event_name) {
|
||||
if (isset($this->eventSettings[$event_name])) {
|
||||
return $this->eventSettings[$event_name];
|
||||
}
|
||||
}
|
||||
|
||||
public function integrityCheck() {
|
||||
parent::integrityCheck();
|
||||
// Check integrity of the configured events.
|
||||
foreach ($this->events as $event_name) {
|
||||
$handler = rules_get_event_handler($event_name, $this->getEventSettings($event_name));
|
||||
$handler->validate();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -394,9 +461,9 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
}
|
||||
|
||||
public function access() {
|
||||
$event_info = rules_fetch_data('event_info');
|
||||
foreach ($this->events as $event) {
|
||||
if (!empty($event_info[$event]['access callback']) && !call_user_func($event_info[$event]['access callback'], 'event', $event)) {
|
||||
foreach ($this->events as $event_name) {
|
||||
$event_info = rules_get_event_info($event_name);
|
||||
if (!empty($event_info['access callback']) && !call_user_func($event_info['access callback'], 'event', $event_info['name'])) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -405,10 +472,10 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
|
||||
public function dependencies() {
|
||||
$modules = array_flip(parent::dependencies());
|
||||
$event_info = rules_fetch_data('event_info');
|
||||
foreach ($this->events as $event) {
|
||||
if (isset($event_info[$event]['module'])) {
|
||||
$modules[$event_info[$event]['module']] = TRUE;
|
||||
foreach ($this->events as $event_name) {
|
||||
$event_info = rules_get_event_info($event_name);
|
||||
if (isset($event_info['module'])) {
|
||||
$modules[$event_info['module']] = TRUE;
|
||||
}
|
||||
}
|
||||
return array_keys($modules);
|
||||
@@ -433,15 +500,20 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
else {
|
||||
// The intersection of the variables provided by the events are
|
||||
// available.
|
||||
$event_info = rules_fetch_data('event_info');
|
||||
$events = array_intersect($this->events, array_keys($event_info));
|
||||
foreach ($events as $event) {
|
||||
$event_info[$event] += array('variables' => array());
|
||||
foreach ($this->events as $event_name) {
|
||||
$handler = rules_get_event_handler($event_name, $this->getEventSettings($event_name));
|
||||
|
||||
if (isset($this->availableVariables)) {
|
||||
$this->availableVariables = array_intersect_key($this->availableVariables, $event_info[$event]['variables']);
|
||||
$event_vars = $handler->availableVariables();
|
||||
// Merge variable info by intersecting the variable-info keys also,
|
||||
// so we have only metadata available that is valid for all of the
|
||||
// provided variables.
|
||||
foreach (array_intersect_key($this->availableVariables, $event_vars) as $name => $variable_info) {
|
||||
$this->availableVariables[$name] = array_intersect_key($variable_info, $event_vars[$name]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->availableVariables = $event_info[$event]['variables'];
|
||||
$this->availableVariables = $handler->availableVariables();
|
||||
}
|
||||
}
|
||||
$this->availableVariables = isset($this->availableVariables) ? RulesState::defaultVariables() + $this->availableVariables : RulesState::defaultVariables();
|
||||
@@ -451,18 +523,38 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
}
|
||||
|
||||
public function __sleep() {
|
||||
return parent::__sleep() + drupal_map_assoc(array('events'));
|
||||
return parent::__sleep() + drupal_map_assoc(array('events', 'eventSettings'));
|
||||
}
|
||||
|
||||
protected function exportChildren($key = 'ON') {
|
||||
$export[$key] = array_values($this->events);
|
||||
foreach ($this->events as $event_name) {
|
||||
$export[$key][$event_name] = (array) $this->getEventSettings($event_name);
|
||||
}
|
||||
return $export + parent::exportChildren();
|
||||
}
|
||||
|
||||
protected function importChildren($export, $key = 'ON') {
|
||||
$this->events = $export[$key];
|
||||
// Detect and support old-style exports: a numerically indexed array of
|
||||
// event names.
|
||||
if (is_string(reset($export[$key])) && is_numeric(key($export[$key]))) {
|
||||
$this->events = $export[$key];
|
||||
}
|
||||
else {
|
||||
$this->events = array_keys($export[$key]);
|
||||
$this->eventSettings = array_filter($export[$key]);
|
||||
}
|
||||
parent::importChildren($export);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides optimize().
|
||||
*/
|
||||
public function optimize() {
|
||||
parent::optimize();
|
||||
// No need to keep event settings for evaluation.
|
||||
$this->eventSettings = array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,6 +562,9 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
*/
|
||||
class RulesAnd extends RulesConditionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'and';
|
||||
|
||||
public function evaluate(RulesState $state) {
|
||||
@@ -486,6 +581,7 @@ class RulesAnd extends RulesConditionContainer {
|
||||
public function label() {
|
||||
return !empty($this->label) ? $this->label : ($this->negate ? t('NOT AND') : t('AND'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,6 +589,9 @@ class RulesAnd extends RulesConditionContainer {
|
||||
*/
|
||||
class RulesOr extends RulesConditionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'or';
|
||||
|
||||
public function evaluate(RulesState $state) {
|
||||
@@ -511,6 +610,8 @@ class RulesOr extends RulesConditionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides RulesContainerPlugin::stateVariables().
|
||||
*
|
||||
* Overridden to exclude all variable assertions as in an OR we cannot assert
|
||||
* the children are successfully evaluated.
|
||||
*/
|
||||
@@ -527,6 +628,7 @@ class RulesOr extends RulesConditionContainer {
|
||||
}
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -534,6 +636,9 @@ class RulesOr extends RulesConditionContainer {
|
||||
*/
|
||||
class RulesLoop extends RulesActionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'loop';
|
||||
protected $listItemInfo;
|
||||
|
||||
@@ -640,6 +745,7 @@ class RulesLoop extends RulesActionContainer {
|
||||
$this->settings['item:label'] = reset($export['ITEM']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -647,6 +753,9 @@ class RulesLoop extends RulesActionContainer {
|
||||
*/
|
||||
class RulesActionSet extends RulesActionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'action set';
|
||||
|
||||
}
|
||||
@@ -656,6 +765,9 @@ class RulesActionSet extends RulesActionContainer {
|
||||
*/
|
||||
class RulesRuleSet extends RulesActionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'rule set';
|
||||
|
||||
/**
|
||||
@@ -672,6 +784,7 @@ class RulesRuleSet extends RulesActionContainer {
|
||||
protected function importChildren($export, $key = 'RULES') {
|
||||
parent::importChildren($export, $key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -679,8 +792,16 @@ class RulesRuleSet extends RulesActionContainer {
|
||||
*/
|
||||
class RulesEventSet extends RulesRuleSet {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'event set';
|
||||
// Event sets may recurse as we block recursions on rule-level.
|
||||
|
||||
/**
|
||||
* Event sets may recurse as we block recursions on rule-level.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $recursion = TRUE;
|
||||
|
||||
public function __construct($info = array()) {
|
||||
@@ -698,7 +819,10 @@ class RulesEventSet extends RulesRuleSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache event-sets per event to allow efficient usage via rules_invoke_event().
|
||||
* Rebuilds the event cache.
|
||||
*
|
||||
* We cache event-sets per event in order to allow efficient usage via
|
||||
* rules_invoke_event().
|
||||
*
|
||||
* @see rules_get_cache()
|
||||
* @see rules_invoke_event()
|
||||
@@ -711,18 +835,27 @@ class RulesEventSet extends RulesRuleSet {
|
||||
$rules = rules_config_load_multiple(FALSE, array('plugin' => 'reaction rule', 'active' => TRUE));
|
||||
|
||||
foreach ($rules as $name => $rule) {
|
||||
foreach ($rule->events() as $event) {
|
||||
foreach ($rule->events() as $event_name) {
|
||||
$event_base_name = rules_get_event_base_name($event_name);
|
||||
// Skip not defined events.
|
||||
if (empty($events[$event])) {
|
||||
if (empty($events[$event_base_name])) {
|
||||
continue;
|
||||
}
|
||||
// Create an event set if not yet done.
|
||||
if (!isset($sets[$event])) {
|
||||
$event_info = $events[$event] + array(
|
||||
'variables' => isset($events[$event]['arguments']) ? $events[$event]['arguments'] : array(),
|
||||
);
|
||||
$sets[$event] = new RulesEventSet($event_info);
|
||||
$sets[$event]->name = $event;
|
||||
if (!isset($sets[$event_name])) {
|
||||
$handler = rules_get_event_handler($event_name, $rule->getEventSettings($event_name));
|
||||
|
||||
// Start the event dispatcher for this event, if any.
|
||||
if ($handler instanceof RulesEventDispatcherInterface && !$handler->isWatching()) {
|
||||
$handler->startWatching();
|
||||
}
|
||||
|
||||
// Update the event info with the variables available based on the
|
||||
// event settings.
|
||||
$event_info = $events[$event_base_name];
|
||||
$event_info['variables'] = $handler->availableVariables();
|
||||
$sets[$event_name] = new RulesEventSet($event_info);
|
||||
$sets[$event_name]->name = $event_name;
|
||||
}
|
||||
|
||||
// If a rule is marked as dirty, check if this still applies.
|
||||
@@ -732,23 +865,22 @@ class RulesEventSet extends RulesRuleSet {
|
||||
if (!$rule->dirty) {
|
||||
// Clone the rule to avoid modules getting the changed version from
|
||||
// the static cache.
|
||||
$sets[$event]->rule(clone $rule);
|
||||
$sets[$event_name]->rule(clone $rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create cache items for all created sets.
|
||||
foreach ($sets as $event => $set) {
|
||||
foreach ($sets as $event_name => $set) {
|
||||
$set->sortChildren();
|
||||
$set->optimize();
|
||||
// Allow modules to alter the cached event set.
|
||||
drupal_alter('rules_event_set', $event, $set);
|
||||
rules_set_cache('event_' . $event, $set);
|
||||
drupal_alter('rules_event_set', $event_name, $set);
|
||||
rules_set_cache('event_' . $event_name, $set);
|
||||
}
|
||||
// Cache a list of empty sets so we can use it to speed up later calls.
|
||||
// See rules_get_event_set().
|
||||
$empty_events = array_keys(array_diff_key($events, $sets));
|
||||
variable_set('rules_empty_sets', array_flip($empty_events));
|
||||
// Cache a whitelist of configured events so we can use it to speed up later
|
||||
// calls. See rules_invoke_event().
|
||||
rules_set_cache('rules_event_whitelist', array_flip(array_keys($sets)));
|
||||
}
|
||||
|
||||
protected function stateVariables($element = NULL) {
|
||||
@@ -763,4 +895,5 @@ class RulesEventSet extends RulesRuleSet {
|
||||
public function save($name = NULL, $module = 'rules') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file Contains classes for data processing.
|
||||
* @file
|
||||
* Contains classes for data processing.
|
||||
*
|
||||
* Data processors can be used to process element arguments on evaluation time,
|
||||
* e.g. to apply input evaluators or to apply simple calculations to number
|
||||
@@ -39,25 +40,28 @@ abstract class RulesDataProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current user has permission to edit this chain of data
|
||||
* processors.
|
||||
* Determines whether the current user has permission to edit this chain of
|
||||
* data processors.
|
||||
*
|
||||
* @return bool
|
||||
* Whether the current user has permission to edit this chain of data
|
||||
* processors.
|
||||
*/
|
||||
public function editAccess() {
|
||||
return $this->access() && (!isset($this->processor) || $this->processor->editAccess());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the processor for parameters.
|
||||
*
|
||||
* It turns the settings into a suiting processor object, which gets invoked
|
||||
* It turns the settings into a suitable processor object, which gets invoked
|
||||
* on evaluation time.
|
||||
*
|
||||
* @param $setting
|
||||
* The processor settings which are to be prepared.
|
||||
* @param $param_info
|
||||
* The info about the parameter to prepare the processor for.
|
||||
* @param $var_info
|
||||
* @param array $var_info
|
||||
* An array of info about the available variables.
|
||||
*/
|
||||
public static function prepareSetting(&$setting, $param_info, $var_info = array()) {
|
||||
@@ -88,17 +92,22 @@ abstract class RulesDataProcessor {
|
||||
|
||||
/**
|
||||
* Returns defined data processors applicable for the given parameter.
|
||||
* Optionally also access to the processors is checked.
|
||||
*
|
||||
* Optionally also checks access to the processors.
|
||||
*
|
||||
* @param $param_info
|
||||
* If given, only processors valid for this parameter are returned.
|
||||
* @param bool $access_check
|
||||
* @param string $hook
|
||||
*/
|
||||
public static function processors($param_info = NULL, $access_check = TRUE, $hook = 'data_processor_info') {
|
||||
static $items = array();
|
||||
|
||||
if (!isset($items[$hook]['all'])) {
|
||||
$items[$hook]['all'] = rules_fetch_data($hook);
|
||||
uasort($items[$hook]['all'], array(__CLASS__, '_item_sort'));
|
||||
if (isset($items[$hook]['all'])) {
|
||||
uasort($items[$hook]['all'], array(__CLASS__, '_item_sort'));
|
||||
}
|
||||
}
|
||||
// Data processing isn't supported for multiple types.
|
||||
if (isset($param_info) && is_array($param_info['type'])) {
|
||||
@@ -182,17 +191,20 @@ abstract class RulesDataProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the value. If $this->processor is set, invoke this processor
|
||||
* first so chaining multiple processors is working.
|
||||
* Processes the value.
|
||||
*
|
||||
* If $this->processor is set, invoke this processor first so chaining
|
||||
* multiple processors is working.
|
||||
*
|
||||
* @param $value
|
||||
* The value to process.
|
||||
* @param $info
|
||||
* Info about the parameter for which we process the value.
|
||||
* @param $state RulesState
|
||||
* @param RulesState $state
|
||||
* The rules evaluation state.
|
||||
* @param $element RulesPlugin
|
||||
* @param RulesPlugin $element
|
||||
* The element for which we process the value.
|
||||
*
|
||||
* @return
|
||||
* The processed value.
|
||||
*/
|
||||
@@ -200,6 +212,9 @@ abstract class RulesDataProcessor {
|
||||
|
||||
/**
|
||||
* Return whether the current user has permission to use the processor.
|
||||
*
|
||||
* @return bool
|
||||
* Whether the current user has permission to use the processor.
|
||||
*/
|
||||
public static function access() {
|
||||
return TRUE;
|
||||
@@ -210,7 +225,7 @@ abstract class RulesDataProcessor {
|
||||
*
|
||||
* @param $settings
|
||||
* The settings of the processor.
|
||||
* @param $var_info
|
||||
* @param array $var_info
|
||||
* An array of info about the available variables.
|
||||
*
|
||||
* @return
|
||||
@@ -219,13 +234,15 @@ abstract class RulesDataProcessor {
|
||||
protected static function form($settings, $var_info) {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A base processor for use as input evaluators. Input evaluators are not listed
|
||||
* in hook_rules_data_processor_info(). Instead they use
|
||||
* hook_rules_evaluator_info() and get attached to input forms.
|
||||
* A base processor for use by input evaluators.
|
||||
*
|
||||
* Input evaluators are not listed in hook_rules_data_processor_info(). Instead
|
||||
* they use hook_rules_evaluator_info() and get attached to input forms.
|
||||
*/
|
||||
abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
|
||||
@@ -266,9 +283,10 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to prepare input evaluator processors. The setting is expected
|
||||
* to be the input value to be evaluated later on and is replaced by the
|
||||
* suiting processor.
|
||||
* Overridden to prepare input evaluator processors.
|
||||
*
|
||||
* The setting is expected to be the input value to be evaluated later on
|
||||
* and is replaced by the suitable processor.
|
||||
*/
|
||||
public static function prepareSetting(&$setting, $param_info, $var_info = array()) {
|
||||
$processor = NULL;
|
||||
@@ -284,7 +302,9 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to just attach the help() of evaluators.
|
||||
* Overrides RulesDataProcessor::attachForm().
|
||||
*
|
||||
* Overridden to just attach the help() of evaluators.
|
||||
*/
|
||||
public static function attachForm(&$form, $settings, $param_info, $var_info, $access_check = TRUE) {
|
||||
foreach (self::evaluators($param_info, $access_check) as $name => $info) {
|
||||
@@ -294,14 +314,15 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all input evaluators that can be applied to the parameters needed
|
||||
* type.
|
||||
* Returns all input evaluators that can be applied to the parameters type.
|
||||
*/
|
||||
public static function evaluators($param_info = NULL, $access_check = TRUE) {
|
||||
return parent::processors($param_info, $access_check, 'evaluator_info');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides RulesDataProcessor::processors().
|
||||
*
|
||||
* Overridden to default to our hook, thus being equivalent to
|
||||
* self::evaluators().
|
||||
*/
|
||||
@@ -310,14 +331,16 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the evalution, e.g. to determine whether the input evaluator has
|
||||
* been used. If this evaluator should be skipped just unset $this->setting.
|
||||
* Prepares the evaluation.
|
||||
*
|
||||
* @param $text
|
||||
* For example, to determine whether the input evaluator has been used.
|
||||
* If this evaluator should be skipped just unset $this->setting.
|
||||
*
|
||||
* @param string $text
|
||||
* The text to evaluate later on.
|
||||
* @param $variables
|
||||
* @param array $variables
|
||||
* An array of info about available variables.
|
||||
* @param $param_info
|
||||
* @param array $param_info
|
||||
* (optional) An array of information about the handled parameter value.
|
||||
* For backward compatibility, this parameter is not required.
|
||||
*/
|
||||
@@ -326,9 +349,9 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
/**
|
||||
* Apply the input evaluator.
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* The text to evaluate.
|
||||
* @param $options
|
||||
* @param array $options
|
||||
* A keyed array of settings and flags to control the processing.
|
||||
* Supported options are:
|
||||
* - language: A language object to be used when processing.
|
||||
@@ -337,7 +360,7 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
* certain way.
|
||||
* - sanitize: A boolean flag indicating whether incorporated replacements
|
||||
* should be sanitized.
|
||||
* @param RulesState
|
||||
* @param RulesState $state
|
||||
* The rules evaluation state.
|
||||
*
|
||||
* @return
|
||||
@@ -348,13 +371,13 @@ abstract class RulesDataInputEvaluator extends RulesDataProcessor {
|
||||
/**
|
||||
* Provide some usage help for the evaluator.
|
||||
*
|
||||
* @param $variables
|
||||
* @param array $variables
|
||||
* An array of info about available variables.
|
||||
* @param $param_info
|
||||
* @param array $param_info
|
||||
* (optional) An array of information about the handled parameter value.
|
||||
* For backward compatibility, this parameter is not required.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* A renderable array.
|
||||
*/
|
||||
public static function help($variables) {
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file Contains the state and data related stuff.
|
||||
* @file
|
||||
* Contains the state and data related stuff.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -14,16 +15,22 @@ class RulesState {
|
||||
|
||||
/**
|
||||
* Globally keeps the ids of rules blocked due to recursion prevention.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static protected $blocked = array();
|
||||
|
||||
/**
|
||||
* The known variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $variables = array();
|
||||
|
||||
/**
|
||||
* Holds info about the variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $info = array();
|
||||
|
||||
@@ -33,8 +40,9 @@ class RulesState {
|
||||
protected $save;
|
||||
|
||||
/**
|
||||
* Holds the arguments while an element is executed. May be used by the
|
||||
* element to easily access the wrapped arguments.
|
||||
* Holds the arguments while an element is executed.
|
||||
*
|
||||
* May be used by the element to easily access the wrapped arguments.
|
||||
*/
|
||||
public $currentArguments;
|
||||
|
||||
@@ -43,7 +51,9 @@ class RulesState {
|
||||
*/
|
||||
protected $currentlyBlocked;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a RulesState object.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Use an object in order to ensure any cloned states reference the same
|
||||
// save information.
|
||||
@@ -131,7 +141,7 @@ class RulesState {
|
||||
*
|
||||
* If necessary, the specified handler is invoked to fetch the variable.
|
||||
*
|
||||
* @param $name
|
||||
* @param string $name
|
||||
* The name of the variable to return.
|
||||
*
|
||||
* @return
|
||||
@@ -164,7 +174,8 @@ class RulesState {
|
||||
*
|
||||
* @param $selector
|
||||
* The data selector of the wrapper to save or just a variable name.
|
||||
* @param $immediate
|
||||
* @param $wrapper
|
||||
* @param bool $immediate
|
||||
* Pass FALSE to postpone saving to later on. Else it's immediately saved.
|
||||
*/
|
||||
public function saveChanges($selector, $wrapper, $immediate = FALSE) {
|
||||
@@ -234,9 +245,11 @@ class RulesState {
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the info about to be saved variables form the given state into the
|
||||
* existing state. Therefor we can aggregate saves from invoked components.
|
||||
* Merged in saves are removed from the given state, but not mergable saves
|
||||
* Merges info from the given state into the existing state.
|
||||
*
|
||||
* Merges the info about to-be-saved variables from the given state into the
|
||||
* existing state. Therefore we can aggregate saves from invoked components.
|
||||
* Merged-in saves are removed from the given state, but not-mergeable saves
|
||||
* remain there.
|
||||
*
|
||||
* @param $state
|
||||
@@ -267,9 +280,9 @@ class RulesState {
|
||||
/**
|
||||
* Returns an entity metadata wrapper as specified in the selector.
|
||||
*
|
||||
* @param $selector
|
||||
* @param string $selector
|
||||
* The selector string, e.g. "node:author:mail".
|
||||
* @param $langcode
|
||||
* @param string $langcode
|
||||
* (optional) The language code used to get the argument value if the
|
||||
* argument value should be translated. Defaults to LANGUAGE_NONE.
|
||||
*
|
||||
@@ -291,7 +304,7 @@ class RulesState {
|
||||
try {
|
||||
foreach (explode(':', $parts[1]) as $name) {
|
||||
if ($wrapper instanceof EntityListWrapper || $wrapper instanceof EntityStructureWrapper) {
|
||||
// Make sure we are usign the right language. Wrappers might be cached
|
||||
// Make sure we are using the right language. Wrappers might be cached
|
||||
// and have previous langcodes set, so always set the right language.
|
||||
if ($wrapper instanceof EntityStructureWrapper) {
|
||||
$wrapper->language($langcode);
|
||||
@@ -312,30 +325,37 @@ class RulesState {
|
||||
|
||||
/**
|
||||
* Magic method. Only serialize variables and their info.
|
||||
*
|
||||
* Additionally we remember currently blocked configs, so we can restore them
|
||||
* upon deserialization using restoreBlocks().
|
||||
*/
|
||||
public function __sleep () {
|
||||
public function __sleep() {
|
||||
$this->currentlyBlocked = self::$blocked;
|
||||
return array('info', 'variables', 'currentlyBlocked');
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method. Unserialize variables and their info.
|
||||
*/
|
||||
public function __wakeup() {
|
||||
$this->save = new ArrayObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the before serialization blocked configurations.
|
||||
* Restores the before-serialization blocked configurations.
|
||||
*
|
||||
* Warning: This overwrites any possible currently blocked configs. Thus
|
||||
* do not invoke this method, if there might be evaluations active.
|
||||
* do not invoke this method if there might be evaluations active.
|
||||
*/
|
||||
public function restoreBlocks() {
|
||||
self::$blocked = $this->currentlyBlocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines always available variables.
|
||||
* Defines always-available variables.
|
||||
*
|
||||
* @param $key
|
||||
* (optional)
|
||||
*/
|
||||
public static function defaultVariables($key = NULL) {
|
||||
// Add a variable for accessing site-wide data properties.
|
||||
@@ -350,12 +370,13 @@ class RulesState {
|
||||
);
|
||||
return isset($key) ? $vars[$key] : $vars;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class holding static methods related to data.
|
||||
*/
|
||||
class RulesData {
|
||||
class RulesData {
|
||||
|
||||
/**
|
||||
* Returns whether the type match. They match if type1 is compatible to type2.
|
||||
@@ -364,11 +385,11 @@ class RulesData {
|
||||
* The name of the type to check for whether it is compatible to type2.
|
||||
* @param $param_info
|
||||
* The type expression to check for.
|
||||
* @param $ancestors
|
||||
* Whether sub-type relationships for checking type compatibility should be
|
||||
* taken into account. Defaults to TRUE.
|
||||
* @param bool $ancestors
|
||||
* (optional) Whether sub-type relationships for checking type compatibility
|
||||
* should be taken into account. Defaults to TRUE.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* Whether the types match.
|
||||
*/
|
||||
public static function typesMatch($var_info, $param_info, $ancestors = TRUE) {
|
||||
@@ -395,7 +416,7 @@ class RulesData {
|
||||
$cache = &rules_get_cache();
|
||||
self::typeCalcAncestors($cache, $var_type);
|
||||
// If one of the types is an ancestor return TRUE.
|
||||
return (bool)array_intersect_key($cache['data_info'][$var_type]['ancestors'], array_flip($valid_types));
|
||||
return (bool) array_intersect_key($cache['data_info'][$var_type]['ancestors'], array_flip($valid_types));
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -417,25 +438,27 @@ class RulesData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns matching data variables or properties for the given info and the to
|
||||
* be configured parameter.
|
||||
* Returns data for the given info and the to-be-configured parameter.
|
||||
*
|
||||
* Returns matching data variables or properties for the given info and the
|
||||
* to-be-configured parameter.
|
||||
*
|
||||
* @param $source
|
||||
* Either an array of info about available variables or a entity metadata
|
||||
* wrapper.
|
||||
* @param $param_info
|
||||
* The information array about the to be configured parameter.
|
||||
* @param $prefix
|
||||
* @param string $prefix
|
||||
* An optional prefix for the data selectors.
|
||||
* @param $recursions
|
||||
* @param int $recursions
|
||||
* The number of recursions used to go down the tree. Defaults to 2.
|
||||
* @param $suggestions
|
||||
* @param bool $suggestions
|
||||
* Whether possibilities to recurse are suggested as soon as the deepest
|
||||
* level of recursions is reached. Defaults to TRUE.
|
||||
*
|
||||
* @return
|
||||
* An array of info about matching variables or properties that match, keyed
|
||||
* with the data selector.
|
||||
* @return array
|
||||
* An array of info about matching variables or properties that match, keyed
|
||||
* with the data selector.
|
||||
*/
|
||||
public static function matchingDataSelector($source, $param_info, $prefix = '', $recursions = 2, $suggestions = TRUE) {
|
||||
// If an array of info is given, get entity metadata wrappers first.
|
||||
@@ -467,7 +490,8 @@ class RulesData {
|
||||
$matches += self::matchingDataSelector($wrapper, $param_info, $prefix . $name . ':', $recursions - 1, $suggestions);
|
||||
}
|
||||
elseif ($suggestions) {
|
||||
// We may not recurse any more, but indicate the possibility to recurse.
|
||||
// We may not recurse any more,
|
||||
// but indicate the possibility to recurse.
|
||||
$matches[$prefix . $name . ':'] = $wrapper->info();
|
||||
if (!is_array($source) && $source instanceof EntityListWrapper) {
|
||||
// Add some more possible list items.
|
||||
@@ -482,8 +506,10 @@ class RulesData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds asserted metadata to the variable info. In case there are already
|
||||
* assertions for a variable, the assertions are merged such that both apply.
|
||||
* Adds asserted metadata to the variable info.
|
||||
*
|
||||
* In case there are already assertions for a variable, the assertions are
|
||||
* merged such that both apply.
|
||||
*
|
||||
* @see RulesData::applyMetadataAssertions()
|
||||
*/
|
||||
@@ -508,10 +534,9 @@ class RulesData {
|
||||
// before the child-wrapper is created.
|
||||
if (count($parts) == 1) {
|
||||
// Support asserting a type in case of generic entity references only.
|
||||
if (isset($assertion['type']) && $var_info[$parts[0]]['type'] == 'entity') {
|
||||
if (entity_get_info($assertion['type'])) {
|
||||
$var_info[$parts[0]]['type'] = $assertion['type'];
|
||||
}
|
||||
$var_type = &$var_info[$parts[0]]['type'];
|
||||
if (isset($assertion['type']) && ($var_type == 'entity' || $var_type == 'list<entity>')) {
|
||||
$var_type = $assertion['type'];
|
||||
unset($assertion['type']);
|
||||
}
|
||||
// Add any single bundle directly to the variable info, so the
|
||||
@@ -547,8 +572,9 @@ class RulesData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Property info alter callback for the entity metadata wrapper for applying
|
||||
* the rules metadata assertions.
|
||||
* Property info alter callback for the entity metadata wrapper.
|
||||
*
|
||||
* Used for applying the rules metadata assertions.
|
||||
*
|
||||
* @see RulesData::addMetadataAssertions()
|
||||
*/
|
||||
@@ -586,7 +612,8 @@ class RulesData {
|
||||
$property_info['properties'][$key]['rules assertion'] = $assertion[$key];
|
||||
$property_info['properties'][$key]['property info alter'] = array('RulesData', 'applyMetadataAssertions');
|
||||
|
||||
// Apply any 'type' and 'bundle' assertion directly to the propertyinfo.
|
||||
// Apply any 'type' and 'bundle' assertion directly to the property
|
||||
// info.
|
||||
if (isset($assertion[$key]['#info']['type'])) {
|
||||
$type = $assertion[$key]['#info']['type'];
|
||||
// Support asserting a type in case of generic entity references only.
|
||||
@@ -608,9 +635,10 @@ class RulesData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Property info alter callback for the entity metadata wrapper to inject
|
||||
* metadata for the 'site' variable. In contrast to doing this via
|
||||
* hook_rules_data_info() this callback makes use of the already existing
|
||||
* Property info alter callback for the entity metadata wrapper.
|
||||
*
|
||||
* Used to inject metadata for the 'site' variable. In contrast to doing this
|
||||
* via hook_rules_data_info() this callback makes use of the already existing
|
||||
* property info cache for site information of entity metadata.
|
||||
*
|
||||
* @see RulesPlugin::availableVariables()
|
||||
@@ -622,6 +650,7 @@ class RulesData {
|
||||
// have specified further metadata.
|
||||
return RulesData::applyMetadataAssertions($wrapper, $property_info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -653,7 +682,7 @@ abstract class RulesIdentifiableDataWrapper extends EntityStructureWrapper {
|
||||
* The type of the passed data.
|
||||
* @param $data
|
||||
* Optional. The data to wrap or its identifier.
|
||||
* @param $info
|
||||
* @param array $info
|
||||
* Optional. Used internally to pass info about properties down the tree.
|
||||
*/
|
||||
public function __construct($type, $data = NULL, $info = array()) {
|
||||
@@ -722,7 +751,7 @@ abstract class RulesIdentifiableDataWrapper extends EntityStructureWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for serializiation.
|
||||
* Prepare for serialization.
|
||||
*/
|
||||
public function __sleep() {
|
||||
$vars = parent::__sleep();
|
||||
@@ -734,6 +763,9 @@ abstract class RulesIdentifiableDataWrapper extends EntityStructureWrapper {
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for unserialization.
|
||||
*/
|
||||
public function __wakeup() {
|
||||
if ($this->id !== FALSE) {
|
||||
// Make sure data is set, so the data will be loaded when needed.
|
||||
@@ -756,10 +788,11 @@ abstract class RulesIdentifiableDataWrapper extends EntityStructureWrapper {
|
||||
* The loaded data object, or FALSE if loading failed.
|
||||
*/
|
||||
abstract protected function load($id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface that allows custom wrapper classes to declare that they are savable.
|
||||
* Used to declare custom wrapper classes as savable.
|
||||
*/
|
||||
interface RulesDataWrapperSavableInterface {
|
||||
|
||||
@@ -767,4 +800,5 @@ interface RulesDataWrapperSavableInterface {
|
||||
* Save the currently wrapped data.
|
||||
*/
|
||||
public function save();
|
||||
|
||||
}
|
||||
|
@@ -28,8 +28,8 @@ function rules_upgrade_form($form, &$form_state) {
|
||||
'#prefix' => '<p>',
|
||||
'#suffix' => '</p>',
|
||||
'#markup' => t('This form allows you to convert rules or rule sets from Rules 1.x to Rules 2.x.') . ' ' .
|
||||
t('In order to convert a rule or rule set make sure you have all dependend modules installed and upgraded, i.e. modules which provide Rules integration that has been used in your rules or rule sets. In addition those modules may need to implement some Rules specific update hooks for the conversion to properly work.') . ' ' .
|
||||
t('After conversion, the old rules and rule sets will stay in the database until you manually delete them. That way you can make sure the conversion has gone right before you delete the old rules and rule sets.')
|
||||
t('In order to convert a rule or rule set make sure you have all dependent modules installed and upgraded, i.e. modules which provide Rules integration that has been used in your rules or rule sets. In addition those modules may need to implement some Rules specific update hooks for the conversion to properly work.') . ' ' .
|
||||
t('After conversion, the old rules and rule sets will stay in the database until you manually delete them. That way you can make sure the conversion has gone right before you delete the old rules and rule sets.'),
|
||||
);
|
||||
|
||||
$option_rules = $option_sets = array();
|
||||
@@ -51,7 +51,7 @@ function rules_upgrade_form($form, &$form_state) {
|
||||
$form['clear'] = array(
|
||||
'#prefix' => '<p>',
|
||||
'#suffix' => '</p>',
|
||||
'#markup' => t('Once you have successfully converted your configuration, you can clean up your database and <a href="!url">delete</a> all Rules 1.x configurations.', array('!url' => url('admin/config/workflow/rules/upgrade/clear')))
|
||||
'#markup' => t('Once you have successfully converted your configuration, you can clean up your database and <a href="!url">delete</a> all Rules 1.x configurations.', array('!url' => url('admin/config/workflow/rules/upgrade/clear'))),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ function rules_upgrade_form($form, &$form_state) {
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Method'),
|
||||
'#options' => array(
|
||||
'export' => t('Convert configuration and export it.'),
|
||||
'save' => t('Convert configuration and save it.'),
|
||||
'export' => t('Convert configuration and export it.'),
|
||||
'save' => t('Convert configuration and save it.'),
|
||||
),
|
||||
'#default_value' => 'export',
|
||||
);
|
||||
@@ -81,7 +81,7 @@ function rules_upgrade_form($form, &$form_state) {
|
||||
$form['actions']['convert'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Convert'),
|
||||
'#disabled' => !db_table_exists('rules_rules')
|
||||
'#disabled' => !db_table_exists('rules_rules'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
@@ -137,6 +137,9 @@ function rules_upgrade_confirm_clear_form($form, $form_state) {
|
||||
return confirm_form($form, $confirm_question, 'admin/config/workflow/rules/upgrade', $confirm_question_long, t('Delete data'), t('Cancel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for deleting data.
|
||||
*/
|
||||
function rules_upgrade_confirm_clear_form_submit($form, &$form_state) {
|
||||
db_drop_table('rules_rules');
|
||||
db_drop_table('rules_sets');
|
||||
@@ -206,7 +209,7 @@ function rules_upgrade_convert_rule_set($name, $cfg_old) {
|
||||
}
|
||||
|
||||
// Add in all rules of the set.
|
||||
foreach(_rules_upgrade_fetch_all_rules() as $rule_name => $rule) {
|
||||
foreach (_rules_upgrade_fetch_all_rules() as $rule_name => $rule) {
|
||||
if ($rule['#set'] == $name) {
|
||||
drupal_set_message(' >> ' . t('Converting %plugin %name...', array('%plugin' => t('rule'), '%name' => $rule_name . ': ' . $rule['#label'])));
|
||||
$new_rule = rules_upgrade_plugin_factory($rule);
|
||||
@@ -220,9 +223,9 @@ function rules_upgrade_convert_rule_set($name, $cfg_old) {
|
||||
/**
|
||||
* Convert a single element.
|
||||
*
|
||||
* @param $element
|
||||
* @param array $element
|
||||
* The element to convert.
|
||||
* @param $target
|
||||
* @param RulesPlugin $target
|
||||
* The converted element to write to.
|
||||
*/
|
||||
function rules_upgrade_convert_element(array $element, RulesPlugin $target) {
|
||||
@@ -235,7 +238,7 @@ function rules_upgrade_convert_element(array $element, RulesPlugin $target) {
|
||||
foreach ($target->pluginParameterInfo() as $name => $info) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, $name);
|
||||
}
|
||||
// @todo: Care about php input evaluator for non-text parameters.
|
||||
// @todo Care about php input evaluator for non-text parameters.
|
||||
|
||||
// Take care of variable names and labels.
|
||||
foreach ($target->pluginProvidesVariables() as $name => $info) {
|
||||
@@ -268,10 +271,10 @@ function rules_upgrade_convert_element(array $element, RulesPlugin $target) {
|
||||
|
||||
// Invoke action/condition specific hooks and a general one.
|
||||
if (($element['#type'] == 'action' || $element['#type'] == 'condition')) {
|
||||
if (function_exists($function = $element['#name'] .'_upgrade')) {
|
||||
if (function_exists($function = $element['#name'] . '_upgrade')) {
|
||||
$element_name = $function($element, $target);
|
||||
}
|
||||
elseif (isset($element['#info']['base']) && function_exists($function = $element['#info']['base'] .'_upgrade')) {
|
||||
elseif (isset($element['#info']['base']) && function_exists($function = $element['#info']['base'] . '_upgrade')) {
|
||||
$element_name = $function($element, $target);
|
||||
}
|
||||
}
|
||||
@@ -299,8 +302,10 @@ function rules_upgrade_plugin_factory($element) {
|
||||
switch ($element['#type']) {
|
||||
case 'OR':
|
||||
return rules_plugin_factory('or');
|
||||
|
||||
case 'AND':
|
||||
return rules_plugin_factory('and');
|
||||
|
||||
default:
|
||||
return rules_plugin_factory($element['#type']);
|
||||
|
||||
@@ -329,7 +334,7 @@ function rules_upgrade_plugin_factory($element) {
|
||||
}
|
||||
|
||||
// Call the upgrade callback if one has been defined.
|
||||
if (function_exists($function = $element['#name'] .'_upgrade_map_name') || (isset($element['#info']['base']) && function_exists($function = $element['#info']['base'] .'_upgrade_map_name'))) {
|
||||
if (function_exists($function = $element['#name'] . '_upgrade_map_name') || (isset($element['#info']['base']) && function_exists($function = $element['#info']['base'] . '_upgrade_map_name'))) {
|
||||
$element_name = $function($element);
|
||||
}
|
||||
if (!isset($element_name)) {
|
||||
@@ -380,59 +385,77 @@ function rules_upgrade_element_variable_settings($element, $target, $name, $new_
|
||||
* Upgrade callbacks for upgrading the provided Rules 1.x integration.
|
||||
*/
|
||||
|
||||
// Comment.module integration.
|
||||
/**
|
||||
* Comment.module integration.
|
||||
*/
|
||||
function rules_action_load_comment_upgrade_map_name($element) {
|
||||
return 'entity_fetch';
|
||||
}
|
||||
|
||||
function rules_action_load_comment_upgrade($element, $target) {
|
||||
$target->settings['type'] = 'comment';
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'cid', 'id');
|
||||
rules_upgrade_element_variable_settings($element, $target, 'comment_loaded', 'entity_fetched');
|
||||
}
|
||||
|
||||
// Node.module integration.
|
||||
/**
|
||||
* Node.module integration.
|
||||
*/
|
||||
function rules_condition_content_is_type_upgrade_map_name($element) {
|
||||
return 'node_is_of_type';
|
||||
}
|
||||
|
||||
function rules_condition_content_is_published_upgrade_map_name($element) {
|
||||
return 'node_is_published';
|
||||
}
|
||||
|
||||
function rules_condition_content_is_sticky_upgrade_map_name($element) {
|
||||
return 'node_is_sticky';
|
||||
}
|
||||
|
||||
function rules_condition_content_is_promoted_upgrade_map_name($element) {
|
||||
return 'node_is_promoted';
|
||||
}
|
||||
|
||||
function rules_condition_content_is_new_upgrade_map_name($element) {
|
||||
return 'entity_is_new';
|
||||
}
|
||||
|
||||
function rules_condition_content_is_new_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'node', 'entity');
|
||||
}
|
||||
|
||||
function rules_action_node_set_author_upgrade_map_name($element) {
|
||||
return 'data_set';
|
||||
}
|
||||
|
||||
function rules_action_node_set_author_upgrade($element, $target) {
|
||||
$target->settings['data:select'] = $element['#settings']['#argument map']['node'] . ':author';
|
||||
$target->settings['value:select'] = $element['#settings']['#argument map']['author'];
|
||||
}
|
||||
|
||||
function rules_action_node_load_author_upgrade_map_name($element) {
|
||||
return 'entity_fetch';
|
||||
}
|
||||
|
||||
function rules_action_node_load_author_upgrade($element, $target) {
|
||||
$target->settings['type'] = 'user';
|
||||
$target->settings['id'] = $element['#settings']['#argument map']['node'] . ':author:uid';
|
||||
}
|
||||
|
||||
function rules_action_set_node_title_upgrade_map_name($element) {
|
||||
return 'data_set';
|
||||
}
|
||||
|
||||
function rules_action_set_node_title_upgrade($element, $target) {
|
||||
$target->settings['data:select'] = $element['#settings']['#argument map']['node'] . ':title';
|
||||
$target->settings['value'] = $element['#settings']['title'];
|
||||
}
|
||||
|
||||
function rules_action_add_node_upgrade_map_name($element) {
|
||||
return 'entity_create';
|
||||
}
|
||||
|
||||
function rules_action_add_node_upgrade($element, $target) {
|
||||
$target->settings['type'] = 'node';
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'title', 'param_title');
|
||||
@@ -443,105 +466,135 @@ function rules_action_add_node_upgrade($element, $target) {
|
||||
drupal_set_message(t('Warning: The node-access check option for the node creation action is not supported any more.'));
|
||||
}
|
||||
}
|
||||
|
||||
function rules_action_load_node_upgrade_map_name($element) {
|
||||
return 'entity_fetch';
|
||||
}
|
||||
|
||||
function rules_action_load_node_upgrade($element, $target) {
|
||||
$target->settings['type'] = 'node';
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'nid', 'id');
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'vid', 'revision_id');
|
||||
rules_upgrade_element_variable_settings($element, $target, 'node_loaded', 'entity_fetched');
|
||||
}
|
||||
|
||||
function rules_action_delete_node_upgrade_map_name($element) {
|
||||
return 'entity_delete';
|
||||
}
|
||||
|
||||
function rules_action_delete_node_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'node', 'entity');
|
||||
}
|
||||
|
||||
function rules_core_node_publish_action_upgrade_map_name($element) {
|
||||
return 'node_publish';
|
||||
}
|
||||
|
||||
function rules_core_node_unpublish_action_upgrade_map_name($element) {
|
||||
return 'node_unpublish';
|
||||
}
|
||||
|
||||
function rules_core_node_make_sticky_action_upgrade_map_name($element) {
|
||||
return 'node_make_sticky_action';
|
||||
}
|
||||
|
||||
function rules_core_node_make_unsticky_action_upgrade_map_name($element) {
|
||||
return 'node_make_unsticky_action';
|
||||
}
|
||||
|
||||
function rules_core_node_promote_action_upgrade_map_name($element) {
|
||||
return 'node_promote_action';
|
||||
}
|
||||
|
||||
function rules_core_node_unpromote_action_upgrade_map_name($element) {
|
||||
return 'node_unpromote_action';
|
||||
}
|
||||
|
||||
|
||||
// Path.module integration.
|
||||
/**
|
||||
* Path.module integration.
|
||||
*/
|
||||
function rules_condition_url_has_alias_upgrade_map_name($element) {
|
||||
return 'path_has_alias';
|
||||
}
|
||||
|
||||
function rules_condition_url_has_alias_upgrade($element, $target) {
|
||||
$target->settings['source'] = $element['#settings']['src'];
|
||||
$target->settings['alias'] = $element['#settings']['dst'];
|
||||
}
|
||||
|
||||
function rules_condition_alias_exists_upgrade_map_name($element) {
|
||||
return 'path_alias_exists';
|
||||
}
|
||||
|
||||
function rules_condition_alias_exists_upgrade($element, $target) {
|
||||
$target->settings['alias'] = $element['#settings']['dst'];
|
||||
}
|
||||
|
||||
function rules_action_path_alias_upgrade($element, $target) {
|
||||
$target->settings['source'] = $element['#settings']['src'];
|
||||
$target->settings['alias'] = $element['#settings']['dst'];
|
||||
}
|
||||
|
||||
function rules_action_node_path_alias_upgrade($element, $target) {
|
||||
$target->settings['alias'] = $element['#settings']['dst'];
|
||||
}
|
||||
|
||||
// PHP.module integration.
|
||||
/**
|
||||
* PHP.module integration.
|
||||
*/
|
||||
function rules_condition_custom_php_upgrade_map_name($element) {
|
||||
return 'php_eval';
|
||||
}
|
||||
|
||||
function rules_action_custom_php_upgrade_map_name($element) {
|
||||
return 'php_eval';
|
||||
}
|
||||
|
||||
// General Rules integration.
|
||||
/**
|
||||
* General Rules integration.
|
||||
*/
|
||||
function rules_condition_text_compare_upgrade_map_name($element) {
|
||||
// @todo: Support regex.
|
||||
// @todo Support regex.
|
||||
return 'data_is';
|
||||
}
|
||||
|
||||
function rules_condition_text_compare_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'text1', 'data');
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'text2', 'value');
|
||||
}
|
||||
|
||||
function rules_condition_number_compare_upgrade_map_name($element) {
|
||||
return 'data_is';
|
||||
}
|
||||
|
||||
function rules_condition_number_compare_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'number1', 'data');
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'number2', 'value');
|
||||
}
|
||||
|
||||
function rules_condition_check_boolean_upgrade_map_name($element) {
|
||||
return 'data_is';
|
||||
}
|
||||
|
||||
function rules_condition_check_boolean_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'boolean', 'data');
|
||||
$target->settings['value'] = TRUE;
|
||||
}
|
||||
|
||||
function rules_action_invoke_set_upgrade_map_name($element) {
|
||||
return 'component_' . $element['#info']['set'];
|
||||
}
|
||||
|
||||
function rules_action_invoke_set_upgrade($element, $target) {
|
||||
foreach ($element['#info']['arguments'] as $name => $info) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, $name);
|
||||
}
|
||||
}
|
||||
|
||||
function rules_action_save_variable_upgrade_map_name($element) {
|
||||
return isset($element['#info']['new variables']) ? 'variable_add' : 'entity_save';
|
||||
}
|
||||
|
||||
function rules_action_save_variable_upgrade($element, $target) {
|
||||
$type = $element['#info']['arguments']['var_name']['default value'];
|
||||
if (isset($element['#info']['new variables'])) {
|
||||
@@ -554,20 +607,25 @@ function rules_action_save_variable_upgrade($element, $target) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// System.module integration.
|
||||
/**
|
||||
* System.module integration.
|
||||
*/
|
||||
function rules_action_set_breadcrumb_upgrade_map_name($element) {
|
||||
return 'breadcumb_set';
|
||||
return 'breadcrumb_set';
|
||||
}
|
||||
|
||||
function rules_action_mail_to_user_upgrade_map_name($element) {
|
||||
return 'mail';
|
||||
}
|
||||
|
||||
function rules_action_mail_to_user_upgrade($element, $target) {
|
||||
$target->settings['to:select'] = $element['#settings']['#argument map']['user'] . ':mail';
|
||||
}
|
||||
|
||||
function rules_action_drupal_goto_upgrade_map_name($element) {
|
||||
return 'redirect';
|
||||
}
|
||||
|
||||
function rules_action_drupal_goto_upgrade($element, $target) {
|
||||
$settings = $element['#settings'];
|
||||
$target->settings['url'] = $settings['path'];
|
||||
@@ -579,86 +637,109 @@ function rules_action_drupal_goto_upgrade($element, $target) {
|
||||
}
|
||||
|
||||
function rules_action_watchdog_upgrade_map_name($element) {
|
||||
// @todo: Support action in Rules 2.x!
|
||||
// @todo Support action in Rules 2.x!
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Taxonomy.module integration.
|
||||
// @todo: Finish.
|
||||
/**
|
||||
* Taxonomy.module integration.
|
||||
*
|
||||
* @todo Finish.
|
||||
*/
|
||||
function rules_action_taxonomy_load_term_upgrade_map_name($element) {
|
||||
return 'entity_fetch';
|
||||
}
|
||||
|
||||
function rules_action_taxonomy_add_term_upgrade_map_name($element) {
|
||||
return 'entity_create';
|
||||
}
|
||||
|
||||
function rules_action_taxonomy_delete_term_upgrade_map_name($element) {
|
||||
return 'entity_delete';
|
||||
}
|
||||
|
||||
function rules_action_taxonomy_term_assign_to_content_upgrade_map_name($element) {
|
||||
// @todo : list.
|
||||
// @todo List.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function rules_action_taxonomy_term_remove_from_content_upgrade_map_name($element) {
|
||||
// @todo : list.
|
||||
// @todo List.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function rules_action_taxonomy_load_vocab_upgrade_map_name($element) {
|
||||
return 'entity_fetch';
|
||||
}
|
||||
|
||||
function rules_action_taxonomy_add_vocab_upgrade_map_name($element) {
|
||||
return 'data_set';
|
||||
}
|
||||
|
||||
// User.module integration.
|
||||
/**
|
||||
* User.module integration.
|
||||
*/
|
||||
function rules_condition_user_hasrole_upgrade_map_name($element) {
|
||||
return 'user_has_role';
|
||||
}
|
||||
|
||||
function rules_condition_user_hasrole_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'user', 'account');
|
||||
}
|
||||
|
||||
function rules_condition_user_comparison_upgrade_map_name($element) {
|
||||
return 'data_is';
|
||||
}
|
||||
|
||||
function rules_condition_user_comparison_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'user1', 'data');
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'user2', 'value');
|
||||
}
|
||||
|
||||
function rules_action_user_addrole_upgrade_map_name($element) {
|
||||
return 'user_add_role';
|
||||
}
|
||||
|
||||
function rules_action_user_addrole_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'user', 'account');
|
||||
}
|
||||
|
||||
function rules_action_user_removerole_upgrade_map_name($element) {
|
||||
return 'user_remove_role';
|
||||
}
|
||||
|
||||
function rules_action_user_removerole_upgrade($element, $target) {
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'user', 'account');
|
||||
}
|
||||
|
||||
function rules_action_load_user_upgrade_map_name($element) {
|
||||
if (!empty($element['#settings']['username'])) {
|
||||
drupal_set_message(t('Warning: Directly upgrading the load user by name action is not supported.'));
|
||||
}
|
||||
return 'entity_fetch';
|
||||
}
|
||||
|
||||
function rules_action_load_user_upgrade($element, $target) {
|
||||
$target->settings['type'] = 'user';
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'userid', 'id');
|
||||
rules_upgrade_element_variable_settings($element, $target, 'user_loaded', 'entity_fetched');
|
||||
}
|
||||
|
||||
function rules_action_user_create_upgrade_map_name($element) {
|
||||
return 'entity_create';
|
||||
}
|
||||
|
||||
function rules_action_user_create_upgrade($element, $target) {
|
||||
$target->settings['type'] = 'user';
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'username', 'param_name');
|
||||
rules_upgrade_element_parameter_settings($element, $target, 'email', 'param_mail');
|
||||
rules_upgrade_element_variable_settings($element, $target, 'user_added', 'entity_created');
|
||||
|
||||
}
|
||||
|
||||
function rules_core_user_block_user_action_upgrade_map_name($element) {
|
||||
return 'user_block';
|
||||
}
|
||||
|
||||
function rules_core_user_block_user_action_upgrade($element, $target) {
|
||||
$target->settings['account:select'] = $element['#settings']['#argument map']['user'];
|
||||
}
|
||||
|
Reference in New Issue
Block a user