Sending notifications based on a cck node reference field

brettev - July 24, 2008 - 16:45
Project:Subscriptions
Version:5.x-2.0
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Basically, I want to send out notifications of a node creation if a user is subscribed to a node that is referenced using the cck node reference. I have a couple content types called Industry and Career, which are nodes I am controlling, and I want users (who can create their own images and video) to be notified when content has been created that references careers or industries that they are subscribed to. Does that make sense? I was looking at the code, and it seems that this might be done through a hook, or through modifying the subscriptions.module around line 189 in the subscriptions_queue function. Can someone point me in the right direction here? Thanks in advance for the help.

Brett

#1

salvis - July 24, 2008 - 17:08

Yes, hook_subscriptions_queue_alter() looks like a good way to do what you want. You'd check your conditions and create {subscriptions_queue} entries yourself for the users that meet your conditions.

Let us know how it goes.

#2

brettev - July 24, 2008 - 19:27

Thanks a ton for your help. I have the logic set up, I just need to know what to add to the rows to make sure it works how I think it should.

I should set module="node", but what do I do for field and value? Do I still use the load_args and load_function as the nid and subscriptions_content_node_load like the ones in there are? Also, does is_new = 1 and last_sent = 0? I'm sure these are pretty simple questions, but for all my searching, I can't seem to find what the rows I have in my table are doing there. Shouldn't they be cleared out when the email is sent?

Brett

#3

salvis - July 25, 2008 - 07:48

field determines which template (mailkey) you get and which mailvars_function. Try 'nid' and use the nid as value.

Yes, use load_args and load_function as given, unless you want to provide your own load_function() for some reason.

If the post is new, is_new should be 1, if it's only updated or commented, it should be 0. last_sent is copied from the user's {subscriptions_user} entry.

Yes, after cron has run and sent out the notifications, the corresponding entries in {subscriptions_queue} should be gone. All of this is done in subscriptions_cron().

#4

brettev - July 25, 2008 - 15:12

This is what I have so far. The first 2 are for nodes that reference them through a single select field, and the second two are for multi selects. Thoughts? Comments? Criticisms?

<?php
function sub_by_cckref_subscriptions_queue_alter(&$event) {
   
$node = $event['node'];
   
$mainindustry = $node->field_main_industry[0]['nid'];
    if (
is_numeric($mainindustry) and $mainindustry > 0) {
       
//trigger an email to everyone that is subscribed to this main industry
       
sub_by_cckref_add_to_queue($event, $node, $mainindustry);
    }
   
   
$maincareer = $node->field_main_career[0]['nid'];
    if (
is_numeric($maincareer) and $maincareer > 0) {
       
//trigger an email to everyone that is subscribed to this main career
       
sub_by_cckref_add_to_queue($event, $node, $maincareer);
    }
   
   
$industries = $node->field_industry_ref;
    if (
$industries) {
        foreach (
$industries as $key => $value) {
            if (
is_numeric($value) and $value > 0) {
               
//trigger an email to everyone that is subscribed to this industry
               
sub_by_cckref_add_to_queue($event, $node, $value);
            }
        }
    }
   
   
$careers = $node->field_career_ref_reqd;
    if (
$careers) {
        foreach (
$careers as $key => $value) {
            if (
is_numeric($value) and $value > 0) {
               
//trigger an email to everyone that is subscribed to this career
               
sub_by_cckref_add_to_queue($event, $node, $value);
            }
        }
    }
}

function
sub_by_cckref_add_to_queue($event, $node, $noderefid) {
   
//find all users subscribed to the mainindustry
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
$db_query("INSERT INTO {subscriptions_queue}
                (uid, name, mail, language, module, field, value, author_uid,
                send_interval, digest, load_args, load_function, is_new, last_sent)
                VALUES
                (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d,
                'subscriptions_content_node_load', %d, %d)"
,
               
$subuser->recipient_uid, $username, $useremail, $event['load_args'],
               
$node->uid, $event['load_args'], $event['is_new'], 0);
        }
    }
}
?>

