This is a great module. The role syncing feature is exactly what I need, however, it's not working for my use case because I am using Rules to assign roles. It appears that when roles are added and removed via rules, the mailman sync doesn't happen. The users don't get subscribed/unsubscribed to the lists. Is there a way to make the syncing happen even when roles are changed via rules? Or expose some UMR actions to rules so I can make it part of the ruleset? For example, if my rule includes "Load referenced user" and "Assign role X", I could add "Sync User Mailman Registrations" to make sure the subscriptions are updated to match the new role assignments.

Comments

walkerasindave’s picture

Issue summary: View changes

I threw together a quick addon module that adds some basic rules integration. This is the first bit of coding I've ever done for Drupal so its probably not very good but feel free to use it. I'm also not sure if its worthwhile uploading to the Drupal repository or maybe someone wants to patch it into User Mailman Register itself.

It adds a new rules action that allows you to specify a user, a list and a subscription status.

In an ideal world I think it would also add integration to have mailing lists as entities, would make more dynamic selection possible.

umr_rules.info

name = User Mailman Register Rules Integration
description = "This is a module that integrates User Mailman Register with Rules within Drupal."
package = Mailman
core = 7.x
version = 1.x-1.0

dependencies[] = rules
dependencies[] = user_mailman_register
files[] = umr_rules.module

umr_rules.rules.inc

<?php
/**
 *Everything in umr_rules.rules.inc
 */

umr_rules.rules.inc

<?php
/**
 *Implements hook_rules_action_info
 *Adds action to rules
 */
function umr_rules_rules_action_info() {
	$actions = array(
		'umr_rules_mailman_subscribe' => array(
			'label' => t('Set mailman subscription status for specified user'),
			'group' => t('Mailman'),
			'parameter' => array (
				'account' => array (
					'type' => 'user',
					'label' => t('User to set subscription status for'),
				),
				'list' => array (
					'type' => 'text',
					'label' => t('Name of Mailman list to set subscription status for'),
					'options list' => 'umr_rules_mailman_lists_list',
					'restriction' => 'input',
				),
				'new_status' => array (
					'type' => 'text',
					'label' => t('Subscription status'),
					'options list' => 'umr_rules_mailman_subscription_status',
					'restriction' => 'input',
				),
			),
		),
	);
	
	return $actions;
}

/**
 *Subscribes/unsubscribes a user account to a list with the required status
 *$account - The user account
 *$list - The list ID of the mailman list
 *$new_status - The integer value of the new status
 */
function umr_rules_mailman_subscribe($account, $list, $new_status) {
	$lista = get_object_vars(_user_mailman_register_get_list($list));
	$subscription = _user_mailman_register_get_remote_status($account, $lista, $account->mail);
	$user_status = array(
		'old_status' => $subscription['lstatus'],
		'new_status' => $new_status,
		'lmod' => $subscription['lmod'],
	);

	_user_mailman_register_update_remote($account,$lista,$user_status,$account->mail,TRUE);
}

/**
 *Returns an array of all the mailman lists with the list id as the key
 */
function umr_rules_mailman_lists_list() {
	$listnames = array();
	foreach (_user_mailman_register_get_lists() as $list) {
		$lid = $list['lid'];
		$listnames[$lid] = $list['name'];
	}
	return $listnames;
}

/**
 *Returns an array of all the available subscription statuses
 */
function umr_rules_mailman_subscription_status() {
	$user_status = array(
		USER_MAILMAN_REGISTER_SUBSCRIBED_NORMAL => t('Subscribe (normal)'),
		USER_MAILMAN_REGISTER_SUBSCRIBED_DIGEST => t('Subscribe (digest)'),
		USER_MAILMAN_REGISTER_SUBSCRIBED_DISABLED => t('Subscribe (disbaled)'),
		USER_MAILMAN_REGISTER_DO_UNSUBSCRIBE => t('Unsubscribe'),
	);
	return $user_status;
}
walkerasindave’s picture

Note, the above is for the 7x branch.

rjlang’s picture

Status: Active » Closed (won't fix)

Looks fine as a separate module. No plans to integrate it into UMR.