public function WordPressAuthorDestination::import in WordPress Migrate 7.2
Override of MigrateDestinationUser::import().
On initial import, if the email address already exists we want to link to that account, and remember that we did so. On updates, if we see that it is a linked account, we don't want to update it.
Parameters
stdClass $account:
stdClass $row:
Overrides MigrateDestinationUser::import
File
- ./
wordpress_author.inc, line 106 - Support for migrating authors from a WordPress blog into Drupal.
Class
Code
public function import(stdClass $account, stdClass $row) {
if (isset($row->migrate_map_destid1)) {
// Updating the account - if it's linked, just return the ID of the linked
// account
$uid = db_select('wordpress_migrate_linked_authors', 'a')
->fields('a', array(
'uid',
))
->condition('mail', $account->mail)
->execute()
->fetchField();
if ($uid) {
$this->numUpdated++;
return array(
$uid,
);
}
}
else {
// Initial import - if already in the users table, add to our linked_authors
// list and return the uid of the existing account.
$uid = db_select('users', 'u')
->fields('u', array(
'uid',
))
->condition('mail', $account->mail)
->execute()
->fetchField();
if (!$uid) {
// This user does not yet exist on the site. See if we're supposed to
// create it.
$create_new_users = $this->importUsers;
if (!$create_new_users) {
// Link this content to the default user chosen in the import settings.
$uid = $this->defaultAuthorUid;
}
}
if ($uid) {
db_merge('wordpress_migrate_linked_authors')
->key(array(
'mail' => $account->mail,
))
->fields(array(
'uid' => $uid,
))
->execute();
$this->numCreated++;
return array(
$uid,
);
}
}
// If there's no linkage, do the normal thing and create a new user.
return parent::import($account, $row);
}