#5

salvis - July 26, 2008 - 02:34

You must check that your $event really contains a node. Then use its nid, not load_args as value, and also pass on the load_function that you get, rather than hard-coding it. Finally, as I said before, last_sent should be taken from {subscriptions_user}.

Does it work?

#6

brettev - July 28, 2008 - 13:48

Thanks for the hints. I think I fixed them. Does this look a little better? I haven't turned the module on yet, I'm kind of waiting to pass it back and forth with some people first. I'm hoping to turn it on today though.

<?php
function sub_by_cckref_subscriptions_queue_alter(&$event) {
   
//global $user;
    //if($user->uid == 1) print_r($event);
   
if(is_set($event['node'])){
       
$node = $event['node'];
       
$mainindustry = $node->field_main_industry[0]['nid'];
        if (
is_numeric($mainindustry) and $mainindustry > 0) {
           
//trigger an email to everyone that is subscribed to this main industry
           
sub_by_cckref_add_to_queue($event, $node, $mainindustry);
        }
       
       
$maincareer = $node->field_main_career[0]['nid'];
        if (
is_numeric($maincareer) and $maincareer > 0) {
           
//trigger an email to everyone that is subscribed to this main career
           
sub_by_cckref_add_to_queue($event, $node, $maincareer);
        }
       
       
$industries = $node->field_industry_ref;
        if (
$industries) {
            foreach (
$industries as $key => $value) {
                if (
is_numeric($value) and $value > 0) {
                   
//trigger an email to everyone that is subscribed to this industry
                   
sub_by_cckref_add_to_queue($event, $node, $value);
                }
            }
        }
       
       
$careers = $node->field_career_ref_reqd;
        if (
$careers) {
            foreach (
$careers as $key => $value) {
                if (
is_numeric($value) and $value > 0) {
                   
//trigger an email to everyone that is subscribed to this career
                   
sub_by_cckref_add_to_queue($event, $node, $value);
                }
            }
        }
    }
}

function
sub_by_cckref_add_to_queue($event, $node, $noderefid) {
   
//find all users subscribed to the mainindustry
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
       
$lastsent = db_result(db_query("SELECT last_sent FROM {subscriptions_user} WHERE uid=%d", $subuser->recipient_uid));
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
$db_query("INSERT INTO {subscriptions_queue}
                (uid, name, mail, language, module, field, value, author_uid,
                send_interval, digest, load_args, load_function, is_new, last_sent)
                VALUES
                (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d,
                '%s', %d, %d)"
,
               
$subuser->recipient_uid, $username, $useremail, $node->nid,
               
$node->uid, $event['load_args'], $event['load_function'] ,$event['is_new'], $lastsent);
        }
    }
}
?>

#7

salvis - July 28, 2008 - 18:59

I don't see any obvious problems, but that doesn't mean much. I would single-step through this kind of code in a debugger to make sure that it does what I intend, and following the flow of control and inspecting variable values often reveals bugs.

#8

brettev - August 14, 2008 - 21:16

here's the working version. tested and awesome!! I had 4 fields I wanted to check against, so those are the 4 top parts.

<?php
function sub_by_cckref_subscriptions_queue_alter(&$event) {   
    if(
$event['module'] == 'node' and $event['action'] == 'insert'){
       
$node = $event['node'];               
       
$mainindustry = $node->field_main_industry[0][nid];
        if (
is_numeric($mainindustry) and $mainindustry > 0) {
           
sub_by_cckref_add_to_queue($event, $node, $mainindustry);
        }
       
$maincareer = $node->field_main_career[0][nid];
        if (
is_numeric($maincareer) and $maincareer > 0) {
           
sub_by_cckref_add_to_queue($event, $node, $maincareer);
        }
       
$industries = $node->field_industry_ref;
        if (
is_array($industries)) {
            foreach (
$industries as $value) {
               
$value = $value['nid'];
                if (
is_numeric($value) and $value > 0) {
                   
sub_by_cckref_add_to_queue($event, $node, $value);
                }
            }
        }
       
$careers = $node->field_career_ref_reqd;
        if (
is_array($careers)) {
            foreach (
$careers as $value) {
               
$value = $value['nid'];
                if (
is_numeric($value) and $value > 0) {
                   
sub_by_cckref_add_to_queue($event, $node, $value);
                }
            }
        }       
    }
}

