I'm trying out this module but the export json file for users doesn't have email addresses. What am I missing? Thanks.

{
    "_links": {
        "self": {
            "href": "http:\/\/default\/user\/2?_format=hal_json"
        },
        "type": {
            "href": "http:\/\/drupal.org\/rest\/type\/user\/user"
        }
    },
    "uuid": [
        {
            "value": "c51ca112-5598-4e15-8808-8d9d973abf8c"
        }
    ],
    "langcode": [
        {
            "value": "en",
            "lang": "en"
        }
    ],
    "name": [
        {
            "value": "user2"
        }
    ],
    "created": [
        {
            "value": "1448898158"
        }
    ],
    "changed": [
        {
            "value": "1448898158",
            "lang": "en"
        }
    ],
    "default_langcode": [
        {
            "value": "1",
            "lang": "en"
        }
    ]
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dakala created an issue. See original summary.

larowlan’s picture

Email is a protected field in core.
If its not being exported then either you don't have permission to see it, or core doesn't export it either - would be my guess

dakala’s picture

@larowlan: Thanks but when logged in as user 1, I can see everything. An export of users without the email field means they can't be imported to another site later.

The entity is loaded correctly and yes mail is protected, as well as the other fields that have been correctly exported. The problem comes after the serialization and not being able to have emails in the output is a major issue IMO.

class Drupal\user\Entity\User#2297 (23) {
  protected $values =>
  array(16) {
    'uid' =>
    array(1) {
      'x-default' =>
      string(1) "2"
    }
    'uuid' =>
    array(1) {
      'x-default' =>
      string(36) "c51ca112-5598-4e15-8808-8d9d973abf8c"
    }
    'langcode' =>
    array(1) {
      'x-default' =>
      string(2) "en"
    }
    'preferred_langcode' =>
    array(1) {
      'x-default' =>
      string(2) "en"
    }
    'preferred_admin_langcode' =>
    array(1) {
      'x-default' =>
      string(2) "en"
    }
    'name' =>
    array(1) {
      'x-default' =>
      string(5) "user2"
    }
    'pass' =>
    array(1) {
      'x-default' =>
      string(55) "$S$E06f8LiuKfE4woht0Iw1/M6ooGDLtAUm7znZqrI3OR7LgUx0WZqw"
    }
    'mail' =>
    array(1) {
      'x-default' =>
      string(17) "user2@example.com"
    }
    'timezone' =>
    array(1) {
      'x-default' =>
      string(13) "Europe/London"
    }
    'status' =>
    array(1) {
      'x-default' =>
      string(1) "1"
    }
    'created' =>
    array(1) {
      'x-default' =>
      string(10) "1448898158"
    }
    'changed' =>
    array(1) {
      'x-default' =>
      string(10) "1448898158"
    }
    'access' =>
    array(1) {
      'x-default' =>
      string(1) "0"
    }
    'login' =>
    array(1) {
      'x-default' =>
      string(1) "0"
    }
    'init' =>
    array(1) {
      'x-default' =>
      string(17) "user2@example.com"
    }
    'default_langcode' =>
    array(1) {
      'x-default' =>
      string(1) "1"
    }
  }
  protected $fields =>
  array(0) {
  }
  protected $fieldDefinitions =>
  NULL
  protected $languages =>
  NULL
  protected $langcodeKey =>
  string(8) "langcode"
  protected $defaultLangcodeKey =>
  string(16) "default_langcode"
  protected $activeLangcode =>
  string(9) "x-default"
  protected $defaultLangcode =>
  string(2) "en"
  protected $translations =>
  array(1) {
    'x-default' =>
    array(1) {
      'status' =>
      int(1)
    }
  }
  protected $translationInitialize =>
  bool(false)
  protected $newRevision =>
  bool(false)
  protected $isDefaultRevision =>
  bool(true)
  protected $entityKeys =>
  array(3) {
    'bundle' =>
    string(4) "user"
    'id' =>
    string(1) "2"
    'uuid' =>
    string(36) "c51ca112-5598-4e15-8808-8d9d973abf8c"
  }
  protected $translatableEntityKeys =>
  array(2) {
    'langcode' =>
    array(1) {
      'x-default' =>
      string(2) "en"
    }
    'default_langcode' =>
    array(1) {
      'x-default' =>
      string(1) "1"
    }
  }
  protected $validated =>
  bool(false)
  protected $validationRequired =>
  bool(false)
  protected $entityTypeId =>
  string(4) "user"
  protected $enforceIsNew =>
  NULL
  protected $typedData =>
  NULL
  protected $cacheContexts =>
  array(0) {
  }
  protected $cacheTags =>
  array(0) {
  }
  protected $cacheMaxAge =>
  int(-1)
  protected $_serviceIds =>
  array(0) {
  }
}
larowlan’s picture

Status: Active » Postponed (maintainer needs more info)

