CVS Agg2, Drupal 4.7, and autotaxonomy module

redraven - May 10, 2006 - 11:27
Project:Aggregator2
Version:HEAD
Component:Code
Category:bug report
Priority:critical
Assigned:budda
Status:active
Description

Hi,

Just installed agg2 on a fresh 4.7 install.

Was having problems getting the autotaxonomy mini-module working.

I've created some feeds with rss feeds that I know have category tags (some of the same feeds are also running on a 4.6 site with agg2 and autotaxonomy, and everything is working fine) but nothing seems to get generated for taxonomy terms when i update the feed on the 4.7 install.

Does autotaxonomy work with the cvs version of agg2 on 4.7?

Thanks for any advice or tips

#1

Christoph C. Cemper - May 22, 2006 - 11:51

I'm interested in this one, too... any comments?

#2

colorado - May 23, 2006 - 17:59

Heyho,

I haven't been able to get Agg2 from cvs to work on my fresh 4.7.0 install. What Agg2 version are you using - did you patch it? If so, with what patch(es)? And with what combination of options in the settings?

(Currently the feeds themselves appear to be working properly (giving no error messages), but refreshing the feed always generates "0 new items" (I have the same feed working perfectly on a patched 4.6.5 installation.)

Thanks!

#3

voidberg - May 31, 2006 - 09:37

Same problem happens to me too. The same thing occurs after patching taxonomy module.

#4

Christoph C. Cemper - June 1, 2006 - 08:12

I have mixed results...

I get one feed with 0 results,
then the other one works fine...

took the normal 4.7 dist and the latest agg2 module

however I get A LOT of "duplicate-key" errors for the term_node table when updating

christoph

#5

mlh - June 16, 2006 - 00:26
Category:support request» bug report
Status:active» reviewed & tested by the community

In aggregator2_autotaxonomy.module On line 30
Change
if($node->type == 'aggregator2-item' && isset($node->rss_item_data)) {
to
if($node->type == 'aggregator2_item' && isset($node->rss_item_data)) {

That should fix the issue.

#6

budda - June 16, 2006 - 17:50
Assigned to:Anonymous» budda
Status:reviewed & tested by the community» fixed

Change committed thanks!

#7

Richard Eriksson - June 22, 2006 - 06:50
Status:fixed» active

I updated to the latest CVS version (which has the aggregator2-item => aggregator2_item fix) and still can't get categories in items' <category> elements to apply correctly to aggregator2 items.

#8

Richard Eriksson - June 23, 2006 - 07:59
Priority:normal» critical

#9

budda - June 30, 2006 - 09:48

Are the category terms getting created correctly in your taxonomy now though?

#10

Richard Eriksson - July 2, 2006 - 02:47

The best I can tell is that aggregator2_autotaxonomy.module works correctly (that is, based one some print_r debugging I did, aggregator2_autotaxnomy would identify the categories from the RSS feed and put them into an array), it's just that once aggregator2.module gets a hold of it, it will only apply the category that comes as from the setting in the feed item node, not the tags in the RSS feed.

#11

Christoph C. Cemper - July 6, 2006 - 22:58

agree with Richard

#12

agentrickard - July 11, 2006 - 13:38

I'm trying to track this problem as well. Here's what I have so far.

Using CVS of aggregator2 and aggregator2_autotaxonomy on fresh 4.7.2 install.

In line 76-78 of aggregator2_autotaxonomny.module we have this line:

                $term = taxonomy_save_term($term);
                $node->taxonomy[] = $term['tid'];
                $cat_names[$category_name][0]->tid = $term['tid'];

The intent here is to save a new term (if needed) and use the $term var to set the taxonomy for the node to be saved.

But http://api.drupal.org/api/4.7/function/taxonomy_save_term taxonomy_save_term does not return a $term object. It only returns a $status message. So the $term['tid'] is never set.

I think we have to grab the $term data by name in order for this function to work.

                taxonomy_save_term($term);
                $term = taxonomy_get_term_by_name($term['name']);               
                $node->taxonomy[] = $term['tid'];
                $cat_names[$category_name][0]->tid = $term['tid'];

Will explore more.

#13

agentrickard - July 11, 2006 - 20:32

I think I'm near a solution, but may be off base. It looks like the module is having trouble with changes to taxonomy_node_save() in 4.7 -- specifically formatting of the $node->taxonomy variable.

Hopefully this is helpful.

Before I go on, two apologies.

1) I haven't tested this thoroughly. Only for my setup.
a) I am inserting tags into feed items using a 4.7 free-tagging vocabulary.
b) I want to insert both the feed tags and the items category tags for each item

