Closed (fixed)
Project:
Default Content
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Mar 2017 at 15:37 UTC
Updated:
17 May 2019 at 22:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
andypostHm, probably it makes sense, the win is that no access restrictions will apply on export
@Berdir any thoughts?
Comment #3
kalpaitch commentedIMO absolutely. Yes. I have found that in order to implement #2698425: Do not re-import existing entities this is needed because in order to find out whether an entity exists we use need to look them up as user 1. If we look up as any other user with limited access and there are nodes that have access restrictions then they won't be found and we'll get a db error.
Comment #4
moshe weitzman commentedI have been considering removing --user from drush since I thought this sort os masquerading is not needed anymore. Isn't there a lower level API that default content can use to bypass access control?
Comment #5
larowlanYeah, we can use the account switcher service in core.
Comment #6
mikran commentedhere is a patch that uses the account switcher service for the task
Comment #7
andypostComment #8
geerlingguy commentedHmm... I tried using the patch in #6—applied it to default_content module successfully, did a
drush cr, then ran:But the exported user JSON still doesn't contain status, email, or roles.
Comment #9
geerlingguy commentedFound that the changes in the patch only apply to the Drush < 9 versions, and I'm running Drush 9. Testing another version of the patch now which updates the Drush services and DefaultContentCommands.php as well.
Comment #10
geerlingguy commentedAttached patch also applies to Drush 9 commands. Seems to work well in my case—now I'm seeing roles, email, etc. (all the things available to user 1).
Comment #11
andypostBtw
\Drupal\default_content\Importer::importContent()already does switch to user 1Comment #12
ao2 commentedOK, so the feature itself is not controversial at all.
The question is: where should the the switch be performed? In
Importer/Exporteror when the commands are called inDrupal\default_content\Commands.And ideally the code should look similar for the
Importerand theExportercases: same import mechanism and same names for variables.I am not doing much Drupal these days so, even though I am the original reporter, I am afraid I could not work on these last details myself.
Comment #13
andypostI think better to make it in exporter because it's hard to explain to module's users that they must user `--user` drush's argument (nobody read docs)
Also it will be minimize code base if someone will provide drupal console integration
Comment #14
moshe weitzman commentedMy understanding is that Command would not consult a --user option because the module doesn't work without a non-priveleged user. It would simply switch to uid=1.
FWIW I dont especially care where the switch happens.
Comment #15
ao2 commented@andypost, just to clarify, when I was referring to the commands I was not suggesting that the user would have to pass `--user` to drush explicitly, as the very purpose of this issue is to avoid that.
I was referring to the current approach used in #10 to switch user in
src/Commands/DefaultContentCommands.phpopposed to the approach already used at import time, which is to switch the user insrc/Importer.php.I think that we'd better add the switch to
src/Exporter.php.@geerlingguy would you be up for it?
Comment #16
geerlingguy commentedRight now I don't have any cycles to devote to working on this patch, with it being end of year, holiday season and all that :(
Comment #17
amateescu commentedHere's a patch that switches the user in
Exporterrather than the drush commands themselves.Comment #19
amateescu commentedFixed the tests.
Comment #20
andypostnot sure it is the best place, suppose better to add to
\Drupal\default_content\Commands\DefaultContentCommandsbecause drush 9 no longer have --user argumentThis way we will keep compatibility with drush8 and will not affect all export methods
Comment #21
amateescu commentedI think it's best to put this directly in the exporter class precisely because it's agnostic to the Drush version :)
Comment #22
larowlanwe throw two execptions here, we should switch back before throwing for safety sake
In addition, I think we should check we're running in a cli context before we switch, in case someone has built UI for this - we don't want there to be an access bypass
other than that, looks good to me - thanks
Comment #23
amateescu commented@larowlan, good points :)
Since the problematic part is the serialization process, not entity loading, I've moved the account switching after those exceptions are thrown. Also cleaned up the code a bit and added the exceptions to
exportContent()as well.Done :)
Comment #24
larowlanLooks good to me
Comment #25
larowlan