Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Importing users runs modify hook, but ignores it #135

Open
Tam opened this issue Sep 7, 2016 · 2 comments
Open

Importing users runs modify hook, but ignores it #135

Tam opened this issue Sep 7, 2016 · 2 comments
Labels

Comments

@Tam
Copy link

Tam commented Sep 7, 2016

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
Copy link

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
Copy link

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];

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants