Every few weeks the admin imports a csv file with users into the site. Existing users are updated, new users are created. The csv also holds passwords. For new users the password needs to be set to value form the csv, for existing users I want to keep the password in Drupal.

Can I make a Feeds Tamper rule where the password value is set on new users and skipped on existing users?

Comments

capono created an issue. See original summary.

HansKuiters’s picture

Status: Active » Closed (won't fix)

No Feeds Tamper solution. I believe Feeds Tamper only works on the source and has no clue about the target. Correct me if I'm wrong.

But I made it work with this hook in my custom module.

function MYMODULE_feeds_presave($source, $entity, $item, $entity_id) {
  if ($entity->feeds_item->entity_type == 'user' && $entity_id != 0 && isset($entity->pass)) {
    // if user exists don't update pass
    unset($entity->pass);
  }
}

The $entity object holds the new values from $source at this stage. By unsetting $entity->pass the current pass doesn't get updated.

Maybe quick and dirty but it works for me. I am interested in other solutions.

HansKuiters’s picture

Title: Only set field value if item is new, never update existing field value » Only set target field value if item is new, never update existing target field value