function
sub_by_cckref_add_to_queue($event, $node, $noderefid) {
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
       
$lastsent = db_result(db_query("SELECT last_sent FROM {subscriptions_user} WHERE uid=%d", $subuser->recipient_uid));
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
db_query("INSERT INTO {subscriptions_queue} (uid, name, mail, language, module, field, value, author_uid, send_interval, digest, load_args, load_function, is_new, last_sent) VALUES (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d, '%s', %d, %d)", $subuser->recipient_uid, $username, $useremail, $node->nid, $node->uid, $event['load_args'], $event['load_function'] ,$event['is_new'], $lastsent);
        }
    }
}
?>

#9

salvis - August 14, 2008 - 21:11

Did you miss the closing tag? Please try to edit #8 and make it readable...

#10

brettev - August 14, 2008 - 21:16

fixed

#11

salvis - August 15, 2008 - 06:38

Nice work, congratulations!

Now that I think about it again, it would probably be better to call subscriptions_queue() rather than inserting directly into {subscriptions_queue}. This would give others a chance to hook_subscriptions_queue_alter (you'd get the call, too, and have to be prepared for it, of course) and insulate you a somewhat against changes in the database schema.

#12

greggles - August 29, 2008 - 17:20

This is _exactly_ what I need.

@brettev, are you interested in maintaining this as a module on drupal.org? If not, I would like to do so.

#13

brettev - August 31, 2008 - 00:35

I would maintain it, but it would have to be made generic and setup with an admin interface. I'm not sure if it would make it to drupal.org as is right now. Would you be interested in making it more generic with an admin page?

#14

greggles - September 1, 2008 - 14:26

@brettev - yes, now that I've played with it more I realize that it needs a bit more work in order to be generalized.

I'm not really sure how to make it more generic right now. I've built similar modules and think it is possible, but I'd need to dig into the CCK API again.

#15

aschiwi - November 7, 2008 - 13:30

Hi brettev,

I'm hoping to have some questions answered on your code. I am no coder but I think I could take the code you posted to modify and use it for me.

Here is my scenario: People would subscribe to a node of type "one". I want them to be notified when a node of type "two" has been created that references the node they are subscribed to. I think that is what your code does, but I don't know your setup. Could you generalize and comment the top part of your code (in function sub_by_cckref_subscriptions_queue_alter) a little bit, so that I can try and use it for myself?

#16

brettev - November 7, 2008 - 17:00

No problem. Happy to help. I've pulled out the 4 checks I had, and just left one of them to simplify things. It should make it easier for you to swap out.

You should leave the bottom function as is, and just modify the $node->field_main_industry[0][nid] to say $node->field_yourfieldname[0][nid].
this only works if it is a single node ref (drop down, not multiselect). The multi select you could pull off my code above.

Does this make sense?

<?php
function sub_by_cckref_subscriptions_queue_alter(&$event) {  
    if(
$event['module'] == 'node' and $event['action'] == 'insert'){
       
$node = $event['node'];    //this references the node that is being inserted. In your case, this would be type "two".          
       
$mainindustry = $node->field_main_industry[0][nid]; //this is the code that pulls the cck field (node reference), which is what the person is subscribed to (type 'one' for you)
       
if (is_numeric($mainindustry) and $mainindustry > 0) { //if this is a valid node reference, trigger subscription notifications to everyone that is subscribed to that type 'one' node
           
sub_by_cckref_add_to_queue($event, $node, $mainindustry);
        }
    }
}


/*
* this function takes the node and the REFERENCED id,
* (type one for you) and finds people who are subscribed
* to the type 'one' and sends them a notification for the node type 'two'
*/
function sub_by_cckref_add_to_queue($event, $node, $noderefid) {
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
       
$lastsent = db_result(db_query("SELECT last_sent FROM {subscriptions_user} WHERE uid=%d", $subuser->recipient_uid));
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
db_query("INSERT INTO {subscriptions_queue} (uid, name, mail, language, module, field, value, author_uid, send_interval, digest, load_args, load_function, is_new, last_sent) VALUES (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d, '%s', %d, %d)", $subuser->recipient_uid, $username, $useremail, $node->nid, $node->uid, $event['load_args'], $event['load_function'] ,$event['is_new'], $lastsent);
        }
    }
}
?>

