@@ -21,7 +21,7 @@ public function update() {
21
21
}
22
22
23
23
/**
24
- * Import configuration from the config directory.
24
+ * Imports configuration from the config directory according to cm.strategy .
25
25
*
26
26
* @command setup:config-import
27
27
*/
@@ -52,49 +52,18 @@ public function import() {
52
52
53
53
switch ($ strategy ) {
54
54
case 'core-only ' :
55
- if (file_exists ($ this ->getConfigValue ("cm.core.dirs. $ cm_core_key.path " ) . '/core.extension.yml ' )) {
56
- $ task ->exec ("drush @ $ drush_alias config-import $ cm_core_key --yes " );
57
- }
55
+ $ this ->importCoreOnly ($ task , $ drush_alias , $ cm_core_key );
58
56
break ;
59
57
60
58
case 'config-split ' :
61
- // We cannot use ${cm.core.dirs.${cm.core.key}.path} here because
62
- // cm.core.key may be 'vcs', which does not have a path defined in
63
- // BLT config. Perhaps this should be refactored.
64
- $ core_config_file = $ this ->getConfigValue ('docroot ' ) . '/ ' . $ this ->getConfigValue ('cm.core.dirs.sync.path ' ) . '/core.extension.yml ' ;
65
- if (file_exists ($ core_config_file )) {
66
- $ task ->exec ("drush @ $ drush_alias pm-enable config_split --yes " );
67
- $ task ->exec ("drush @ $ drush_alias config-import sync --yes " );
68
- }
59
+ $ this ->importConfigSplit ($ task , $ drush_alias );
69
60
break ;
70
61
71
62
case 'features ' :
72
- $ task ->exec ("drush @ $ drush_alias config-import $ cm_core_key --partial --yes " );
73
- if ($ this ->getConfig ()->has ('cm.features.bundle" ' )) {
74
- $ task ->exec ("drush @ $ drush_alias pm-enable features --yes " );
75
- // Clear drush caches to register features drush commands.
76
- $ task ->exec ("drush cc drush --yes " );
77
- foreach ($ this ->getConfigValue ('cm.features.bundle ' ) as $ bundle ) {
78
- $ task ->exec ("drush @ $ drush_alias features-revert-all --bundle= $ bundle --yes " );
79
- // Revert all features again!
80
- // @see https://www.drupal.org/node/2851532
81
- $ task ->exec ("drush @ $ drush_alias features-revert-all --bundle= $ bundle --yes " );
82
- }
83
- }
84
- if ($ this ->getConfigValue ('cm.features.no-overrides ' )) {
85
- $ this ->say ("Checking for features overrides... " );
86
- if ($ this ->getConfig ()->has ('cm.features.bundle ' )) {
87
- foreach ($ this ->getConfigValue ('cm.features.bundle ' ) as $ bundle ) {
88
- $ features_overriden = $ task ->exec ("drush fl --bundle= $ {bundle} | grep -Ei '(changed|conflicts|added)( *)$ " );
89
- // @todo emit:
90
- // A feature in the ${bundle} bundle is overridden. You must
91
- // re-export this feature to incorporate the changes.
92
- // @todo throw Exception.
93
- }
94
- }
95
- }
63
+ $ this ->importFeatures ($ task , $ drush_alias , $ cm_core_key );
96
64
break ;
97
65
}
66
+
98
67
$ task ->exec ("drush @ $ drush_alias cache-rebuild " );
99
68
$ task ->run ();
100
69
@@ -103,4 +72,67 @@ public function import() {
103
72
}
104
73
}
105
74
75
+ /**
76
+ * Import configuration using core config management only.
77
+ *
78
+ * @param $task
79
+ * @param $drush_alias
80
+ * @param $cm_core_key
81
+ */
82
+ protected function importCoreOnly ($ task , $ drush_alias , $ cm_core_key ) {
83
+ if (file_exists ($ this ->getConfigValue ("cm.core.dirs. $ cm_core_key.path " ) . '/core.extension.yml ' )) {
84
+ $ task ->exec ("drush @ $ drush_alias config-import $ cm_core_key --yes " );
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Import configuration using config_split module.
90
+ *
91
+ * @param $task
92
+ * @param $drush_alias
93
+ */
94
+ protected function importConfigSplit ($ task , $ drush_alias ) {
95
+ // We cannot use ${cm.core.dirs.${cm.core.key}.path} here because
96
+ // cm.core.key may be 'vcs', which does not have a path defined in
97
+ // BLT config. Perhaps this should be refactored.
98
+ $ core_config_file = $ this ->getConfigValue ('docroot ' ) . '/ ' . $ this ->getConfigValue ('cm.core.dirs.sync.path ' ) . '/core.extension.yml ' ;
99
+ if (file_exists ($ core_config_file )) {
100
+ $ task ->exec ("drush @ $ drush_alias pm-enable config_split --yes " );
101
+ $ task ->exec ("drush @ $ drush_alias config-import sync --yes " );
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Import configuration using features module.
107
+ * @param $task
108
+ * @param $drush_alias
109
+ * @param $cm_core_key
110
+ */
111
+ protected function importFeatures ($ task , $ drush_alias , $ cm_core_key ) {
112
+ $ task ->exec ("drush @ $ drush_alias config-import $ cm_core_key --partial --yes " );
113
+ if ($ this ->getConfig ()->has ('cm.features.bundle" ' )) {
114
+ $ task ->exec ("drush @ $ drush_alias pm-enable features --yes " );
115
+ // Clear drush caches to register features drush commands.
116
+ $ task ->exec ("drush cc drush --yes " );
117
+ foreach ($ this ->getConfigValue ('cm.features.bundle ' ) as $ bundle ) {
118
+ $ task ->exec ("drush @ $ drush_alias features-revert-all --bundle= $ bundle --yes " );
119
+ // Revert all features again!
120
+ // @see https://www.drupal.org/node/2851532
121
+ $ task ->exec ("drush @ $ drush_alias features-revert-all --bundle= $ bundle --yes " );
122
+ }
123
+ }
124
+ if ($ this ->getConfigValue ('cm.features.no-overrides ' )) {
125
+ $ this ->say ("Checking for features overrides... " );
126
+ if ($ this ->getConfig ()->has ('cm.features.bundle ' )) {
127
+ foreach ($ this ->getConfigValue ('cm.features.bundle ' ) as $ bundle ) {
128
+ $ features_overriden = $ task ->exec ("drush fl --bundle= $ {bundle} | grep -Ei '(changed|conflicts|added)( *)$ " );
129
+ // @todo emit:
130
+ // A feature in the ${bundle} bundle is overridden. You must
131
+ // re-export this feature to incorporate the changes.
132
+ // @todo throw Exception.
133
+ }
134
+ }
135
+ }
136
+ }
137
+
106
138
}
0 commit comments