First off, thanks for this module. It really pushes Feeds and allows us to easily pull data from external systems that don't output a flat feed of all data.

Here is a description of my importers:

  1. One importer creates feed nodes from a list of users
  2. Second importer is a selfnode importer that populates these feed nodes

After running the importer which generates feed nodes from a list, it shows '600 nodes imported'. I can then use the 'Delete items' tab on the importer to mass delete and reimport them easily.

The problem I am running into is when these feed nodes self-import, they are no longer 'tracked' by the first importer I've created. If it originally imported 600 nodes, and 100 of those have self-imported, only 500 are shown on the first importer under '# imported items total'. If I choose to 'Delete items' (expecting to delete all 600 that it created), it only deletes the 500 that have not been self-imported. I then have to manually delete the other 100.

Comments

vinmassaro’s picture

It seems like once feed nodes self-import, they are then 'owned' by that importer and not by their source importer. Any hints to where this happens in code would be great as I am more than willing to write a patch. Thanks.

twistor’s picture

Assigned: Unassigned » twistor

This is a tricky one. I think the current behavior is "correct" in that a the node does own itself. But, it can be a pain.

twistor’s picture

Status: Active » Needs review
StatusFileSize
new1.4 KB
vinmassaro’s picture

@twistor: thanks for the patch, but still no luck. Still seeing the same behavior from the original post.

twistor’s picture

Ahh, it won't switch the items back to being owned by the correct importer, but if you run the master importer they should switch and stay that way.

I realized the correct way to fix this is to create our own tracking table, real patch coming.

vinmassaro’s picture

Hmm, I deleted all nodes, did a fresh import off 600 items, self-imported 50, and it showed 550 imported items when I went to delete. I ran the import again, it said no new items, but the number imported did not change. I then deleted and it only deleted the 550.

arh1’s picture

Status: Needs review » Needs work

I missed this issue before, but as I work through #2023735: Selfnode processing deleting feed_item db rows, leading to duplicates I'm pretty sure it's a duplicate.

The fundamental issue seems to be that Feeds and Feeds Self Node Processor are competing for the same primary key in feeds_item (entity_type+entity_id), so they'll always create two separate records. The patch in #3 doesn't address that.

@twistor, in #5 it sounds like you're suggesting a table something like feeds_self_node_processor_item . I'm happy to help with a patch, though you'd bang it out much more quickly than I :)

arh1’s picture

Status: Needs work » Needs review
StatusFileSize
new9.61 KB

Here's an initial, very rough pass at a patch. It creates the new feeds_selfnode_processor_feed_item table, and uses that to track self-processing feed node items.

As well as a general review of the approach, there are 3 todo's marked in the code. Let me know your thoughts!

arh1’s picture