#17

aschiwi - November 10, 2008 - 15:34

First of all, thank you for your quick help! Second, I didn't get it to work yet, I tried a few thinks but it's not happening. Could you take a look at my code? I changed the name of the module in the function, because I had already named it something else. I changed the name of my field (it happens to be multiselect because I need to prepopulate and hide the field for users) and figured I could leave $industries. In line 3 it now says $node = $event['two'];, which is probably wrong because you didn't tell me to change that to the name of my content type. BUT, writing 'node' instead of 'two' doesn't do it either. I'm sure though that somewhere I would have to put both "one" and "two", so that the module knows which content types I'm referring to?

<?php
function subscriptions_by_noderef_queue_alter(&$event) { 
    if(
$event['module'] == 'node' and $event['action'] == 'insert'){
       
$node = $event['two'];    //this references the node that is being inserted. In your case, this would be type "two".         
       
       
$industries = $node->field_noderef_arbeitsschritt_ref;
        if (
is_array($industries)) {
            foreach (
$industries as $value) {
               
$value = $value['nid'];
                if (
is_numeric($value) and $value > 0) {
                   
subscriptions_by_noderef_add_to_queue($event, $node, $value);
                }
            }
        }
    }
}


/*
* this function takes the node and the REFERENCED id,
* (type one for you) and finds people who are subscribed
* to the type 'one' and sends them a notification for the node type 'two'
*/
function subscriptions_by_noderef_add_to_queue($event, $node, $noderefid) {
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
       
$lastsent = db_result(db_query("SELECT last_sent FROM {subscriptions_user} WHERE uid=%d", $subuser->recipient_uid));
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
db_query("INSERT INTO {subscriptions_queue} (uid, name, mail, language, module, field, value, author_uid, send_interval, digest, load_args, load_function, is_new, last_sent) VALUES (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d, '%s', %d, %d)", $subuser->recipient_uid, $username, $useremail, $node->nid, $node->uid, $event['load_args'], $event['load_function'] ,$event['is_new'], $lastsent);
        }
    }
}
?>

#18

brettev - November 10, 2008 - 15:51

I'm guessing this should work. You are using a multi select for the field, right?

<?php
function subscriptions_by_noderef_queue_alter(&$event) {
    if(
$event['module'] == 'node' and $event['action'] == 'insert'){
       
$node = $event['node'];    //this should stay 'node' no matter what type you are using.   
      
       
$industries = $node->field_noderef_arbeitsschritt_ref;
        if (
is_array($industries)) {
            foreach (
$industries as $value) {
               
$value = $value['nid'];
                if (
is_numeric($value) and $value > 0) {
                   
subscriptions_by_noderef_add_to_queue($event, $node, $value);
                }
            }
        }
    }
}


/*
* this function takes the node and the REFERENCED id,
* (type one for you) and finds people who are subscribed
* to the type 'one' and sends them a notification for the node type 'two'
*/
function subscriptions_by_noderef_add_to_queue($event, $node, $noderefid) {
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
       
$lastsent = db_result(db_query("SELECT last_sent FROM {subscriptions_user} WHERE uid=%d", $subuser->recipient_uid));
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
db_query("INSERT INTO {subscriptions_queue} (uid, name, mail, language, module, field, value, author_uid, send_interval, digest, load_args, load_function, is_new, last_sent) VALUES (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d, '%s', %d, %d)", $subuser->recipient_uid, $username, $useremail, $node->nid, $node->uid, $event['load_args'], $event['load_function'] ,$event['is_new'], $lastsent);
        }
    }
}
?>

