Hello,

Just grabbed the new Leech for drupal 5.x and when I update the leech items, it tells me that the group settings of child items were updated but nothing is actually happening. I have the template story and the feed story both set to automatically go into an organic group I have setup, but it leaves the child items with no group association at all.

Any advice?

CommentFileSizeAuthor
#7 leech.txt100.39 KBtonythemediaguy

Comments

tonythemediaguy’s picture

Just a test, I installed the new 5.x Aggregator module and set it up with the same feed info as Leech. When it updated it's feed, it did mark the feed's items as belonging to the appropriate groups. I thought the problem might be with OG, but after this I'm confident it's in the way that Leech updates the items with OG info.

tonythemediaguy’s picture

Title: Leech + Organic Groups = not updating child feed items » Leech + Organic Groups = not updating audience

Leech isn't writing anything to the og_ancestry table, so I added this at line 2603:

		$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) 
                  VALUES (%d, %d, 1)";
          db_query($sql, $n->nid, $gid);

It adds them in everytime the cron is run, creating hundreds of duplicates in the og_ancestry table but for now it's solving my small issue.

But along with Leech not using the audience correctly, it's also not sending out the og emails for those who subscribed to the group.

kaerast’s picture

OK, well the obvious next steps now are to add some conditions to that statement:

a) detect if organic groups is installed
b) do a "SELECT count(*) FROM {og_ancestry} WHERE nid = $n->nid AND group_nid = $gid" in order to avoid duplicates.

Should leeched items really be public though? We're presuming they should be public because they are available elsewhere - but that might not be the case.

I'm assuming there's a better way of doing this, one which will use OG APIs to send out the group email and set group details. I haven't got time to investigate myself though.

tonythemediaguy’s picture

Here is the code that Leech uses to call up OG:

/**
* private function,
* for being called in nodeapi submit hook
* passes on group settings of feed node to all related feed items
*
* @param unknown_type $node
*/
function _leech_news_pass_on_groups(&$node) {
 
  if (!module_exists('og')) {
    return;
  }

  if (!is_array($node->og_groups)) {
    return;
  }
 
  if (!isset($node->nid)) {
    return;
  }

  timer_start("ogpass");
 
  $r = db_query("SELECT DISTINCT nid FROM {leech_news_item} WHERE fid = %d", $node->nid);
  $updated = 0; $total = 0;
  while ($n = db_fetch_object($r)) {

    db_query("DELETE FROM {node_access} WHERE nid = %d AND realm LIKE '%s'", $n->nid, 'og_%');
   
    if (is_array($node->og_groups)) {
      foreach ($node->og_groups as $gid) {
        if ($gid != 0) {
          $sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete)
                  VALUES (%d, %d, 'og_subscriber', 1, 1, 1)";
          db_query($sql, $n->nid, $gid);
         
           $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public)
                  VALUES (%d, %d, 1)";
                   db_query($sql, $n->nid, $gid);

          if ($node->og_public) {
            $sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'og_public', %d)";
            db_query($sql, $n->nid, $gid);
          }
        }
      }
    }
 
    // if the public checkbox was selected, give a universal grant for this node
    if ($node->og_public) {
      $sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'og_all', 1)";
      db_query($sql, $n->nid);
    }
    $updated++;
  }
 
  if ($updated > 0) {
    drupal_set_message("Group settings of ".$updated." child feed item(s) updated in ".timer_read("ogpass")." ms", "status");
  }
  // Transform the $node->og_groups according to the og_submit_group taste
  foreach($node->og_groups as $gid) {
    $transformed_groups[$gid] = $gid;
  }
  $node->og_groups = $transformed_groups;
  timer_stop("ogpass");
}

As far as everything being public, for now that's ok for my purpose, but would ultimately need to choose what is public and what isn't.

tonythemediaguy’s picture

OK, I got Leech and OG working pretty well for now by adding the DELETE FROM right before it puts the articles into the og_ancestry table. This keeps the duplicate entrys from happening. Works great.

But it doesn't send out the emails to those who have subscribed to the group. How can I call up the function in organic groups from leech that sends out the emails? In the og_module the function is called og_mail but I don't know enough about php to tell this function to run everytime Leech updates these groups.

Any help is appreciated.

    if (is_array($node->og_groups)) {
      foreach ($node->og_groups as $gid) {
        if ($gid != 0) {
          $sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) 
                  VALUES (%d, %d, 'og_subscriber', 1, 1, 1)";
            db_query($sql, $n->nid, $gid);
	
		$sql = "DELETE FROM {og_ancestry} WHERE nid = $n->nid AND group_nid = $gid";
	    	db_query($sql, $n->nid, $gid);

		$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) 
                  VALUES (%d, %d, 1)";
              db_query($sql, $n->nid, $gid);
          
          if ($node->og_public) {
            $sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'og_public', %d)";
            db_query($sql, $n->nid, $gid);
          }
        }
      }
    }
aron novak’s picture

Thanks for your efforts trying to make leech work with og! Can you send me a patch: 1.6 vs. current state of your code?
As I understood you almost reached that leech + og works smoothly, only the email sending don't work, right?
When I receive your patch I'll find a solution to fix this remaining issue.

tonythemediaguy’s picture

StatusFileSize
new100.39 KB

Hi,

I'm not sure how to submit the patch. I am attaching my leech.module file to this post. The only lines that were changed/altered, were 2605 through 2609. I commented in the file so you can find it. Here is what I added to get it working:

   $sql = "DELETE FROM {og_ancestry} WHERE nid = $n->nid AND group_nid = $gid";
	      db_query($sql, $n->nid, $gid);

		  $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, 1)";
          db_query($sql, $n->nid, $gid);
alex_b’s picture

Status: Active » Fixed

Hi Tony,

I just tested your suggestion with OG 2.2 and it does it for me too...

I committed it to the 5.x version ( http://cvs.drupal.org/viewcvs/drupal/contributions/modules/leech/leech.m... )

On a more general note: I am aware that og support is experimental. Specifically we should actually not directly meddle with OG's datastructure (sql statements) but rather manipulate nodes and store them using the node_save() function.

However, the latter approach was always a little too slow for retroactive group changes - that is batch updating huge sets of feed items when you change the group settings on their source feed node.

I would be happy though if somebody came up with a patch that manipulates og settings on a node level in the default setting and provides retroactive changes of group settings with a direct write to the og datastructure only as experimental setting.

I change the status of this thread to fixed.

PS: here is how to submit a patch: http://drupal.org/patch/create

alex_b’s picture

Status: Fixed » Closed (fixed)

in 5.x-1.7