When I want check unique key with multiple columns, I needs values mark as unique, or all values current importing passed into callback of unique check. But FeedsProcessor::existingEntityId only pass single value in that column.
That will hard to implement unique check table when primary key include multiple columns(like this):

 CREATE TABLE `testtest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `key1` varchar(255) NOT NULL DEFAULT '',
  `key2` varchar(255) NOT NULL DEFAULT '',
  `data1` text,
  PRIMARY KEY (`key1`,`key2`),
  KEY `id` (`id`)
) 
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jimyhuang created an issue. See original summary.

jimyhuang’s picture

Trying to improve this. I pass all columns marked as unique into argument of callback.

jimyhuang’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 2656786-1.patch, failed testing.

jimyhuang’s picture

FileSize
2.6 KB

fixes testing error, modify api document.

jimyhuang’s picture

FileSize
2.6 KB
jimyhuang’s picture

FileSize
2.6 KB
jimyhuang’s picture

Status: Needs work » Needs review
FileSize
2.6 KB
MegaChriz’s picture

This looks like a nice addition, I'm only a bit concerned about the following: would the implementation of that unique callback make the assumption that the user configures multiple targets as unique? What happens if the user only sets one target as unique?
Ideally, the two values would be sent to the single target, but I don't think this is possible in Feeds 7.x-2.x.

jimyhuang’s picture

foreach ($this->uniqueTargets($source, $result) as $target => $value) {

According original code(before my patch), feeds support user config multiple unique targets. Then loop these targets. If user set only one unique target, then loop only go once.

the two values would be sent to the single target

I'm not sure if I can catch what you means. When only one unique target, then the callback function will receive duplicate argument. I don't like that, but because of callback have lots of dependencies with other modules, I wouldn't like to change argument behavior.

MegaChriz’s picture

Marked #2382687: Permit custom unique mapper to have access to whole row as a duplicate. Small difference in that issue is that it is suggesting to pass the whole item to the callback instead of only the columns that are marked as unique.