Can you enable the user rest endpoint or create a views rest export of users and see if mail shows there.
I suspect it won't.

dakala’s picture

This is the output of a views rest export of the user.

[
  {
    "uid": [
      {
        "value": "2"
      }
    ],
    "uuid": [
      {
        "value": "c51ca112-5598-4e15-8808-8d9d973abf8c"
      }
    ],
    "langcode": [
      {
        "value": "en"
      }
    ],
    "preferred_langcode": [
      {
        "value": "en"
      }
    ],
    "preferred_admin_langcode": [
      {
        "value": "en"
      }
    ],
    "name": [
      {
        "value": "user2"
      }
    ],
    "mail": [
      {
        "value": "user2@example.com"
      }
    ],
    "timezone": [
      {
        "value": "Europe\/London"
      }
    ],
    "status": [
      {
        "value": "1"
      }
    ],
    "created": [
      {
        "value": "1448898158"
      }
    ],
    "changed": [
      {
        "value": "1448898158"
      }
    ],
    "access": [
      {
        "value": "0"
      }
    ],
    "login": [
      {
        "value": "0"
      }
    ],
    "init": [
      {
        "value": "user2@example.com"
      }
    ],
    "roles": [
      
    ],
    "default_langcode": [
      {
        "value": "1"
      }
    ],
    "user_picture": [
      
    ]
  }
]
Saphyel’s picture

I confirm this is still happening.

mlncn’s picture

Sorry i missed this issue and technically posted a duplicate but i think the fix will likely progress in #2699469: User entity exported without status, roles.

dakala’s picture

@mlncn: Thanks for moving this forward. I couldn't follow this up to see where the problem was.

larowlan’s picture

The issue is the drush command.

It needs to call the account switcher service and switch to user 1 before exporting, then switch back afterwards.

Field permissions prevent those fields form being exported.

larowlan’s picture

Title: No email address in user export » No email address, roles, status in user export
Status: Postponed (maintainer needs more info) » Active
codium’s picture

I've tried to export content by:

drush --user=1 dcer node 13 --folder=my_path

but still no email & status values in exported json.

AaronBauman’s picture

Title: No email address, roles, status in user export » Run drush export commands as user 1
Category: Support request » Feature request
Status: Active » Needs review
FileSize
2.44 KB

feature request or bug report?

larowlan’s picture

+++ b/drush/default_content.drush.inc
@@ -54,6 +54,10 @@ function default_content_drush_command() {
+  $user1 = \Drupal\user\Entity\User::load(1);

@@ -75,6 +81,10 @@ function drush_default_content_export($entity_type_id, $entity_id) {
+  $user1 = \Drupal\user\Entity\User::load(1);

@@ -99,9 +111,15 @@ function drush_default_content_export_references($entity_type_id, $entity_id = N
+  $user1 = \Drupal\user\Entity\User::load(1);

Please import the class instead of using the FQCN. Thanks

I call it a feature request. I didn't really expect anyone to use this to import users.

andypost’s picture

Looking at patch I think better to refactor switching code into separate function for clarity and to allow drush option for it later

AaronBauman’s picture

Status: Needs review » Needs work
AaronBauman’s picture

OK, refactored, and uses a "run_as" argument to enable user switching.

See how you like this one.

AaronBauman’s picture

Status: Needs work » Needs review
andypost’s picture

Title: Run drush export commands as user 1 » Run drush export commands as customized user
Status: Needs review » Reviewed & tested by the community

Looks great!

larowlan’s picture

+1

  • andypost committed 11fa548 on 8.x-1.x authored by aaronbauman
    Issue #2625846 by aaronbauman: Run drush export commands as customized...
andypost’s picture

Status: Reviewed & tested by the community » Fixed
AaronBauman’s picture

Status: Fixed » Needs review
FileSize
2.58 KB

Sorry, I guess this slipped past all of us.
"run_as" is defined as an argument in default_content_drush_command(), but is actually implemented as an option.

Attached patch fixes definition in default_content_drush_command()

Also, since it's changing anway, switches from "run_as" with underscore to "run-as" with hyphen instead.

andypost’s picture

IMO option supposes "optional", just wording changes, please review

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

+1

  • andypost committed e4e75b9 on 8.x-1.x
    Issue #2625846 by aaronbauman, andypost: Run drush export commands as...
andypost’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ao2’s picture

Hi,

the run-as option is working fine, but isn't it equivalent to using the drush --user option?

I tried a command similar to the one in #11 and the email address get exported fine with:
drush --user=1 default-content-export-references user --folder=$PWD/content_as_user_1

and it gives the same output of:
drush default-content-export-references user --run-as=1 --folder=$PWD/content_run_as_user_1

So maybe the run-as option is not strictly necessary, or am I missing something?

Also, would you consider a patch to run import/export as user 1 by default?

Thanks,
Antonio

andypost’s picture

Good points, needs follow-up issue!

smaz’s picture

Added a follow-up issue.