boboldehampsink / import

DEPRECATED - Import plugin for Craft CMS
MIT License
177 stars 28 forks source link

Importing users runs modify hook, but ignores it #135

Open Tam opened 8 years ago

Tam commented 8 years ago

I'm trying to import some users and I have this modify in my business logic plugin:

public function modifyImportRow($element, $map, $data)
{
    // Map data to fields
    $fields = array_combine($map, $data);

    // Initialize content array
    $content = array();

    // Arrange your content in a way that makes sense for your plugin
    foreach ($fields as $handle => $value) {
        $content[$handle] = $value;
    }

    $name = explode(' ', $data[2], 2);
    $content['firstName'] = $name[0];
    $content['lastName'] = $name[1];

    // Set modified content
    $element->setContentFromPost($content);
}

The users are importing successfully, and the hook is running (I can ::log from it) but none of the modifications take effect. I'm not getting any errors (checked log files & craft_import_log table).

smockensturm commented 8 years ago

Check out this answer:

http://craftcms.stackexchange.com/a/16265/153

You'll have to make some adjustments. ie. check for a particular field handle (name?) and get your manipulations inside the foreach loop. Are you importing into a table by chance?

steverowling commented 7 years ago

If you are setting the default firstName and lastName fields on a UserModel, you can't do that using setContentFromPost().

Instead, try setting them directly on the $element like this:

$element->firstName = $name[0];
$element->lastName = $name[1];