Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My use case is: Client has a stock list which covers their entire range of product, many which are not to be sold through the website, however they would like to use this master list to update the stock for only products on the website and not to create new products.
I guess this may well be resolved if Feeds is fixed to care about Required Fields?
Comment | File | Size | Author |
---|---|---|---|
#57 | interdiff-1286298-55-57.txt | 3.14 KB | MegaChriz |
#57 | feeds-skip-new-items-1286298-57.patch | 5.32 KB | MegaChriz |
#55 | don_t_create_new_items-1286298-55.patch | 2.18 KB | charginghawk |
#47 | don_t_create_new_items-1286298-47.patch | 2.69 KB | fietserwin |
Comments
Comment #1
johnbarclay CreditAttribution: johnbarclay commentedSo for the node processor, an option could be added to the "Update Existing nodes" field:
Comment #2
killtheliterate CreditAttribution: killtheliterate commentedLove to hear if there's any method to achieve this
Comment #3
checker CreditAttribution: checker commentedI have the same problem with product stock: update but not create. Do you have found any solution?
Comment #4
checker CreditAttribution: checker commentedAs a work around you can write a little plugin for feeds tamper module. that plugin can check if an entity is available or not. if not you can unset the entry and feeds importer won't import this (and won't create a new entry)
Comment #5
joshualoman CreditAttribution: joshualoman commentedAnyone found a simple solution for this? I need this functionality too!! Checker's suggestion i don't really understand..
Comment #6
Triskelion CreditAttribution: Triskelion commentedI have attached a quick patch to the latest dev version which appears to implement this. I am still in the process of testing.
Update: Typos in code. Corrected patch next
Comment #7
Triskelion CreditAttribution: Triskelion commentedI should not do these things late at night. Typos corrected.
Comment #8
agileadamPatch #7 works great for me! I was confused when I was getting a success message of "There are no new commerce products." but it was because the entities I was importing were unchanged from the existing entities. Checking "Skip hash check" forced the records to update. I tested a csv that had one new product, and one existing product, and it updated only the existing product (did not create the new product). Excellent!
Thanks @triskelion!
Comment #9
twistor CreditAttribution: twistor commentedVery nice! This will need tests though. It should also depend on #1835106: Make entity loading generic. which is going in tonight.
Comment #10
Triskelion CreditAttribution: Triskelion commentedNoticed that there have been some changes in the way this module works.
I rerolled the patch with the new dev version. Hope I got it right.
Comment #11
twistor CreditAttribution: twistor commentedThat's close, I don't think we need the changes to FeedsNodeProcessor at all.
Comment #12
Triskelion CreditAttribution: Triskelion commentedIt's just a couple of support functions in FeedsNodeProcessor. I made the changes to sync processing with FEEDS_UPDATE_EXISTING as they are logically equivalent, except FEEDS_SKIP_NEW does not create new nodes. Am I misunderstanding the logic?
My main concern is in the timing of the loop escape in FeedsProcessor. As before, I placed it just before the 'try' statement, but the new handling of the entity load threw me off a bit.
Thanks for the prompt acknowledgement.
Comment #13
a.ross CreditAttribution: a.ross commentedUntil this patch is in, you can get the "update only" behavior by using Rules. Example configuration for products:
Comment #14
rotty_dean CreditAttribution: rotty_dean commenteda.ross this rule looks like what i am looking for but i can't seem to get the mapping from the feed. So at the moment everything is skipped. I have tried:
NOT Entity exists by property
Parameter: Entity type: Commerce Product, Property: SKU, Value: [xpathparser:1]
I need this because i have a list of products that need unpublishing, and in that list about 90% was never added to the database so they need to be skipped.
Comment #15
a.ross CreditAttribution: a.ross commentedI haven't done this with an XML parser, only a CSV parser, but that shouldn't make a difference.
You should be able to select the field you need (SKU of the imported item) as you normally would in Rules. Click "Switch to data selection" below where you (incorrectly) entered "xpathparser:1". Then you'll be able to select the SKU of the imported "commerce-product".
Comment #16
marktheshark CreditAttribution: marktheshark commentedHave you installed the unique field module in order to be able to update products with their SKU as a unique key?
Comment #17
johnvTriggering testbot.
Comment #18
marktheshark CreditAttribution: marktheshark commentedDoes the patch concern only nodes, or can it also be used for entities (e.g. Drupal Commerce products)?
Comment #19
a.ross CreditAttribution: a.ross commentedThe Rule I described works with vanilla Feeds. We have Feeds tamper installed but we're not using it for the stock updates, as a rule makes more sense.
In case you missed it, click "switch to data selection" in Rules to select the SKU of the imported item.
Comment #20
marktheshark CreditAttribution: marktheshark commentedThanks, if I wanted to implement the FEEDS_SKIP_NEW functionality, as per the patch, would I need to do it in a different file from FeedsNodeProcessor.inc?
I'm asking because FeedsNodeProcessor.inc probably pertains only to entity types = node.
Comment #21
a.ross CreditAttribution: a.ross commentedDon't know, I'm not the author of the patch and I'm happy with our Rule.
Comment #22
marktheshark CreditAttribution: marktheshark commentedYou mean that any changes should apply to FeedsProcessor.inc only so that all others inherit it, right?
Comment #23
marktheshark CreditAttribution: marktheshark commentedApplied the recommended changes to FeedProcessor.inc and FeedsCommerceProductMultiProcessor.inc (for importing multiple product types at once.
Creation of new entities was successfully skipped, however the updated entities are a bit messed up: all images of the product are now not displaying any more...
Comment #24
fietserwinThe danger of mixing insert and update behavior is that child classes that derive from the base class might need to be changed as well. This node processor is a good example. But who tells us that there aren't any other child classes in projects outside the feeds project, that would need the same change? (e.g. the commerce product processor)
To solve this dilemma, we should go for a separate config value that defines how to handle existing entities. Thus defining 2 new constants:
and storing that in a config value:
$this->config['insert_new']
Whether we then write hook_update_n () or use !empty($this->config['insert_new']) to skip inserting new records is a choice. The latter will give us a shorter and easier patch, the former will be better in the long run.
Change nodes to @entities (and rewrite to phrase the action only once, but this is also a symptom of mixing insert and update behavior)
I will try to post a patch shortly (without a hook_update_n()).
Comment #25
fietserwinAs the constructor of a feeds class calls defaultConfig(), the whole thing about needing a hook_update_n or not was not needed at all.
Attached a patch that works locally for me. Not sure though, if some tests may need to be adapted.
Comment #26
matsjacobsson CreditAttribution: matsjacobsson commentedI also got this to work nicely with a.ross suggestion with rules! Thanks!!
For the condition value I used:
commerce-product:sku
And the actions dataselctor:
commerce-product
Comment #27
drupalninja99 CreditAttribution: drupalninja99 commentedPatch here works well with this one: https://drupal.org/node/1539224
Comment #28
osopolarBackport for D6 attached.
In D7 FEEDS_SKIP_NEW is defined as 1 and FEEDS_INSERT_NEW as 0. This could be misleading in case of this code:
$this->config['insert_new'] == FEEDS_SKIP_NEW;
. Somebody could think when $this->config['insert_new'] is 1 (TRUE?) it means insert new node, but it actually stands for skip new node.Therefore I defined the constants in D6 conversely with FEEDS_INSERT_NEW as 1 and FEEDS_SKIP_NEW as 0. Maybe this should be fixed in D7 version.
Comment #30
fietserwinIf you use constants to get some kind of enum type, you should not bother about their actual value. In languages that provide an enum type you don't even (have to) declare their values.
Attach patches for other main versions than the issues version with a do-not-test or with a different extension.
Comment #31
osopolar@fietserwin: Thanks for the do-not-test hint.
Comment #32
memcinto CreditAttribution: memcinto commentedJust going to mention here that on a D7 site where I had the feeds-nocreate-1286298-7.patch installed, when I used a Feeds Importer to update existing nodes, using the "update only don't create new" option, it deleted the images in a image field attached to those nodes. (The image field was not involved in the import in any way.) It didn't just break the link between the node and the file, it deleted the image files off the server. Using the importer with the setting changed to "Update existing nodes" did not delete any files.
Comment #33
Drupali CreditAttribution: Drupali commentedPatch in #25 works great for me. Good job.
Comment #34
Darren OhComment #35
Drupali CreditAttribution: Drupali commentedI am getting the Notices while using this patch with entities. See enclosed image to see the errors.
Notice: Undefined index: insert_new in FeedsProcessor->configForm() (line 654 of /Applications/MAMP/htdocs/FGM/sites/all/modules/contrib/feeds/plugins/FeedsProcessor.inc).
Notice: Undefined index: insert_new in FeedsProcessor->configForm() (line 654 of /Applications/MAMP/htdocs/FGM/sites/all/modules/contrib/feeds/plugins/FeedsProcessor.inc).
Comment #36
tengokupatch #25 works for me too! thanks!
even with the commerce feeds product import
Comment #37
caspervoogt CreditAttribution: caspervoogt commentedpatch #25 didn't work for me with Commerce Feeds - but the rules approach from #13 works for me.
Comment #38
sedam CreditAttribution: sedam commentedPath #25 didn't work for me. I need to update a product entity without create new product that it exits (only update). Any suggestions? what am i doing wrong? FYI, I'm using lastest Feeds version on D7. thank you so much!
Comment #39
sedam CreditAttribution: sedam commentedDefinitely I was doing wrong mapping fields. I marked a SKU as an unique field and after applying the patch #25, produts are updating.
Comment #40
brandonc503 CreditAttribution: brandonc503 commented*deleted as i cant remove account
Comment #41
brandonc503 CreditAttribution: brandonc503 commented*deleted as i cant remove account
Comment #42
IckZ CreditAttribution: IckZ commentedsubscribe
Comment #43
IckZ CreditAttribution: IckZ commentedafter some testing I can say, that patch #25 is working for me :) thx a lot!
Comment #44
Aambro CreditAttribution: Aambro commented#13 with rules worked for me. And no need to patch.
Comment #45
fietserwinReroll of #25.
This patch answers the concerns that were raised:
- #28: switched the definitions to be more in line with the values for the constants regarding update behavior (especially FEEDS_SKIP_EXISTING).
- #32: this refers to the patch in #10, so can be ignored.
- #35: This warnings suggests that there is a child class that does not call the parent implementation of configDefaults(). That turns out to be FeedsEntityProcessor, so I also changed the configDefaults() method for that class. Thanks for reporting: solved in this patch.
- #37: Commerce feeds is another module and I guess that if that does not work, it also overrides methods without calling the parent implementation (like FeedsEntityProcessor did). if Commerce feeds depends on Feeds, it thus might have to adapt code if this patch gets in.
- #38: solved as of #39, so not a problem of this patch.
Comment #47
fietserwinCalling parent::configDefaults() in FeedsEntityProcessor lead to an infinite recursion, oops. This patch ran the tests fine locally.
Comment #48
MegaChriz CreditAttribution: MegaChriz commented#47 looks promising. This needs tests.
Comment #49
ben van den broeck CreditAttribution: ben van den broeck commentedI was trying #47 but it didn't stop creating products in my drupal commerce on importing a csv.
Comment #50
fietserwin#49: what processor are you using? I wouldn't be surprise if that is the one of the commerce feeds module and that was already reported in #37.
Comment #51
ben van den broeck CreditAttribution: ben van den broeck commentedIt is indeed with the commerce processor, I thought this was working with the commerce processor before, but probably i'm wrong. Now i use the rules solution offered in #13.
Comment #52
brandonc503 CreditAttribution: brandonc503 commented*deleted as i cant remove account
Comment #53
charginghawk CreditAttribution: charginghawk commentedFYI, Feed's entity processor has been moved to its own module: https://www.drupal.org/project/feeds_entity_processor
So you may need to apply this patch there.
Comment #54
MegaChriz CreditAttribution: MegaChriz commentedThe generic entity processor indeed moved to an other module, but you no longer have to patch that in this issue. The entity processor was only patched here because it didn't automatically inherit the "insert_new" setting.
The patch needs a reroll and the changes to FeedsEntityProcessor need to be left out in this patch.
The patch also needs an automated test.
Comment #55
charginghawk CreditAttribution: charginghawk commentedRerolling with FeedsEntityProcessor.inc changes stripped out.
Comment #56
charginghawk CreditAttribution: charginghawk commentedComment #57
MegaChriz CreditAttribution: MegaChriz commentedAnd here is a patch with an automated test.
The following is tested with a source file containing 10 items:
The probably only weird thing is that Feeds reports "There are no new nodes" even when you don't intent to import new nodes. Maybe this message should be "There are no nodes to update" when the setting "Insert new nodes" is set to "Do not insert new nodes" and when the setting "Update existing nodes" is set to "Update existing nodes". Thoughts?
Comment #58
joelpittetThe messaging is minor point but I on board with a +1 for "There are no nodes to update."
Comment #59
brandonc503 CreditAttribution: brandonc503 commentedi ran #57 patch against the
7.x-2.x-dev 2015-Jun-18
and
Checking patch plugins/FeedsProcessor.inc...
Checking patch tests/feeds_processor_node.test...
Applied patch plugins/FeedsProcessor.inc cleanly.
Applied patch tests/feeds_processor_node.test cleanly.
fyi
this was my first patch. so this was my first updating module for security and patching again for first time
Comment #60
fietserwinI also updated a site to the dev version, installed the module with the now separate entity processor and applied the latest patch: applies and works.
Regarding the message: the condition is actually that nothing happened: no updates, no changes, no unpublishing, no deletions and no failures. so the message should be somethinkg like "No action was necessary on processing this feed" or "No action taken on processing this feed" or "...". Can some native English speaker come up with a nice sentence?
Comment #61
joelpittetI believe this is slightly better:
Hope that helps, Cheers
Comment #62
maxplus CreditAttribution: maxplus commentedHi,
just tested it with commerce feeds because I did not want to create new products during a stock update.
Worked great at first glance
Thanks!
Comment #63
a.milkovsky#57 works for me as well. Thank you! I think it is time for RTBC
Comment #65
twistor CreditAttribution: twistor as a volunteer commentedComment #67
madelyncruz CreditAttribution: madelyncruz commentedI've tested #13 and it works well. Thank you a.ross
Comment #68
kevster CreditAttribution: kevster commentedHaving this problem and cant apply against latest dev as getting hunk issues - cant apply 2 out of 5 - I guess as its moved on now. Also have issue re #23 @marktheshark re my commerce prods having the image path wiped out despite the field not being in my importer.
Any chance of an update on the patch please?
Comment #69
MegaChriz CreditAttribution: MegaChriz commented@kevster
The patch in this issue has already been committed. There is no need to apply it to the latest dev. The issue of images being wiped out is a different issue. Maybe there is an existing issue for images being wiped out (I couldn't find one so far)? If you like to have this issue addressed, search for an existing issue first. If you can't find one, then try to reproduce the issue on a clean install. Finally, open a new issue with the steps to reproduce the problem.