From 85c164a3beda9b728acfe4c3b7b2aceefbae2f25 Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Sat, 22 Oct 2016 15:56:25 -0400 Subject: [PATCH 1/5] Starting support for drush config-export command. --- backdrop.drush.inc | 3 ++ .../config/backdrop_config_export.drush.inc | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 commands/config/backdrop_config_export.drush.inc diff --git a/backdrop.drush.inc b/backdrop.drush.inc index 59bdaf6..dd009a0 100644 --- a/backdrop.drush.inc +++ b/backdrop.drush.inc @@ -65,6 +65,9 @@ function backdrop_drush_command_alter(&$command) { case 'user-password': $backdrop_command = 'backdrop-user-password'; break; + case 'config-export': + $backdrop_command = 'backdrop-config-export'; + break; } // Commands that work with Backdrop with no adjustments. diff --git a/commands/config/backdrop_config_export.drush.inc b/commands/config/backdrop_config_export.drush.inc new file mode 100644 index 0000000..e2febe1 --- /dev/null +++ b/commands/config/backdrop_config_export.drush.inc @@ -0,0 +1,48 @@ + 'Export a Backdrop site configuration.', + 'callback' => 'backdrop_config_export', + 'bootstrap' => \Drush\Boot\BackdropBoot::BOOTSTRAP_SITE, + 'aliases' => array('cex'), + 'examples' => array( + 'drush cex' => 'Exports the configuration for the current site to the staging config directory.', + ), + ); + + return $items; +} + +/** + * Command callback for config-export + */ +function backdrop_config_export() { + try { + require_once BACKDROP_ROOT . '/settings.php'; + //global $config_directories['active']; + drush_print_r($config_directories); + $config_dir_active = $config_directories['active']; + $config_dir_staging = $config_directories['staging']; + passthru( + "rm -rf " . BACKDROP_ROOT . "/$config_dir_staging/*" + ); + passthru( + "cp -R " . BACKDROP_ROOT . "/$config_dir_active/ " . BACKDROP_ROOT . "/$config_dir_staging" + ); + } + catch(Exception $e) { + drush_print_r('couldn\t do it' . $e); + } +} \ No newline at end of file From 5b8649dd390c5c2942d873e4799a00add990552e Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Sun, 23 Oct 2016 12:57:44 -0400 Subject: [PATCH 2/5] Issue #74: Interim commit to cex to work on bsi. --- commands/config/backdrop_config_export.drush.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/config/backdrop_config_export.drush.inc b/commands/config/backdrop_config_export.drush.inc index e2febe1..386f170 100644 --- a/commands/config/backdrop_config_export.drush.inc +++ b/commands/config/backdrop_config_export.drush.inc @@ -16,7 +16,7 @@ function backdrop_config_export_drush_command() { 'description' => 'Export a Backdrop site configuration.', 'callback' => 'backdrop_config_export', 'bootstrap' => \Drush\Boot\BackdropBoot::BOOTSTRAP_SITE, - 'aliases' => array('cex'), + 'aliases' => array('bcex'), 'examples' => array( 'drush cex' => 'Exports the configuration for the current site to the staging config directory.', ), From 97073380532a7d44b23ca256abc7687bd4a0e41f Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Sun, 23 Oct 2016 14:41:41 -0400 Subject: [PATCH 3/5] Issue #74: Code clean up and messaging for bcex. --- commands/config/backdrop_config_export.drush.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/config/backdrop_config_export.drush.inc b/commands/config/backdrop_config_export.drush.inc index 386f170..ac9f534 100644 --- a/commands/config/backdrop_config_export.drush.inc +++ b/commands/config/backdrop_config_export.drush.inc @@ -6,6 +6,7 @@ */ use \Drush\Boot\BackdropBoot; +use Drush\Log\LogLevel; /** * Implements hook_drush_command(). @@ -18,7 +19,7 @@ function backdrop_config_export_drush_command() { 'bootstrap' => \Drush\Boot\BackdropBoot::BOOTSTRAP_SITE, 'aliases' => array('bcex'), 'examples' => array( - 'drush cex' => 'Exports the configuration for the current site to the staging config directory.', + 'drush bcex' => 'Exports the configuration for the current site to the staging config directory.', ), ); @@ -31,8 +32,6 @@ function backdrop_config_export_drush_command() { function backdrop_config_export() { try { require_once BACKDROP_ROOT . '/settings.php'; - //global $config_directories['active']; - drush_print_r($config_directories); $config_dir_active = $config_directories['active']; $config_dir_staging = $config_directories['staging']; passthru( @@ -41,8 +40,9 @@ function backdrop_config_export() { passthru( "cp -R " . BACKDROP_ROOT . "/$config_dir_active/ " . BACKDROP_ROOT . "/$config_dir_staging" ); + drush_log(dt('Configuration is exported to !staging', array('!staging' => $config_dir_staging)), LogLevel::SUCCESS); } catch(Exception $e) { - drush_print_r('couldn\t do it' . $e); + drush_print_r('couldn\'t do it ' . $e); } } \ No newline at end of file From 63ea7b57b7d8079c071fb1f96d4ae3cec1eb197e Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Wed, 23 Nov 2016 17:50:45 -0500 Subject: [PATCH 4/5] Adding bcex and bcim for config-export and config-import. --- .../config/backdrop_config_export.drush.inc | 2 +- .../config/backdrop_config_import.drush.inc | 79 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 commands/config/backdrop_config_import.drush.inc diff --git a/commands/config/backdrop_config_export.drush.inc b/commands/config/backdrop_config_export.drush.inc index ac9f534..1c3e5ed 100644 --- a/commands/config/backdrop_config_export.drush.inc +++ b/commands/config/backdrop_config_export.drush.inc @@ -45,4 +45,4 @@ function backdrop_config_export() { catch(Exception $e) { drush_print_r('couldn\'t do it ' . $e); } -} \ No newline at end of file +} diff --git a/commands/config/backdrop_config_import.drush.inc b/commands/config/backdrop_config_import.drush.inc new file mode 100644 index 0000000..2123e70 --- /dev/null +++ b/commands/config/backdrop_config_import.drush.inc @@ -0,0 +1,79 @@ + 'Import Backdrop site configuration.', + 'callback' => 'backdrop_config_import', + 'bootstrap' => \Drush\Boot\BackdropBoot::BOOTSTRAP_FULL, + 'aliases' => array('bcim'), + 'examples' => array( + 'drush bcim' => 'Imports the configuration for the current site from the staging config directory to the active config directory.', + ), + ); + + return $items; + } + +/** + * Command callback for backdrop-config-import. + */ +function backdrop_config_import() { + require_once BACKDROP_ROOT . '/settings.php'; + require_once BACKDROP_ROOT . '/core/modules/config/config.admin.inc'; + require_once BACKDROP_ROOT . '/core/includes/config.inc'; + $config_dir_active = config_get_config_directory('active'); + $config_dir_staging = config_get_config_directory('staging'); + $config_statuses = config_get_statuses(); + + // Prepare the table of config changes to show the user. + foreach($config_statuses as $key => $config_status) { + if ($config_status == 'update') { + $rows[] = array("\t", $key, "\033[33mupdate\033[0m"); + } + elseif ($config_status == 'delete') { + $rows[] = array("\t", $key, "\033[31mdelete\033[0m"); + } + elseif ($config_status == 'create') { + $rows[] = array("\t", $key, "\033[32mcreate\033[0m"); + } + } + + if (!empty($rows)) { + drush_print(dt("The following configuration changes will be imported: \n")); + $table = drush_format_table($rows); + drush_print_r($table); + } + else { + drush_log(dt("There are no configuration changes to import."), LogLevel::SUCCESS); + return; + } + + if(!drush_confirm(dt('Do you really want to continue?'))) { + return drush_user_abort(); + } + try { + if (!empty($config_dir_active)) { + passthru( + "rm -rf " . BACKDROP_ROOT . "/$config_dir_active/*" + ); + passthru( + "cp -R " . BACKDROP_ROOT . "/$config_dir_staging/ " . BACKDROP_ROOT . "/$config_dir_active" + ); + } + drush_log(dt('Configuration imported to !active', array('!active' => $config_dir_active)), LogLevel::SUCCESS); + } + catch (Exception $e) { + drush_log(dt("Configuration import failed. $e"), LogLevel::DEBUG); + } +} From ff4de6b3fb965aa6d090771b31496d92ccb903dc Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Wed, 23 Nov 2016 17:52:17 -0500 Subject: [PATCH 5/5] Adding bcex and bcim to commands array. --- backdrop.drush.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backdrop.drush.inc b/backdrop.drush.inc index dd009a0..b6c3673 100644 --- a/backdrop.drush.inc +++ b/backdrop.drush.inc @@ -68,6 +68,10 @@ function backdrop_drush_command_alter(&$command) { case 'config-export': $backdrop_command = 'backdrop-config-export'; break; + case 'config-import': + case 'backdrop-config-import': + $backdrop_command = 'backdrop-config-import'; + break; } // Commands that work with Backdrop with no adjustments.