Hi,

I've added a patch to your module to get ALL static Contact Groups from Addemar.
Before you had:

$mail_groups = $s_client->getMailgroupsByType(1);

Which doesn't give me the groups I need... They just give that specific type of group.
I need all (static) Contact Groups.

I've written a patch that will add the description (Addemar produces hidden groups apparently, when your Contact Group is listed under 'subscription list') to the list in the module. It will also load every (static) contact group.

Comments

Gleach created an issue. See original summary.

Gleach’s picture

StatusFileSize
new9.27 KB

I've updated the patch.
Last patch had a conflict with the variable: '$key'.

Above all I fixed the the way data is passed to (with) soap.
Now I couldn't let Addemar (in Drupal) subscribe in several groups, eventhough I selected them!
It's fixed now. I'm passing an array of keys, instead of a string with keys seperated by a comma.

now: array(0 => id1, 1 => id2,..)
before: string (id1,id2,id3,...)

Now: Contact group with id2 will also be subscribed to.
Before: only id1 would be subscribed too.

Using version 1.5.

bart.hanssens’s picture

Assigned: Unassigned » stefan.r
stefan.r’s picture

Status: Needs review » Needs work
  1. +++ b/profiles/openfed/modules/contrib/addemar_subscription/includes/addemar_subscription.functions.inc
    @@ -51,17 +51,29 @@ function _addemar_subscription_add_more_newsletter_form($key, $weight, $group =
    +      catch (Exception $e) {
    +      }
    

    Should this silently fail?

  2. +++ b/profiles/openfed/modules/contrib/addemar_subscription/addemar_subscription.module
    @@ -222,8 +222,8 @@ function addemar_subscription_subscribe_form() {
    +          '#title' => t(check_plain($label)),
    
    @@ -233,15 +233,15 @@ function addemar_subscription_subscribe_form() {
    +      '#value' => t(variable_get_value('addemar_subscription_submit_button')),
    

    Unrelated as the issue was already in the module, but this is incorrect usage of t() (can be fixed in a followup)

  3. +++ b/profiles/openfed/modules/contrib/addemar_subscription/addemar_subscription.module
    @@ -312,16 +312,21 @@ function addemar_subscription_subscribe_form_submit($form, &$form_state) {
    +          if ($id != 0) {
    

    Can we add a comment about why we skip group 0?

  4. +++ b/profiles/openfed/modules/contrib/addemar_subscription/addemar_subscription.module
    @@ -312,16 +312,21 @@ function addemar_subscription_subscribe_form_submit($form, &$form_state) {
    +            if (!is_numeric($cid)) {
    +              $success = FALSE;
    +            }
    

    When would this be not numeric? And do we need to log any information here?

  5. +++ b/profiles/openfed/modules/contrib/addemar_subscription/includes/addemar_subscription.functions.inc
    @@ -51,17 +51,29 @@ function _addemar_subscription_add_more_newsletter_form($key, $weight, $group =
    +      if (isset ($mail_groups)) {
    

    Coding standards nitpick: should be isset( rather than isset (

  6. +++ b/profiles/openfed/modules/contrib/addemar_subscription/includes/addemar_subscription.functions.inc
    @@ -51,17 +51,29 @@ function _addemar_subscription_add_more_newsletter_form($key, $weight, $group =
    +          if ($group_data->type == '1') {
    

    Do special groups always have type 1?

Gleach’s picture

1) We/you can set a watchdog message or error message

2) The variable_get_value can be set into a variable. That $var can be used into the t(), would that be ok?

3) Apparently this should be wrong. I thought contact groups started with id: '1'. If my source is right, id 0 does exist. making this if-statement excessive. The account where I have access to does not have a contact group with id 0. So this have to be looked at.

4) This is your/the original code... It's basically an extra check that's been tested there. If $cid somehow turned out to be a string, it will throw a drupal error message.

  // Check return.
  if ($success) {
    drupal_set_message(variable_get_value('addemar_subscription_message_success'), 'status');
  }
  else {
    drupal_set_message(variable_get_value('addemar_subscription_message_error'), 'error');
  }

5) Weird, I have an auto-indenter which has been fine-tuned on Drupal coding standards. But you're absolutely right.

6) According to your/original code: yes. I have no idea why only static-groups are allowed in the first place. You will probably have your reasons. This could be an extension later on?
For now it's ok for me to work with static-groups only, as you/original code had intended.

stefan.r’s picture

OK, awaiting your new patch! Don't worry about 2, we can fix that elsewhere.

Gleach’s picture

StatusFileSize
new11.51 KB

1,2,3 and 5 should be fixed now.
Can re-check the patch again and test it pls?

stefan.r’s picture

Status: Needs work » Reviewed & tested by the community

Look OK to me

Gleach’s picture

Priority: Normal » Critical
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.01 KB

Critical:

Due to some local problems, my patch wasn't complete.

If you apply last patch to the module, the module will not work properly.
You won't be able to create more than one group in Addemar back-end.

Why? If you look at my new patch, you'll see I adjusted the key of the foreach loop (which wa $key). This is quite necessary...
If you see which argument is passed with the function (_addemar_subscription_add_more_newsletter_form), you'll see that an argument is called "$key".

Therefore I'm completely letting the module crash, when it the function is being called.
Simple fix: rename the key of the foreach.

My apologies for any inconveniences.

  • stefan.r committed 9031eee on 7.x-1.x authored by Gleach
    Issue #2658814 by Gleach: All Static Contact Groups
    
stefan.r’s picture

Status: Needs review » Fixed

Committed, thanks.

stefan.r’s picture

$s_client->getMailgroupsByType() gives SoapFault: contact group not found in SoapClient->__call() as of today -- I assume Addemar's API has changed?

Gleach’s picture

Yes, because not all 'keys' are legit as they can crash the whole app.
Therefore the try-catch was used for.
But probably it's better to NOT let the soap call 'try'.

      try {
        $mail_groups = $s_client->getMailgroupsByType($group_key);
      }
      catch (Exception $e) {
        watchdog('error', $e->getMessage());
      }

Anyway, I've hard-coded checked on the possible values, which I do not like. But I don't see any other way?

0	no special
1	unsubscribers list
2	test list
4	reporting list
6	subscription list
7	unsubscription list

See the patch in attachments. The patch is build on the last patch.
So basically, if you apply this patch (https://www.drupal.org/node/2658814#comment-11028833 ), than you can apply this patch.
Is this ok? Or do I need to commit a whole new patch starting from the current active version?

btw: Addemar has no updates, or no updates that influences the module for as far I can see?
Patch tested on Addemar Web Service v1.5 & v1.4

stefan.r’s picture

We only have the SOAP error as of today. Maybe it's due to a change our the settings, but it looks like their API changed. So I've emailed them about this, perhaps they can fix it on their side.

But the problem is not the one in this patch... it's another line:

$groups_ids = $s_client->getMailgroupsByType();

So we'd probably need to loop through the IDs instead of doing a call to getMailgroupsByType() without any arguments.

stefan.r’s picture

Status: Fixed » Needs review
StatusFileSize
new910 bytes

How about this?

  • stefan.r committed fbea250 on 7.x-1.x
    Issue #2658814: All Static Contact Groups
    
Gleach’s picture

Status: Needs review » Reviewed & tested by the community

This could and will work. Then again, I still don't like the idea that the id's are hardcoded.
On the other hand, if you look to previous addemar versions, then you'll notice that they didn't change the id's.

stefan.r’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.