Skip to content

Commit 7df8d2c

Browse files
committed
fix: issue importing production items when namespace has multiple productions
ported from CCR
1 parent 1cefb56 commit 7df8d2c

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

cls/SourceControl/Git/Production.cls

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ ClassMethod ImportPTD(externalName As %String, productionName As %String) As %St
149149
return sc
150150
}
151151

152+
/// Imports all PTDs within a given directory. Also recursively imports from all subdirectories
153+
ClassMethod ImportPTDsDir(directory As %String, isDecompMethod As %String = "") As %Status
154+
{
155+
set sc = $$$OK
156+
set rs = ##class(%ResultSet).%New("%File:FileSet")
157+
$$$ThrowOnError(rs.Execute(directory, "*.xml", "", 1))
158+
$$$ThrowSQLIfError(rs.%SQLCODE, rs.%Message)
159+
while rs.Next() {
160+
set path = rs.Data("Name")
161+
set type = rs.Data("Type")
162+
if type = "D" {
163+
set sc = ..ImportPTDsDir(path)
164+
} else {
165+
$$$ThrowOnError(..ParseExternalName(path, .internalName, .prodName))
166+
set srcCtrlCls = ##class(%Studio.SourceControl.Interface).SourceControlClassGet()
167+
set isDecomp = $select(isDecompMethod="":1, 1:$classMethod(srcCtrlCls, isDecompMethod, internalName))
168+
if isDecomp {
169+
set filename = ##class(%File).GetFilename(path)
170+
if ($extract(filename) = "P") && '$$$comClassDefined(prodName) {
171+
$$$ThrowOnError(..CreateProduction(prodName))
172+
}
173+
set sc = ..ImportPTD(path, prodName)
174+
}
175+
}
176+
}
177+
return sc
178+
}
179+
152180
/// Export a single Production Config Item. For a given Ens.Config.Item, the
153181
/// exports the PTD for this item to the file system under the directory specified
154182
ClassMethod ExportConfigItemSettings(productionClass As %String, item As %RegisteredObject, nameMethod As %String, Output internalName As %String) As %Status
@@ -270,10 +298,7 @@ ClassMethod GetModifiedItemsAfterSave(internalName, Output modifiedItems)
270298
/// Check if current CSP session is EnsPortal page
271299
ClassMethod IsEnsPortal() As %Boolean
272300
{
273-
If $IsObject($Get(%session)) && ($Get(%request.Data("pageclass","1")) [ "EnsPortal") {
274-
Return 1
275-
}
276-
Return 0
301+
Return $Data(%request) && '($IsObject(%request) && (%request.UserAgent [ "Code"))
277302
}
278303

279304
/// Perform check if Production Decomposition logic should be used for given item
@@ -334,7 +359,7 @@ ClassMethod ParseExternalName(externalName, Output internalName = "", Output pro
334359
/// - itemName: name of the configuration item
335360
/// - productionName: name of the associated production
336361
/// - isProdSettings: if true, this item is a production settings; if false, this item is a configuration item settings
337-
ClassMethod ParseInternalName(internalName, noFolders As %Boolean = 0, Output fileName, Output itemName, Output productionName, Output isProdSettings As %Boolean)
362+
ClassMethod ParseInternalName(internalName, noFolders As %Boolean = 0, Output fileName, Output itemName, Output itemClassName, Output productionName, Output isProdSettings As %Boolean)
338363
{
339364
set name = $piece(internalName,".",1,*-1)
340365
if 'noFolders {
@@ -394,11 +419,11 @@ ClassMethod RemoveItem(internalName, noFolders As %Boolean = 0) As %Status
394419
if '##class(%Library.EnsembleMgr).IsEnsembleNamespace() {
395420
quit
396421
}
397-
do ..ParseInternalName(internalName, noFolders, , .itemName, .productionName, .isProdSettings)
422+
do ..ParseInternalName(internalName, noFolders, , .itemName, .itemClassName, .productionName, .isProdSettings)
398423
if 'isProdSettings {
399424
set production = ##class(Ens.Config.Production).%OpenId(productionName,,.sc)
400425
quit:$$$ISERR(sc)
401-
set configItem = production.OpenItemByConfigName(itemName,.sc)
426+
set configItem = ##class(Ens.Config.Production).OpenItemByConfigName(productionName_"||"_itemName_"|"_itemClassName,.sc)
402427
quit:$$$ISERR(sc)
403428
do production.RemoveItem(configItem)
404429
set sc = production.%Save()

cls/SourceControl/Git/Utils.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ ClassMethod ImportItem(InternalName As %String, force As %Boolean = 0, verbose A
13451345
// ideally we could just new %SourceControl, but Ens portal config pages do not use %SourceControl
13461346
new %gscSkipSaveHooks
13471347
set %gscSkipSaveHooks = 1
1348-
do ##class(SourceControl.Git.Production).ParseInternalName(InternalName,,,,.targetProduction)
1348+
do ##class(SourceControl.Git.Production).ParseInternalName(InternalName,,,,,.targetProduction)
13491349
if (targetProduction '= "") && '$$$comClassDefined(targetProduction) {
13501350
set sc = ##class(SourceControl.Git.Production).CreateProduction(targetProduction)
13511351
}

0 commit comments

Comments
 (0)