Skip to content

Commit d04fa4e

Browse files
committed
Port production changes from CCR
1 parent c0ae6bd commit d04fa4e

File tree

1 file changed

+81
-14
lines changed

1 file changed

+81
-14
lines changed

cls/SourceControl/Git/Production.cls

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ ClassMethod ExportProductionDefinitionShards(productionClass As %String, nameMet
3535
Return $$$OK
3636
}
3737

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+
3869
/// Exports a Studio project including both the provided PTD and export notes for the PTD
3970
ClassMethod ExportProjectForPTD(productionClass, ptdName, exportPath) As %Status
4071
{
@@ -101,6 +132,15 @@ ClassMethod ExportPTD(internalName As %String, nameMethod) As %Status
101132
Return sc
102133
}
103134

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+
104144
/// Export a single Production Config Item. For a given Ens.Config.Item, the
105145
/// exports the PTD for this item to the file system under the directory specified
106146
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
164204
set modifiedInternalName = ..CreateInternalName(productionName,,,1)
165205
}
166206
}
167-
if (modifiedInternalName '= "") {
207+
if ($get(modifiedInternalName) '= "") {
168208
set modifiedItems(modifiedInternalName) = "M"
169209
}
170210
} else {
@@ -234,10 +274,18 @@ ClassMethod IsProductionClass(className As %String, nameMethod As %String) As %B
234274
if (className '= "") && $$$comClassDefined(className) {
235275
return $classmethod(className, "%Extends", "Ens.Production")
236276
} 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
237284
set filename = $classmethod(##class(%Studio.SourceControl.Interface).SourceControlClassGet(), nameMethod, className_".CLS")
238285
if ##class(%File).Exists(filename) {
239286
$$$ThrowOnError($System.OBJ.Load(filename))
240287
}
288+
// if Production exists as a class definition on the server, check if extending Ens.Production
241289
set classDef = ##class(%Dictionary.ClassDefinition).%OpenId(className)
242290
if $isobject(classDef) && ##class(%Dictionary.ClassDefinition).%ExistsId(classDef.Super) {
243291
return $classmethod(classDef.Super, "%Extends", "Ens.Production")
@@ -247,25 +295,31 @@ ClassMethod IsProductionClass(className As %String, nameMethod As %String) As %B
247295
}
248296

249297
/// 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
251299
{
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")
262313
set settingsPTDText = $zconvert(deployDoc.GetValueAt("/Export/Document[2]/1"),"I","XML")
263314
set settingsPTD = ##class(EnsLib.EDI.XML.Document).%New(settingsPTDText)
264315
set itemClass = settingsPTD.GetValueAt("/Item/@ClassName")
265316
set itemName = settingsPTD.GetValueAt("/Item/@Name")
266317
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+
}
268321
}
322+
return sc
269323
}
270324

271325
/// 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
295349
}
296350

297351
/// 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
299353
{
300354
return $select(
301355
isProductionSettings: productionName_"||ProductionSettings-"_productionName_".PTD",
@@ -370,4 +424,17 @@ ClassMethod CreateProduction(productionName As %String, superClasses = "") As %S
370424
return sc
371425
}
372426

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+
373440
}

0 commit comments

Comments
 (0)