|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.databind.ObjectReader; |
4 | 4 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 5 | +import com.marklogic.appdeployer.AppConfig; |
5 | 6 | import com.marklogic.appdeployer.ConfigDir; |
6 | 7 | import com.marklogic.appdeployer.command.AbstractUndoableCommand; |
7 | 8 | import com.marklogic.appdeployer.command.CommandContext; |
| 9 | +import com.marklogic.appdeployer.command.ResourceFilenameFilter; |
8 | 10 | import com.marklogic.appdeployer.command.SortOrderConstants; |
9 | 11 | import com.marklogic.appdeployer.command.forests.DeployForestsCommand; |
10 | 12 | import com.marklogic.mgmt.PayloadParser; |
|
21 | 23 | import com.marklogic.rest.util.JsonNodeUtil; |
22 | 24 |
|
23 | 25 | import java.io.File; |
| 26 | +import java.io.FilenameFilter; |
24 | 27 | import java.io.IOException; |
25 | 28 | import java.util.*; |
26 | 29 |
|
@@ -134,8 +137,39 @@ public void undo(CommandContext context) { |
134 | 137 | // If no databases were found, may still need to delete the content database in case no file exists for it. |
135 | 138 | // That's because the command for creating a REST API server will not delete the content database by default, |
136 | 139 | // though it will delete the test database by default |
137 | | - DatabaseManager dbMgr = new DeployDatabaseCommand().newDatabaseManageForDeleting(context); |
138 | | - dbMgr.deleteByName(context.getAppConfig().getContentDatabaseName()); |
| 140 | + if (deleteContentDatabaseOnUndo(databasePlans, context.getAppConfig())) { |
| 141 | + DatabaseManager dbMgr = new DeployDatabaseCommand().newDatabaseManageForDeleting(context); |
| 142 | + dbMgr.deleteByName(context.getAppConfig().getContentDatabaseName()); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * If no database files are found, may still need to delete the content database in case no file exists for it. |
| 148 | + * That's because the command for creating a REST API server will not delete the content database by default. |
| 149 | + * |
| 150 | + * Per ticket #404, this will now do a check to see if the default content database filename is ignored. If so, |
| 151 | + * and there are no database files found, then the content database will not be deleted. |
| 152 | + * |
| 153 | + * @param databasePlans |
| 154 | + * @param appConfig |
| 155 | + * @return |
| 156 | + */ |
| 157 | + protected boolean deleteContentDatabaseOnUndo(List<DatabasePlan> databasePlans, AppConfig appConfig) { |
| 158 | + if (databasePlans == null || databasePlans.isEmpty()) { |
| 159 | + FilenameFilter filter = getResourceFilenameFilter(); |
| 160 | + if (filter != null && filter instanceof ResourceFilenameFilter) { |
| 161 | + Set<String> filenamesToIgnore = ((ResourceFilenameFilter) filter).getFilenamesToIgnore(); |
| 162 | + if (filenamesToIgnore != null && !filenamesToIgnore.isEmpty() && appConfig.getConfigDirs() != null) { |
| 163 | + for (ConfigDir configDir : appConfig.getConfigDirs()) { |
| 164 | + if (filenamesToIgnore.contains(configDir.getDefaultContentDatabaseFilename())) { |
| 165 | + return false; |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + return true; |
| 171 | + } |
| 172 | + return false; |
139 | 173 | } |
140 | 174 |
|
141 | 175 | /** |
|
0 commit comments