2) I haven't rolled a patch because I haven't learned CVS.

Here's what I changed.

aggregator2.module function aggregator2_parse_items() line 1985

     //   $edit->taxonomy = $feed->feed_item_taxonomy;
        $terms = module_invoke('taxonomy', 'node_get_terms', $edit->fid, 'tid');
        foreach ($terms as $tid => $term) {
          if ($term->tid) {
            $edit->taxonomy[$tid] = $term;
          }
        }    

This gives us the taxonomy object in the same format as for saveing feeds.

Aggregator2_autotaxonomy.module function aggregator2_autotaxonomy_nodeapi(), line 47.

      case 'insert':
      case 'update':
      // The aggregator2 module uses hook_prepare, so we need to account for it     
      case 'prepare':

Lines 69:

              // Create a new category term
              if (count($cat_names[$category_name]) == 0) {
                $term = array();
                $term['name'] = $category_name;
                $term['description'] = t('Auto generated by aggregator2 autotaxonomy');
                $term['vid'] = $vocab;
                $term['weight'] = 0;
                // broken
                //$term = taxonomy_save_term($term);
                taxonomy_save_term($term);
                $terms = taxonomy_get_term_by_name($term['name']);    
                foreach ($terms as $term) {
                  $node->taxonomy[$term->tid] = $term;               
                }

Line 80:

              else {
                // Use the existing category term in the database
                if (!in_array($cat_names[$category_name][0]->tid, $node->taxonomy)) {
                  $terms = taxonomy_get_term_by_name($cat_names[$category_name][0]->name);
                  foreach ($terms as $term) {
                    $node->taxonomy[$term->tid] = $term;               
                  }                 

And here's what I get as a $node-taxonomy object on save:

    [taxonomy] => Array
        (
            [14] => stdClass Object
                (
                    [tid] => 14
                    [vid] => 1
                    [name] => celebrities
                    [description] =>
                    [weight] => 0
                )
        )

This works for new node creation. Seems to work also when editing an existing node.

#14

agentrickard - July 11, 2006 - 20:52

One additional change.

Line 64 of aggregator2_autotaxonomy():

            $category_name = trim($category_name);
            if ($category_name != '') {

The current code: if (trim($category_name) != '') does not actually trim() the variable, which I think is necessary.

#15

Richard Eriksson - July 14, 2006 - 14:46

I'm attaching a patch made from the above code. I tested it and it updated old feed items along with keeping the taxonomy terms for new items. A couple of bugs remain, as far as I can tell

  • the feed's taxonomy terrm does not seem to be applied (that is, in the feed node itself, if you choose a taxonomy term, that term is not applied to feed items)
  • if you choose "Apply changes to already existing items after feed is re-edited" when editing the feed node, you lose all the taxonomy terrm info for the feed items

This gets us closer to fixing this issue, Ken.

AttachmentSize
aggregator2-item-terms.patch.txt 3.26 KB

#16

Richard Eriksson - July 14, 2006 - 14:56

Another issue with the patch is that on the updated feed items, it dupilcates some tags if you're using free-tagging.

#17

agentrickard - July 15, 2006 - 16:47

Here's a copy of the module as I have it in production right now. It fixes the duplication issues.

Again, sorry for the lack of a proper patch.

AttachmentSize
aggregator2_autotaxonomy.module 7.39 KB

#18

agentrickard - July 15, 2006 - 16:49

Soory. That last copy still has some debugging statements in it.

AttachmentSize
aggregator2_autotaxonomy_0.module 7.39 KB

#19

agentrickard - July 17, 2006 - 16:53

OK. Progress. I added a routine to kill duplicate taxonomy terms that were showing up. I'm still not sure where they were coming from. I think aggregator2 is putting them in.

Anyway, I have this version running, error-free at http://www.rubybaboon.com/

AttachmentSize
aggregator2_autotaxonomy_1.module 7.17 KB

#20

agentrickard - July 17, 2006 - 21:28

Alright one more time. After the last patch, the assigned item_taxonomy from the aggregator2_feed table wasn't getting saved. So I forced it into the aggregator2_autotaxonomy module.

Maybe not the best solution but I think it's working. (Again).

AttachmentSize
aggregator2_autotaxonomy_2.module 7.63 KB
 
 

Drupal is a registered trademark of Dries Buytaert.