New patch with a better approach to the process function (my first todo from #8).

vinmassaro’s picture

@ arh1: thanks for your work on this. I will give your patch a test later this week.

arh1’s picture

Title: As nodes self-import, they cannot be deleted by their original importer » Separate tracking of feeds_selfnode_processor items from other feeds items

@vinmassaro: sounds good -- let's get this working! I'm anxious to deploy it, too, as the dev version fixes other bugs in beta3 and I'd hate to revert. (Secretly hoping that when we get this issue tidied up we might see a new release soon :) )

I made the issue title more general as I believe is appropriate.

arh1’s picture

This patch gets the feeds item hash from the new tracking table so that it properly only updates the item when its source has changed.

arh1’s picture

Oops, and we need to override Feeds' hash function so we're comparing apples to apples here and not updating fsnp items unnecessarily. What else am I missing?

vinmassaro’s picture

@arh1: I just tested your patch in #13 and it is working well. I was able to import 900 items, self-import them, then go back to the original importer and delete them all in one shot.

arh1’s picture

@vinmassaro -- great, glad to hear it. This is a big patch -- I hope we get more eyes on it, especially Twistor's! :)

I'm still poking and testing, but am planning to roll this out into production w/ our site's next release.

twistor’s picture

Component: Miscellaneous » Code
Assigned: twistor » Unassigned
Status: Needs review » Needs work

This is looking really good.

+++ b/sites/all/modules/feeds_selfnode_processor/FeedsSelfNodeProcessor.incundefined
@@ -141,6 +149,29 @@ class FeedsSelfNodeProcessor extends FeedsNodeProcessor {
   /**
+   * Override parent::hash().
+   */
+  protected function hash($item) {
+    static $serialized_mappings;
+    if (!$serialized_mappings) {
+      $serialized_mappings = serialize($this->config['mappings']);
+    }
+    return hash('md5', serialize($item) . $serialized_mappings);

What's the difference between this and the parent hash()?

+++ b/sites/all/modules/feeds_selfnode_processor/feeds_selfnode_processor.installundefined
@@ -0,0 +1,151 @@
+
+// @todo: Need to review this db schema... Should it stay identical to
+// feeds_item?

I don't think it needs to stay the same. We can drop entity_type and entity_id.

+++ b/sites/all/modules/feeds_selfnode_processor/feeds_selfnode_processor.moduleundefined
@@ -15,3 +15,84 @@ function feeds_selfnode_processor_feeds_plugins() {
+// @todo: Instead of calling _feeds_selfnode_processor_item_info_save from our
+// process function, can we disable Feeds implementations of these hooks when
+// we're running Feeds Self Node Processor's implementations of them, so we can
+// let the hooks call _feeds_selfnode_processor_item_info_*?
+
+/**
+ * Implements hook_entity_insert().
+ */
+/*
+function feeds_selfnode_processor_entity_insert($entity, $type) {
+  list($id) = entity_extract_ids($type, $entity);
+  feeds_selfnode_processor_item_info_insert($entity, $id);

Let's just make these methods on the processor, and not attach anything to the entity. That will disable the Feeds hook.

+++ b/sites/all/modules/feeds_selfnode_processor/feeds_selfnode_processor.moduleundefined
@@ -15,3 +15,84 @@ function feeds_selfnode_processor_feeds_plugins() {
+/**
+ * Implements hook_entity_delete().
+ */
+/*
+function feeds_entity_delete($entity, $type) {
+  list($id) = entity_extract_ids($type, $entity);
+
+  // Delete any imported items produced by the source.
+  db_delete('feeds_item_selfnode_processor')
+    ->condition('entity_type', $type)
+    ->condition('entity_id', $id)
+    ->execute();

hook_entity_delete(), should change to hook_node_delete(). This is the only hook we need.

Moving the feed_item management to the processor is something I'm doing in the 3.x branch of Feeds anyway. It's silly to fire a hook when we know exactly what's happening on import anyway.

arh1’s picture

Component: Code » Miscellaneous
Assigned: Unassigned » arh1
Status: Needs work » Needs review
StatusFileSize
new10.95 KB
new8.25 KB

Thanks, twistor. Updated patch attached...

What's the difference between this and the parent hash()?

Oops -- nothing. :) I thought $this would refer to the FeedsSelfNodeProcessor object as opposed to the FeedsProcessor object such that $this->config['mappings'] would differ, but that's not the case, is it. Removed.

I don't think it needs to stay the same. We can drop entity_type and entity_id.

So this has also killed the table's primary key and altered most of the indexes as well. I've added a new primary key for feed_nid -- not sure if that's what we want, or if we want to tweak any other indexes.

Let's just make these methods on the processor, and not attach anything to the entity. That will disable the Feeds hook.

Done.

hook_entity_delete(), should change to hook_node_delete(). This is the only hook we need.

Implemented.

Alright, how's this sitting now? :)

arh1’s picture

Component: Miscellaneous » Code

Oops, didn't mean to change Component.

vinmassaro’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new8.38 KB

@arh1: The patch did not apply for me cleanly since it was not created relative to the module directory. Once I fixed it manually and tested, it worked great. I rerolled the patch to apply against 7.x-1.x HEAD and gave you attribution. Thanks!

arh1’s picture

@vinmassaro -- Thanks for the re-roll and I'm glad it's working for you. I look forward to this getting committed (or any more feedback from twistor).

t_hall’s picture

Would this patch solve the issue of Feeds Self Node Processor creating duplicate items? Please correct me if I'm on the wrong path..

arh1’s picture

@t_hall -- it might... See my comment #7 and linked issue above. If that matches your scenario, you're in the right place (and you should try out the patch in this issue!). If not, you'll probably want to create a new issue and describe your situation in detail.

sjancich’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new7.8 KB

There's a bug in the patch from #19.

The getHash() method returns an object, not the hash value as a string, so therefore the hash check will always fail since we are comparing a string against an object. This caused a massive headache for me because I was mapping an image field in my feed importer. A new copy of the image got added on every update until my server ran out of disk space.

Here is a re-roll of the patch where the getHash() method returns the hash from the DB as a string.

twistor’s picture

Assigned: arh1 » twistor
StatusFileSize
new6.17 KB

There's no reason to track the URL and GUID since we don't do unique fields.

  • twistor committed e115b29 on 7.x-1.x
    Issue #1965524 by arh1, twistor, sjancich, vinmassaro: Fixed Separate...
twistor’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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