Commit 2c9aad85 authored by AaronBauman's avatar AaronBauman Committed by andypost

Issue #2857589 by aaronbauman, MerryHamster: Remove the run-as option in drush commands

parent f0d90253
...@@ -18,7 +18,6 @@ function default_content_drush_command() { ...@@ -18,7 +18,6 @@ function default_content_drush_command() {
], ],
'options' => [ 'options' => [
'file' => dt('Write out the exported content to a file instead of stdout'), 'file' => dt('Write out the exported content to a file instead of stdout'),
'run-as' => dt('Run as a particular user (uid)'),
], ],
'aliases' => ['dce'], 'aliases' => ['dce'],
'required-arguments' => 2, 'required-arguments' => 2,
...@@ -31,7 +30,6 @@ function default_content_drush_command() { ...@@ -31,7 +30,6 @@ function default_content_drush_command() {
], ],
'options' => [ 'options' => [
'folder' => dt('Folder to export to, entities are grouped by entity type into directories.'), 'folder' => dt('Folder to export to, entities are grouped by entity type into directories.'),
'run-as' => dt('Run as a particular user (uid)'),
], ],
'aliases' => ['dcer'], 'aliases' => ['dcer'],
'required-arguments' => 1, 'required-arguments' => 1,
...@@ -41,9 +39,6 @@ function default_content_drush_command() { ...@@ -41,9 +39,6 @@ function default_content_drush_command() {
'arguments' => [ 'arguments' => [
'module' => dt('The name of the module.'), 'module' => dt('The name of the module.'),
], ],
'options' => [
'run-as' => dt('Run as a particular user (uid)'),
],
'aliases' => ['dcem'], 'aliases' => ['dcem'],
'required-arguments' => 1, 'required-arguments' => 1,
]; ];
...@@ -60,7 +55,6 @@ function default_content_drush_command() { ...@@ -60,7 +55,6 @@ function default_content_drush_command() {
* The entity ID to export. * The entity ID to export.
*/ */
function drush_default_content_export($entity_type_id, $entity_id) { function drush_default_content_export($entity_type_id, $entity_id) {
_drush_default_content_setup();
/** @var \Drupal\default_content\DefaultContentManagerInterface $manager */ /** @var \Drupal\default_content\DefaultContentManagerInterface $manager */
$manager = \Drupal::service('default_content.manager'); $manager = \Drupal::service('default_content.manager');
$export = $manager->exportContent($entity_type_id, $entity_id); $export = $manager->exportContent($entity_type_id, $entity_id);
...@@ -71,7 +65,6 @@ function drush_default_content_export($entity_type_id, $entity_id) { ...@@ -71,7 +65,6 @@ function drush_default_content_export($entity_type_id, $entity_id) {
else { else {
drush_print($export); drush_print($export);
} }
_drush_default_content_teardown();
} }
/** /**
...@@ -83,7 +76,6 @@ function drush_default_content_export($entity_type_id, $entity_id) { ...@@ -83,7 +76,6 @@ function drush_default_content_export($entity_type_id, $entity_id) {
* (Optional) The entity ID to export or all entities will be exported. * (Optional) The entity ID to export or all entities will be exported.
*/ */
function drush_default_content_export_references($entity_type_id, $entity_id = NULL) { function drush_default_content_export_references($entity_type_id, $entity_id = NULL) {
_drush_default_content_setup();
/** @var \Drupal\default_content\DefaultContentManagerInterface $manager */ /** @var \Drupal\default_content\DefaultContentManagerInterface $manager */
$manager = \Drupal::service('default_content.manager'); $manager = \Drupal::service('default_content.manager');
...@@ -99,7 +91,6 @@ function drush_default_content_export_references($entity_type_id, $entity_id = N ...@@ -99,7 +91,6 @@ function drush_default_content_export_references($entity_type_id, $entity_id = N
$serialized_by_type = $manager->exportContentWithReferences($entity_type_id, $entity_id); $serialized_by_type = $manager->exportContentWithReferences($entity_type_id, $entity_id);
$manager->writeDefaultContent($serialized_by_type, $folder); $manager->writeDefaultContent($serialized_by_type, $folder);
} }
_drush_default_content_teardown();
} }
/** /**
...@@ -109,36 +100,9 @@ function drush_default_content_export_references($entity_type_id, $entity_id = N ...@@ -109,36 +100,9 @@ function drush_default_content_export_references($entity_type_id, $entity_id = N
* The module name to export. * The module name to export.
*/ */
function drush_default_content_export_module($module_name) { function drush_default_content_export_module($module_name) {
_drush_default_content_setup();
/** @var \Drupal\default_content\DefaultContentManagerInterface $manager */ /** @var \Drupal\default_content\DefaultContentManagerInterface $manager */
$manager = \Drupal::service('default_content.manager'); $manager = \Drupal::service('default_content.manager');
$serialized_by_type = $manager->exportModuleContent($module_name); $serialized_by_type = $manager->exportModuleContent($module_name);
$module_folder = \Drupal::moduleHandler()->getModule($module_name)->getPath() . '/content'; $module_folder = \Drupal::moduleHandler()->getModule($module_name)->getPath() . '/content';
$manager->writeDefaultContent($serialized_by_type, $module_folder); $manager->writeDefaultContent($serialized_by_type, $module_folder);
_drush_default_content_teardown();
}
/**
* Check "run-as" option and switch user if given.
*
* @return void
*/
function _drush_default_content_setup() {
if ($uid = drush_get_option('run-as')) {
$accountSwitcher = \Drupal::service('account_switcher');
$account = User::load($uid);
$accountSwitcher->switchTo($account);
}
}
/**
* Check "run-as" option and switch user back if given.
*
* @return void
*/
function _drush_default_content_teardown() {
if ($uid = drush_get_option('run-as')) {
$accountSwitcher = \Drupal::service('account_switcher');
$accountSwitcher->switchBack();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment