@@ -101,7 +101,7 @@ ClassMethod ExportPTD(internalName As %String, nameMethod) As %Status
101
101
/// exports the PTD for this item to the file system under the directory specified
102
102
ClassMethod ExportConfigItemSettings (productionClass As %String , item As %RegisteredObject , nameMethod As %String ) As %Status
103
103
{
104
- Set internalName = productionClass _ " ||Settings- " _ item . Name _ " | " _ item . ClassName _ " .PTD "
104
+ set internalName = .. CreateInternalName ( productionClass , item . Name , item . ClassName , 0 )
105
105
Set externalName = $ClassMethod ($$SrcCtrlCls ^%buildccr , nameMethod , internalName )
106
106
Set filename = ##class (%File ).NormalizeFilename (externalName )
107
107
set st = ##class (Ens.Deployment.Utils ).CreatePTDFromItem (.item , .ptdName )
@@ -115,7 +115,7 @@ ClassMethod ExportConfigItemSettings(productionClass As %String, item As %Regist
115
115
/// class name
116
116
ClassMethod ExportProductionSettings (productionClass As %String , nameMethod As %String ) As %Status
117
117
{
118
- Set internalName = productionClass _ " ||ProductionSettings- " _ productionClass _ " .PTD "
118
+ set internalName = .. CreateInternalName ( productionClass ,,, 0 )
119
119
Set class = ##class (%Dictionary.CompiledClass ).%OpenId (productionClass )
120
120
Set sc = ##class (Ens.Deployment.Utils ).CreatePTDFromProduction (class , .ptdName )
121
121
If $$$ISERR(sc ) {
@@ -153,11 +153,11 @@ ClassMethod GetModifiedItemsBeforeSave(internalName, Location, Output modifiedIt
153
153
}
154
154
set modifiedInternalName = " "
155
155
if $isobject (modifiedItem ) {
156
- set modifiedInternalName = productionName _ " ||Settings- " _ modifiedItem .Name _ " | " _ modifiedItem .ClassName _ " .PTD "
156
+ set modifiedInternalName = .. CreateInternalName ( productionName , modifiedItem .Name , modifiedItem .ClassName , 0 )
157
157
} else {
158
158
// cannot check %IsModified on production config settings because they are not actually modified at this point.
159
159
// workaround: just assume any change not to a specific item is to the production settings
160
- set modifiedInternalName = productionName _ " ||ProductionSettings- " _ productionName _ " .PTD "
160
+ set modifiedInternalName = .. CreateInternalName ( productionName ,,, 1 )
161
161
}
162
162
}
163
163
if (modifiedInternalName '= " " ) {
@@ -193,14 +193,14 @@ ClassMethod GetModifiedItemsAfterSave(internalName, Output modifiedItems)
193
193
$$$ThrowSQLIfError(rs .%SQLCODE , rs .%Message )
194
194
while rs .%Next () {
195
195
if '$get (^mtempsscProd ($job ," items" , $listbuild (rs .Name , rs .ClassName ))) {
196
- set itemInternalName = productionName _ " ||Settings- " _ rs .Name _ " | " _ rs .ClassName _ " .PTD "
196
+ set itemInternalName = .. CreateInternalName ( productionName , rs .Name , rs .ClassName , 0 )
197
197
set modifiedItems (itemInternalName ) = " A"
198
198
}
199
199
kill ^mtempsscProd ($job ," items" , $listbuild (rs .Name , rs .ClassName ))
200
200
}
201
201
set key = $order (^mtempsscProd ($job ," items" ," " ))
202
202
while (key '= " " ) {
203
- set itemInternalName = productionName _ " ||Settings- " _ $listget (key ,1 ) _ " | " _ $listget (key ,2 ) _ " .PTD "
203
+ set itemInternalName = .. CreateInternalName ( productionName , $listget (key ,1 ), $listget (key ,2 ), 0 )
204
204
set modifiedItems (itemInternalName ) = " D"
205
205
set key = $order (^mtempsscProd ($job ," items" ,key ))
206
206
}
@@ -242,23 +242,25 @@ ClassMethod IsProductionClass(className As %String, nameMethod As %String) As %B
242
242
return 0
243
243
}
244
244
245
- /// Given a file name for a PTD item, returns a suggested internal name.
246
- ClassMethod ParseExternalName (externalName , Output internalName )
245
+ /// Given a file name for a PTD item, returns a suggested internal name. This method assumes that the file exists on disk.
246
+ ClassMethod ParseExternalName (externalName , Output internalName = " " , Output productionName = " " )
247
247
{
248
- set file = $piece (externalName , " /" , *)
249
- set deployDoc = ##class (EnsLib.EDI.XML.Document ).%New (externalName )
250
- set exportNotesPTDText = $ZCVT (deployDoc .GetValueAt (" /Export/Document[1]/1" )," I" ," XML" )
251
- set exportNotesPTD = ##class (EnsLib.EDI.XML.Document ).%New (exportNotesPTDText )
252
- set productionName = exportNotesPTD .GetValueAt (" /Deployment/Creation/SourceProduction" )
253
- if $extract (file ,1 ,9 ) = " ProdStgs-" {
254
- set internalName = productionName _" ||ProductionSettings-" _productionName _" .PTD"
255
- } else {
256
- // Special case for Config Item Settings PTD, requires checking PTD CDATA for Item and Class name
257
- set settingsPTDText = $zconvert (deployDoc .GetValueAt (" /Export/Document[2]/1" )," I" ," XML" )
258
- set settingsPTD = ##class (EnsLib.EDI.XML.Document ).%New (settingsPTDText )
259
- set itemClass = settingsPTD .GetValueAt (" /Item/@ClassName" )
260
- set itemName = settingsPTD .GetValueAt (" /Item/@Name" )
261
- set internalName = productionName _" ||Settings-" _itemName _" |" _itemClass _" .PTD"
248
+ if ##class (%File ).Exists (externalName ) {
249
+ set file = $piece (externalName , " /" , *)
250
+ set deployDoc = ##class (EnsLib.EDI.XML.Document ).%New (externalName )
251
+ set exportNotesPTDText = $ZCVT (deployDoc .GetValueAt (" /Export/Document[1]/1" )," I" ," XML" )
252
+ set exportNotesPTD = ##class (EnsLib.EDI.XML.Document ).%New (exportNotesPTDText )
253
+ set productionName = exportNotesPTD .GetValueAt (" /Deployment/Creation/SourceProduction" )
254
+ if $extract (file ,1 ,9 ) = " ProdStgs-" {
255
+ set internalName = ..CreateInternalName (productionName ,,,1 )
256
+ } else {
257
+ // Special case for Config Item Settings PTD, requires checking PTD CDATA for Item and Class name
258
+ set settingsPTDText = $zconvert (deployDoc .GetValueAt (" /Export/Document[2]/1" )," I" ," XML" )
259
+ set settingsPTD = ##class (EnsLib.EDI.XML.Document ).%New (settingsPTDText )
260
+ set itemClass = settingsPTD .GetValueAt (" /Item/@ClassName" )
261
+ set itemName = settingsPTD .GetValueAt (" /Item/@Name" )
262
+ set internalName = ..CreateInternalName (productionName , itemName , itemClass , 0 )
263
+ }
262
264
}
263
265
}
264
266
@@ -288,6 +290,36 @@ ClassMethod ParseInternalName(internalName, noFolders As %Boolean = 0, Output fi
288
290
set fileName = $translate ($replace (name , " ." , " _" ) _ " .xml" , " \" , " /" )
289
291
}
290
292
293
+ /// Calculates the internal name for a decomposed production item
294
+ ClassMethod CreateInternalName (productionName = " " , itemName = " " , itemClassName = " " , isProductionSettings As %Boolean = 0 )
295
+ {
296
+ return $select (
297
+ isProductionSettings : productionName _" ||ProductionSettings-" _productionName _" .PTD" ,
298
+ 1 : productionName _ " ||Settings-" _ itemName _ " |" _ itemClassName _ " .PTD"
299
+ )
300
+ }
301
+
302
+ /// Given an external name for a PTD item, removes that item from the production.
303
+ ClassMethod RemoveItemByExternalName (externalName , nameMethod ) As %Status
304
+ {
305
+ set sc = $$$OK
306
+ set productionName = $replace ($piece ($replace (externalName ," \" ," /" )," /" ,*-1 )," _" ," ." )
307
+ set production = ##class (Ens.Config.Production ).%OpenId (productionName ,,.sc )
308
+ $$$QuitOnError(sc )
309
+ set itemToRemove = $$$NULLOREF
310
+ for i =1 :1 :production .Items .Count () {
311
+ set configItem = production .Items .GetAt (i )
312
+ set itemInternalName = ..CreateInternalName (productionName , configItem .Name , configItem .ClassName )
313
+ set itemExternalName = $classmethod ($$SrcCtrlCls ^%buildccr , nameMethod , itemInternalName )
314
+ if itemExternalName = externalName {
315
+ set itemToRemove = configItem
316
+ quit
317
+ }
318
+ }
319
+ do production .RemoveItem (itemToRemove )
320
+ return production .%Save ()
321
+ }
322
+
291
323
/// Given an internal name for a PTD item, removes that item from the production.
292
324
ClassMethod RemoveItem (internalName , noFolders As %Boolean = 0 ) As %Status
293
325
{
0 commit comments