#19

aschiwi - November 10, 2008 - 16:22

Yes I am using a multiselect field. Not required, because it gets filled in anyways (by prepopulate, not by user). I tried your above code, but still not working yet. Checked my field again, because I am prepopulating the field with (for example) [nid:70] instead of the actual title of the node. I thought that might be it. But then I tried with writing the words in and it was the same. I guess I have to tackle this again tomorrow, probably missing something small...

#20

brettev - November 10, 2008 - 16:24

The code is set to work with node reference type fields. It won't work with a text field where you are putting the node id in.

#21

aschiwi - November 11, 2008 - 09:11

But it IS a node reference field... I am using the autocomplete kind. To get a node referenced, you can either type in the title of the node or type in [nid:40], "40" standing for whatever the nid is. For some reason I can't remember now, I couldn't get the title information into the nodereference field by using prepopulate. But either way, I tried the code by typing in the actual title of the referenced node and it didn't work. I have to try again today, will let you know what works out for me in the end :-)

#22

aschiwi - November 13, 2008 - 08:46

So with some help of a friend I finally managed to do this. It was my mistake, on line 1 I didn't see that it had to be modulename_SUBSCRIPTIONS_queue_alter...
And by the way, it works wether the nodereference field has the title of the referenced node in it OR the nid (in the [nid:1] pattern). We use prepopulate to put the nid in the nodereference field because sometimes the title of a node might be too long for it, and then it wont get referenced right.

Thanks again for your help.

<?php
function sub_by_cckref_subscriptions_queue_alter(&$event) { 
    if(
$event['module'] == 'node' and $event['action'] == 'insert'){
       
$node = $event['node'];    //this references the node that is being inserted. In your case, this would be type "two".         
       
$arbeitsschritt = $node->field_noderef_arbeitsschr;
        if (
is_array($arbeitsschritt)) {
            foreach (
$arbeitsschritt as $value) {
               
$value = $value['nid'];
                if (
is_numeric($value) and $value > 0) {
                   
sub_by_cckref_add_to_queue($event, $node, $value);
                }
            }
        }
        
$aktivitaet = $node->field_noderef_arbeitspaket_v_ak;
        if (
is_array($aktivitaet)) {
            foreach (
$aktivitaet as $value) {
               
$value = $value['nid'];
                if (
is_numeric($value) and $value > 0) {
                   
sub_by_cckref_add_to_queue($event, $node, $value);
                }
            }
        }       
    }
}


/*
* this function takes the node and the REFERENCED id,
* (type one for you) and finds people who are subscribed
* to the type 'one' and sends them a notification for the node type 'two'
*/
function sub_by_cckref_add_to_queue($event, $node, $noderefid) {
   
$subusers = db_query("SELECT recipient_uid FROM {subscriptions} WHERE field='nid' AND value=%d ", $noderefid);
    while (
$subuser = db_fetch_object($subusers)) {
       
$userrow = db_fetch_object(db_query("SELECT name, mail FROM {users} WHERE uid=%d", $subuser->recipient_uid));
       
$username = $userrow->name;
       
$useremail = $userrow->mail;
       
$lastsent = db_result(db_query("SELECT last_sent FROM {subscriptions_user} WHERE uid=%d", $subuser->recipient_uid));
        if (
is_numeric($subuser->recipient_uid) and $subuser->recipient_uid > 0 and strlen($username) > 0 and strlen($useremail) > 0) {
           
db_query("INSERT INTO {subscriptions_queue} (uid, name, mail, language, module, field, value, author_uid, send_interval, digest, load_args, load_function, is_new, last_sent) VALUES (%d, '%s', '%s', '', 'node', 'nid', %d, %d, 1, -1, %d, '%s', %d, %d)", $subuser->recipient_uid, $username, $useremail, $node->nid, $node->uid, $event['load_args'], $event['load_function'] ,$event['is_new'], $lastsent);
        }
    }
}
?>

