/**
  * Import user.
  *
  * @param User $user
  *
  * @todo Here we are assuming that there cannot be two users with the
  * same user_login. This might be wrong. Investigate!
  * Consider using WP function get_user_by.
  *
  * @see http://codex.wordpress.org/Function_Reference/get_user_by
  */
 public function import_user(User $user)
 {
     // Database table base prefix for production and content stage.
     $prod_prefix = $this->custom_dao->get_table_base_prefix();
     $stage_prefix = $this->batch->get_custom_data('sme_table_base_prefix');
     // Change database table base prefix from content staging prefix to
     // production prefix.
     $meta = array_map(function ($record) use($stage_prefix, $prod_prefix) {
         if (isset($record['meta_key']) && strpos($record['meta_key'], $stage_prefix) === 0) {
             $record['meta_key'] = substr_replace($record['meta_key'], $prod_prefix, 0, strlen($stage_prefix));
         }
         return $record;
     }, $user->get_meta());
     // Update user with new meta.
     $user->set_meta($meta);
     // See if user exists in database.
     $existing = $this->user_dao->get_user_by_user_login($user->get_login());
     // Create if user does not exist, update otherwise.
     if (empty($existing)) {
         $this->user_dao->insert($user);
     } else {
         $user->set_id($existing->get_id());
         $this->user_dao->update_user($user);
     }
 }
 /**
  * Add database table base prefix to batch.
  *
  * @param Batch $batch
  */
 private function add_table_prefix(Batch $batch)
 {
     $batch->add_custom_data('sme_table_base_prefix', $this->custom_dao->get_table_base_prefix());
 }