@@ -18,6 +18,11 @@ class ImportFromRemoteCommand extends Command
18
18
{
19
19
private const ARGUMENT_PROJECT_NAME = 'source-project-name ' ;
20
20
private const OPTION_NO_ADMIN_ACCOUNT_BACKUP = 'no-admin-backup ' ;
21
+ private const OPTION_CONFIG_DATA_BACKUP = 'config-backup ' ;
22
+
23
+ private CONST VALUE_CONFIG_SKIP = 'skip ' ;
24
+ private CONST VALUE_CONFIG_PRESERVE = 'preserve-local ' ;
25
+ private CONST VALUE_CONFIG_MERGE = 'merge ' ;
21
26
22
27
private const SUCCESS = 1 ;
23
28
@@ -47,6 +52,13 @@ protected function configure()
47
52
'Set this flag to skip backup of local admin accounts ' ,
48
53
false
49
54
);
55
+ $ this ->addOption (
56
+ self ::OPTION_CONFIG_DATA_BACKUP ,
57
+ null ,
58
+ InputOption::VALUE_OPTIONAL ,
59
+ 'Set this flag to back up the whole core_config_data table ' ,
60
+ self ::VALUE_CONFIG_MERGE
61
+ );
50
62
}
51
63
52
64
/**
@@ -68,6 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
68
80
try {
69
81
$ sourceProjectMeta = new ProjectMeta ($ input ->getArgument (self ::ARGUMENT_PROJECT_NAME ));
70
82
$ backupAdminAccounts = !$ input ->getOption (self ::OPTION_NO_ADMIN_ACCOUNT_BACKUP );
83
+ $ backupConfig = $ this ->getConfigBackupOption ($ input );
71
84
72
85
$ output ->writeln ('<fg=cyan;options=bold>Downloading Database From Cloud Storage...</> ' );
73
86
$ this ->dbFacade ->downloadDatabaseDump ($ sourceProjectMeta );
@@ -84,6 +97,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
84
97
$ this ->dbFacade ->backupLocalAdminAccounts ($ sourceProjectMeta );
85
98
}
86
99
100
+ if ($ backupConfig === self ::VALUE_CONFIG_PRESERVE ) {
101
+ $ output ->writeln ('<fg=cyan;options=bold>Backing up config ...</> ' );
102
+ $ this ->dbFacade ->backupLocalConfig ($ sourceProjectMeta );
103
+ } else if ($ backupConfig === self ::VALUE_CONFIG_MERGE ) {
104
+ $ output ->writeln ('<fg=cyan;options=bold>Backing up preconfigured config paths ...</> ' );
105
+ $ this ->dbFacade ->backupConfigValues ($ sourceProjectMeta );
106
+ }
107
+
87
108
$ output ->writeln ("<info>Starting the Database import</info> " );
88
109
$ this ->dbFacade ->importDatabaseDump ($ sourceProjectMeta );
89
110
$ output ->writeln ("<info>Database successfully imported.</info> " );
@@ -92,17 +113,37 @@ protected function execute(InputInterface $input, OutputInterface $output): int
92
113
$ output ->writeln ('<fg=cyan;options=bold>Restoring local admin accounts ...</> ' );
93
114
$ this ->dbFacade ->restoreLocalAdminAccountsFromBackup ($ sourceProjectMeta );
94
115
}
116
+
117
+ if ($ backupConfig === self ::VALUE_CONFIG_PRESERVE ) {
118
+ $ output ->writeln ('<fg=cyan;options=bold>Restoring config ...</> ' );
119
+ $ this ->dbFacade ->restoreLocalConfigFromBackup ($ sourceProjectMeta );
120
+ } else if ($ backupConfig === self ::VALUE_CONFIG_MERGE ) {
121
+ $ output ->writeln ('<fg=cyan;options=bold>Restoring preconfigured config paths ...</> ' );
122
+ $ this ->dbFacade ->restoreConfigValues ();
123
+ }
95
124
} catch (Exception $ e ) {
96
125
$ output ->writeln ("<error> {$ e ->getMessage ()}</error> " );
97
126
} finally {
98
127
if (isset ($ sourceProjectMeta )) {
99
128
$ this ->dbFacade ->cleanUpLocalDumpFiles ($ sourceProjectMeta );
100
129
}
101
- if ($ backupAdminAccounts ) {
130
+ if (isset ( $ backupAdminAccounts ) && $ backupAdminAccounts ) {
102
131
$ this ->dbFacade ->cleanUpAdminAccountsBackup ($ sourceProjectMeta );
103
132
}
133
+ if (isset ($ backupConfig ) && $ backupConfig === self ::VALUE_CONFIG_PRESERVE ) {
134
+ $ this ->dbFacade ->cleanUpConfigBackup ($ sourceProjectMeta );
135
+ }
104
136
}
105
137
106
138
return self ::SUCCESS ;
107
139
}
140
+
141
+ private function getConfigBackupOption (InputInterface $ input ): string
142
+ {
143
+ $ configBackupOption = $ input ->getOption (self ::OPTION_CONFIG_DATA_BACKUP );
144
+ if (!in_array ($ configBackupOption , [self ::VALUE_CONFIG_SKIP , self ::VALUE_CONFIG_PRESERVE , self ::VALUE_CONFIG_MERGE ])) {
145
+ $ configBackupOption = self ::VALUE_CONFIG_MERGE ;
146
+ }
147
+ return $ configBackupOption ;
148
+ }
108
149
}
0 commit comments