? 1031530.account_email_entity_exists.patch Index: includes/rules.state.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/rules/includes/Attic/rules.state.inc,v retrieving revision 1.1.2.11 diff -u -p -r1.1.2.11 rules.state.inc --- includes/rules.state.inc 16 Feb 2011 17:22:33 -0000 1.1.2.11 +++ includes/rules.state.inc 17 Feb 2011 02:20:39 -0000 @@ -161,8 +161,8 @@ class RulesState { /** * Apply permanent changes provided the wrapper's data type is savable. * - * @param $name - * The name of the variable to update. + * @param $selector + * The data selector of the wrapper to save or just a variable name. * @param $immediate * Pass FALSE to postpone saving to later on. Else it's immediately saved. */ @@ -184,6 +184,8 @@ class RulesState { * Remembers to save the wrapper on cleanup or does it now. */ protected function save($selector, EntityMetadataWrapper $wrapper, $immediate) { + // Convert variable names and selectors to both use underscores. + $selector = strtr($selector, '-', '_'); if (isset($this->save[$selector])) { if ($this->save[$selector][0]->getIdentifier() == $wrapper->getIdentifier()) { // The entity is already remembered. So do a combined save. @@ -196,7 +198,9 @@ class RulesState { } } if (!isset($this->save[$selector])) { - $this->save[$selector] = array(clone $wrapper, self::$blocked); + // In case of immediate saving don't clone the wrapper, so saving a new + // entity immediately makes the identifier available afterwards. + $this->save[$selector] = array($immediate ? $wrapper : clone $wrapper, self::$blocked); } if ($immediate) { $this->saveNow($selector); Index: modules/data.eval.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/rules/modules/Attic/data.eval.inc,v retrieving revision 1.1.2.7 diff -u -p -r1.1.2.7 data.eval.inc --- modules/data.eval.inc 14 Feb 2011 18:11:55 -0000 1.1.2.7 +++ modules/data.eval.inc 17 Feb 2011 02:20:40 -0000 @@ -330,3 +330,11 @@ function rules_condition_entity_has_fiel function rules_condition_entity_is_of_type($wrapper, $type) { return $wrapper->type() == $type; } + +/** + * Condition: Entity exists with the matching property value. + */ +function rules_condition_entity_exists($type, $property, $value) { + $result = entity_metadata_table_query($type, $property, $value, 1); + return !empty($result); +} Index: modules/data.rules.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/rules/modules/Attic/data.rules.inc,v retrieving revision 1.1.2.8 diff -u -p -r1.1.2.8 data.rules.inc --- modules/data.rules.inc 15 Feb 2011 14:21:10 -0000 1.1.2.8 +++ modules/data.rules.inc 17 Feb 2011 02:20:40 -0000 @@ -637,6 +637,34 @@ function rules_data_condition_info() { 'group' => t('Entities'), 'base' => 'rules_condition_entity_is_of_type', ), + 'entity_exists' => array( + 'label' => t('Entity exists by property'), + 'parameter' => array( + 'type' => array( + 'type' => 'text', + 'label' => t('Entity type'), + 'options list' => 'rules_data_action_type_options', + 'description' => t('The type of the entity that should be fetched.'), + 'restriction' => 'input', + ), + 'property' => array( + 'type' => 'text', + 'label' => t('Property'), + 'description' => t('The property by which the entity is to be selected.'), + 'restriction' => 'input', + ), + 'value' => array( + 'type' => 'text', + 'label' => t('Value'), + 'description' => t('The property value of the entity to be fetched.'), + ), + ), + 'group' => t('Entities'), + 'base' => 'rules_condition_entity_exists', + 'callbacks' => array( + 'form_alter' => 'rules_action_type_form_alter', + ), + ), ); } Index: modules/user.eval.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/rules/modules/Attic/user.eval.inc,v retrieving revision 1.1.2.1 diff -u -p -r1.1.2.1 user.eval.inc --- modules/user.eval.inc 16 Dec 2010 09:30:43 -0000 1.1.2.1 +++ modules/user.eval.inc 17 Feb 2011 02:20:40 -0000 @@ -89,5 +89,28 @@ function rules_action_user_unblock($acco } /** + * Action: Send a user account e-mail. + */ +function rules_action_user_send_account_email($account, $email_type) { + // If we received an authenticated user account... + if (!empty($account)) { + module_load_include('inc', 'rules', 'modules/user.rules'); + + $types = rules_user_account_email_options_list(); + + // Attempt to send the account e-mail. + $result = _user_mail_notify($email_type, $account); + + // Log the success or failure. + if ($result) { + watchdog('rules', '%type e-mail sent to %recipient.', array('%type' => $types[$email_type], '%recipient' => $account->mail)); + } + else { + watchdog('rules', 'Failed to send %type e-mail to %recipient.', array('%type' => $types[$email_type], '%recipient' => $account->mail)); + } + } +} + +/** * @} */ Index: modules/user.rules.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/rules/modules/Attic/user.rules.inc,v retrieving revision 1.1.2.4 diff -u -p -r1.1.2.4 user.rules.inc --- modules/user.rules.inc 14 Feb 2011 15:08:49 -0000 1.1.2.4 +++ modules/user.rules.inc 17 Feb 2011 02:20:40 -0000 @@ -215,6 +215,26 @@ function rules_user_action_info() { 'label' => t('Unblock a use'), 'base' => 'rules_action_user_unblock', ); + + $items['user_send_account_email'] = array( + 'label' => t('Send account e-mail'), + 'parameter' => array( + 'account' => array( + 'type' => 'user', + 'label' => t('Account'), + ), + 'email_type' => array( + 'type' => 'text', + 'label' => t('E-mail type'), + 'description' => t("Select the e-mail based on your site's account settings to send to the user."), + 'options list' => 'rules_user_account_email_options_list', + ), + ), + 'group' => t('User'), + 'base' => 'rules_action_user_send_account_email', + 'access callback' => 'rules_user_integration_access', + ); + return $items; } @@ -233,5 +253,23 @@ function rules_user_roles_options_list($ } /** + * Options list callback for user account e-mail types. + * + * @see _user_mail_notify() + */ +function rules_user_account_email_options_list() { + return array( + 'register_admin_created' => t('Welcome (new user created by administrator)'), + 'register_no_approval_required' => t('Welcome (no approval required)'), + 'register_pending_approval' => t('Welcome (awaiting approval)'), + 'password_reset' => t('Password recovery'), + 'status_activated' => t('Account activation'), + 'status_blocked' => t('Account blocked'), + 'cancel_confirm' => t('Account cancellation confirmation'), + 'status_canceled' => t('Account canceled'), + ); +} + +/** * @} */