I am trying to allow multiple users on my site to import csv files with feeds. The problem I am running into is that the users have to get there user id, and then use a unique id for each node they import. I am just wondering is there a way to allow all the users to upload csv files and not have them overwriting other users items just there own? Thanks.

Comments

edev’s picture

Component: Feeds Import » Code
Issue summary: View changes
megachriz’s picture

Status: Active » Fixed

If you attach your importer to a content type and use 'GUID' as your unique target, users will need to create a node to import content. Since the GUID is restricted to content imported using the created feed node, users will not be able to import eachothers content.

Using GUID as unique target has one limitation: you can only update content imported by Feeds. If you want your users also be able to update manually created content, you need to have something else as unique target. Since Feeds 7.x-2.0-beta1 other fields can be marked as unique target when using "Unique values" validation rule from the Field validation module. As this solution alone doesn't help to prevent users from overwriting eachothers content, you will also need to use the "Rewrite" plugin from Feeds Tamper to add in the unique user value:

  1. Install the modules Field validation, Feeds Tamper and Feeds Tamper Admin UI.
  2. Add a text field to act as your unique target.
  3. Add a validation rule of type "Unique values" for your text field.
  4. On the mapping section, map "Feed node: User ID" to "Temporary target".
  5. Map the unique column from your CSV file to your unique text field.
  6. Add a "Rewrite" tamper plugin for your unique text field to combine the two source values. It should be something like [parent:uid]_[id].

This way the unique value is a combination of the user ID and the unique ID from the source file, preventing an user from updating content created by other users. You will need to write additional code though to fill in the unique text field with the right value when the user manually creates the content. And you will need to prevent the users from being able to edit the text field. This can be done with the Field permissions module for example.

You can also implement your own custom solution for retrieving existing nodes using "unique callbacks". See https://www.drupal.org/node/1307732#field_as_unique_id_7 for more information.

Status: Fixed » Closed (fixed)

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