@@ -35,6 +35,37 @@ ClassMethod ExportProductionDefinitionShards(productionClass As %String, nameMet
35
35
Return $$$OK
36
36
}
37
37
38
+ /// Removes settings for a given Production and each Config Item from
39
+ /// source control. This marks each of them for delete and is triggered
40
+ /// by deleting a decomposed Production.
41
+ ClassMethod DeleteProductionDefinitionShards (productionClass As %String , deleteMethod As %String , nameMethod As %String ) As %Status
42
+ {
43
+ set sc = $$$OK
44
+ if '$isobject ($get (%SourceControl )) {
45
+ new %SourceControl
46
+ $$$ThrowOnError(##class (%Studio.SourceControl.Interface ).SourceControlCreate ())
47
+ }
48
+ set settingsPTD = ..CreateInternalName (productionClass ,,,1 )
49
+ set sourceControlClass = ##class (%Studio.SourceControl.Interface ).SourceControlClassGet ()
50
+ set settingsPTDFile = $classmethod (sourceControlClass , nameMethod , settingsPTD )
51
+ // if the Production settings PTD exists, delete all PTDs for this Production
52
+ if ##class (%File ).Exists (settingsPTDFile ) {
53
+ set ptdDir = ##class (%File ).GetDirectory (settingsPTDFile )
54
+ set rs = ##class (%ResultSet ).%New (" %File:FileSet" )
55
+ $$$ThrowOnError(rs .Execute (ptdDir , " *.xml" ))
56
+ $$$ThrowSQLIfError(rs .%SQLCODE , rs .%Message )
57
+ while rs .Next () {
58
+ set ptdFilename = rs .Data (" Name" )
59
+ set sc = ##class (%Studio.SourceControl.Production ).ParseExternalName (ptdFilename , .ptdInternalName )
60
+ quit :$$$ISERR(sc )
61
+ // TODO: Consider reverting delete if any ptd is not editable by current user
62
+ set sc = $method (%SourceControl , deleteMethod , ptdInternalName )
63
+ quit :$$$ISERR(sc )
64
+ }
65
+ }
66
+ return sc
67
+ }
68
+
38
69
/// Exports a Studio project including both the provided PTD and export notes for the PTD
39
70
ClassMethod ExportProjectForPTD (productionClass , ptdName , exportPath ) As %Status
40
71
{
@@ -101,6 +132,15 @@ ClassMethod ExportPTD(internalName As %String, nameMethod) As %Status
101
132
Return sc
102
133
}
103
134
135
+ /// Imports a PTD into a produciton given an external name and produciton name
136
+ ClassMethod ImportPTD (externalName As %String , productionName As %String ) As %Status
137
+ {
138
+ set rollbackFile = ##class (%File ).TempFilename ()
139
+ set sc = ##class (Ens.Deployment.Deploy ).DeployCode (externalName ,productionName ,0 ,rollbackFile )
140
+ do ##class (%File ).Delete (rollbackFile )
141
+ return sc
142
+ }
143
+
104
144
/// Export a single Production Config Item. For a given Ens.Config.Item, the
105
145
/// exports the PTD for this item to the file system under the directory specified
106
146
ClassMethod ExportConfigItemSettings (productionClass As %String , item As %RegisteredObject , nameMethod As %String , Output internalName As %String ) As %Status
@@ -164,7 +204,7 @@ ClassMethod GetModifiedItemsBeforeSave(internalName, Location, Output modifiedIt
164
204
set modifiedInternalName = ..CreateInternalName (productionName ,,,1 )
165
205
}
166
206
}
167
- if (modifiedInternalName '= " " ) {
207
+ if ($get ( modifiedInternalName ) '= " " ) {
168
208
set modifiedItems (modifiedInternalName ) = " M"
169
209
}
170
210
} else {
@@ -234,10 +274,18 @@ ClassMethod IsProductionClass(className As %String, nameMethod As %String) As %B
234
274
if (className '= " " ) && $$$comClassDefined(className ) {
235
275
return $classmethod (className , " %Extends" , " Ens.Production" )
236
276
} else {
277
+ // check if there exists a Production settings PTD export for ths Production
278
+ set settingsPTD = ..CreateInternalName (className ,,,1 )
279
+ set settingsPTDFilename = $classmethod (##class (%Studio.SourceControl.Interface ).SourceControlClassGet (), nameMethod , settingsPTD )
280
+ if ##class (%File ).Exists (settingsPTDFilename ) {
281
+ return 1
282
+ }
283
+ // check if there is a class export for this Production, load it for class definition
237
284
set filename = $classmethod (##class (%Studio.SourceControl.Interface ).SourceControlClassGet (), nameMethod , className _" .CLS" )
238
285
if ##class (%File ).Exists (filename ) {
239
286
$$$ThrowOnError($System .OBJ .Load (filename ))
240
287
}
288
+ // if Production exists as a class definition on the server, check if extending Ens.Production
241
289
set classDef = ##class (%Dictionary.ClassDefinition ).%OpenId (className )
242
290
if $isobject (classDef ) && ##class (%Dictionary.ClassDefinition ).%ExistsId (classDef .Super ) {
243
291
return $classmethod (classDef .Super , " %Extends" , " Ens.Production" )
@@ -247,25 +295,31 @@ ClassMethod IsProductionClass(className As %String, nameMethod As %String) As %B
247
295
}
248
296
249
297
/// Given a file name for a PTD item, returns a suggested internal name. This method assumes that the file exists on disk.
250
- ClassMethod ParseExternalName (externalName , Output internalName = " " , Output productionName = " " )
298
+ ClassMethod ParseExternalName (externalName , Output internalName = " " , Output productionName = " " ) As %Status
251
299
{
252
- if ##class (%File ).Exists (externalName ) {
253
- set file = $piece (externalName , " /" , *)
254
- set deployDoc = ##class (EnsLib.EDI.XML.Document ).%New (externalName )
255
- set exportNotesPTDText = $ZCVT (deployDoc .GetValueAt (" /Export/Document[1]/1" )," I" ," XML" )
256
- set exportNotesPTD = ##class (EnsLib.EDI.XML.Document ).%New (exportNotesPTDText )
257
- set productionName = exportNotesPTD .GetValueAt (" /Deployment/Creation/SourceProduction" )
258
- if $extract (file ,1 ,9 ) = " ProdStgs-" {
259
- set internalName = ..CreateInternalName (productionName ,,,1 )
260
- } else {
261
- // Special case for Config Item Settings PTD, requires checking PTD CDATA for Item and Class name
300
+ set sc = $$$OK
301
+ set extNameNormalized = $replace (externalName , " \" , " /" )
302
+ set file = $piece (extNameNormalized , " /" , *)
303
+ if $extract (file ,1 ,9 ) = " ProdStgs-" {
304
+ set productionName = $replace ($extract (file ,10 ,*-4 ), " _" , " ." )
305
+ set internalName = ..CreateInternalName (productionName ,,,1 )
306
+ } else {
307
+ if ##class (%File ).Exists (externalName ) {
308
+ // Special case for Config Item Settings PTD, requires checking PTD CDATA for Item and Class name
309
+ set deployDoc = ##class (EnsLib.EDI.XML.Document ).%New (externalName )
310
+ set exportNotesPTDText = $ZCVT (deployDoc .GetValueAt (" /Export/Document[1]/1" )," I" ," XML" )
311
+ set exportNotesPTD = ##class (EnsLib.EDI.XML.Document ).%New (exportNotesPTDText )
312
+ set productionName = exportNotesPTD .GetValueAt (" /Deployment/Creation/SourceProduction" )
262
313
set settingsPTDText = $zconvert (deployDoc .GetValueAt (" /Export/Document[2]/1" )," I" ," XML" )
263
314
set settingsPTD = ##class (EnsLib.EDI.XML.Document ).%New (settingsPTDText )
264
315
set itemClass = settingsPTD .GetValueAt (" /Item/@ClassName" )
265
316
set itemName = settingsPTD .GetValueAt (" /Item/@Name" )
266
317
set internalName = ..CreateInternalName (productionName , itemName , itemClass , 0 )
267
- }
318
+ } else {
319
+ set sc = $$$ERROR($$$GeneralError, " Item settings PTD file " _ externalName _ " does not exist. Cannot parse external name." )
320
+ }
268
321
}
322
+ return sc
269
323
}
270
324
271
325
/// Given an internal name for a PTD item, returns a suggested filename for export, as well as:
@@ -295,7 +349,7 @@ ClassMethod ParseInternalName(internalName, noFolders As %Boolean = 0, Output fi
295
349
}
296
350
297
351
/// Calculates the internal name for a decomposed production item
298
- ClassMethod CreateInternalName (productionName = " " , itemName = " " , itemClassName = " " , isProductionSettings As %Boolean = 0 )
352
+ ClassMethod CreateInternalName (productionName = " " , itemName = " " , itemClassName = " " , isProductionSettings As %Boolean = 0 ) As %String
299
353
{
300
354
return $select (
301
355
isProductionSettings : productionName _" ||ProductionSettings-" _productionName _" .PTD" ,
@@ -370,4 +424,17 @@ ClassMethod CreateProduction(productionName As %String, superClasses = "") As %S
370
424
return sc
371
425
}
372
426
427
+ /// Given an internal name of a Production and an IRIS user, populate an array with the filenames
428
+ /// for each of their current uncommitted changes associated with the given Production
429
+ ClassMethod GetUserProductionChanges (productionName As %String , ByRef items )
430
+ {
431
+ set sql = " SELECT InternalName, Action FROM %Studio_SourceControl.Change WHERE ChangedBy = ? AND Committed = 0 AND InternalName %STARTSWITH ?"
432
+ set rs = ##class (%SQL.Statement ).%ExecDirect (,sql ,$username ,productionName _" ||" )
433
+ $$$ThrowSQLIfError(rs .%SQLCODE , rs .%Message )
434
+ while rs .%Next () {
435
+ set items (rs .InternalName ) = rs .Action
436
+ }
437
+ quit $$$OK
438
+ }
439
+
373
440
}
0 commit comments