#23

Flying Drupalist - November 26, 2008 - 13:37

Hi, is this going to become a module?

#24

brettev - November 27, 2008 - 04:59

http://www.brettevanson.com/module/subscriptions-cck-node-reference

I haven't tested it as it is, but it should work. Let me know if it works for you.

#25

salvis - November 29, 2008 - 12:20

Hi, is this going to become a module?

I don't understand it well enough to tell whether it's sufficiently general to become a subscriptions/contrib, nor whether brettev wants to contribute it and continue to support it, but I'm certainly open to contributions.

#26

brettev - November 30, 2008 - 03:41

I need a few people to use it and post feedback about whether it works for their needs or not. If enough people use it and have a good experience with it, then we can push for include into the subscriptions contrib section.

Brett

#27

Flying Drupalist - November 30, 2008 - 15:55

Oh, I'm on 6.6. Can't use this yet. :(

#28

brettev - December 1, 2008 - 15:29

I updated the module with a new table name. As far as why it's not showing up in your list, I am not sure. That's a troubleshooting issue, not an issue with this module specifically. Could you have the files in the wrong directory?

#29

Flying Drupalist - December 1, 2008 - 16:32

Hi, you must be seeing an old version of my post. I updated it yesterday. I'm on 6.6, and originally I was confused because I couldn't find a checkbox under the subscription category in the module listing, where I assumed it would be. Then I realized that this was a 5.x issue and I couldn't use the module in any case. A 6.x port would be appreciated, sorry for the trouble.

#30

aschiwi - December 19, 2008 - 09:21

I didn't try your module but I am using the code you provided here in a custom module. What I just realized is missing from that code is that there are no notifications sent out when the node is updated, which is something I need and added to my code. I looked at the code of your module and I think you don't have 'update' in there either (though I am by no means a coder, maybe I just didn't see).

In line 52 of your module it says

<?php
if($event['module'] == 'node' and $event['action'] == 'insert') {
?>

The same line is in the code I got from you before and I added the update part so now it looks like this:

<?php
if($event['module'] == 'node' && (($event['action'] == 'insert') || ($event['action'] == 'update'))) {
?>

#31

parrottvision - February 3, 2009 - 03:05

subscribing - would love to see this in 6 as a part of module.

#32

MJH - February 28, 2009 - 22:59

This is exactly the functionality I am looking for.
Will this be included in the Drupal 6 version of Subscriptions or will there be an external module?

Is there another "Subscription / Notification" module already working under Drupal 6, that can inform a user subscribed to a node if that node is referenced in another node?

#33

gunzip - April 5, 2009 - 15:49

subscribe ;)

#34

gunzip - April 6, 2009 - 10:46

well maybe there's a simple way with nodeapi intercepting the insert of a node with a reference field:

function mymodule_nodeapi(&$node, $op, $params = NULL, $page = NULL) {
  switch ($op) {
    case 'insert':
      if (isset($node->field_referred_ref[0]['nid'])) {
        $ref   = node_load($node->field_referred_ref[0]['nid']);
        $event = array(
          'module'        => 'node',
          'uid'           => $ref->uid,
          'load_function' => 'subscriptions_content_node_load',
          'load_args'     => $ref->nid,
          'type'          => 'node',
          'action'        => $op,
          'is_new'        => TRUE,
          'node'          => $ref,
        );
        subscriptions_queue($event);
      }
}

i think this could be merged into the subscriptions_cck nodeapi
(you have to loop through all the nids if you have a multi value field...)

#35

lelizondob - September 5, 2009 - 18:48

subscribe

 
 

Drupal is a registered trademark of Dries Buytaert.