Skip to content

Commit 391fd88

Browse files
committed
port production class changes from %Studio.SourceControl
1 parent 1f7dd47 commit 391fd88

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

cls/SourceControl/Git/Production.cls

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
/// This class serves as an intermediary for managing Source Control for Productions.
2-
/// Included is handling for exporting Productions as individual pieces of settings
3-
/// and importing individual item settings.
1+
/// This is a replica of %Studio.SourceControl.Production for backwards compatibility with older IRIS versions.
42
Class SourceControl.Git.Production Extends %RegisteredObject
53
{
64

5+
/// This Parameter should be updated when synced from Perforce
6+
Parameter SrcVer = "$Id: //custom_ccrs/_common/config/cls/Studio/SourceControl/Production.xml#3 $";
7+
8+
/// Revision number of this class when compiled as part of the //custom_ccrs/_common/config/... branch.
9+
/// This version will not be updated (by design) when the class is integrated to other branches.
10+
/// This allows the user to tell what version of the Studio client tools are in use.
11+
Parameter Version = 4;
12+
713
/// Exports settings for a given Production and each Config Item from
814
/// the ProductionDefinition as separate XMLs. These are exported to
915
/// the appropriate file based on nameMethod of the source control class
@@ -159,9 +165,16 @@ ClassMethod ExportPTD(internalName As %String, nameMethod) As %Status
159165
/// Imports a PTD into a produciton given an external name and produciton name
160166
ClassMethod ImportPTD(externalName As %String, productionName As %String) As %Status
161167
{
162-
set rollbackFile = ##class(%File).TempFilename()
163-
set sc = ##class(Ens.Deployment.Deploy).DeployCode(externalName,productionName,0,rollbackFile)
164-
do ##class(%File).Delete(rollbackFile)
168+
try {
169+
set ^IRIS.Temp("sscProd",$job,"bypassLock") = 1
170+
set rollbackFile = ##class(%File).TempFilename()
171+
set sc = ##class(Ens.Deployment.Deploy).DeployCode(externalName,productionName,0,rollbackFile)
172+
do ##class(%File).Delete(rollbackFile)
173+
kill ^IRIS.Temp("sscProd",$job,"bypassLock")
174+
} catch err {
175+
kill ^IRIS.Temp("sscProd",$job,"bypassLock")
176+
set sc = err.AsStatus()
177+
}
165178
return sc
166179
}
167180

@@ -171,7 +184,7 @@ ClassMethod ImportPTDsDir(directory As %String, isDecompMethod As %String = "")
171184
set sc = $$$OK
172185
set rs = ##class(%ResultSet).%New("%File:FileSet")
173186
$$$ThrowOnError(rs.Execute(directory, "*.xml", "", 1))
174-
$$$ThrowSQLIfError(rs.%SQLCODE, rs.%Message)
187+
throw:rs.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(rs.%SQLCODE, rs.%Message)
175188
while rs.Next() {
176189
set path = rs.Data("Name")
177190
set type = rs.Data("Type")
@@ -347,13 +360,16 @@ ClassMethod IsProductionClass(className As %String, nameMethod As %String) As %B
347360
}
348361
// check if there is a class export for this Production, load it for class definition
349362
set filename = $classmethod(##class(%Studio.SourceControl.Interface).SourceControlClassGet(), nameMethod, className_".CLS")
350-
if ##class(%File).Exists(filename) {
363+
if ##class(%File).Exists(filename) && (##class(%File).GetFileSize(filename) '= 0) {
351364
$$$ThrowOnError($System.OBJ.Load(filename))
352365
}
353366
// if Production exists as a class definition on the server, check if extending Ens.Production
354367
set classDef = ##class(%Dictionary.ClassDefinition).%OpenId(className)
355-
if $isobject(classDef) && ##class(%Dictionary.ClassDefinition).%ExistsId(classDef.Super) {
356-
return $classmethod(classDef.Super, "%Extends", "Ens.Production")
368+
if $isobject(classDef) {
369+
for i=1:1:classDef.XDatas.Count() {
370+
set xdata = classDef.XDatas.GetAt(i)
371+
if xdata.Name = "ProductionDefinition" return 1
372+
}
357373
}
358374
}
359375
return 0
@@ -505,6 +521,7 @@ ClassMethod GetUserProductionChanges(productionName As %String, ByRef items)
505521
/// Executes a SQL query without privilege checking if possible on this IRIS version
506522
ClassMethod ExecDirectNoPriv(sql, args...) As %SQL.StatementResult
507523
{
524+
// once minimum version is IRIS 2021.1.3, remove and just use %ExecDirectNoPriv
508525
try {
509526
set rs = ##class(%SQL.Statement).%ExecDirectNoPriv(,sql,args...)
510527
} catch err {
@@ -513,4 +530,24 @@ ClassMethod ExecDirectNoPriv(sql, args...) As %SQL.StatementResult
513530
return rs
514531
}
515532

533+
/// Handles all compile-time logic for this class
534+
ClassMethod OnToolsCompile() [ CodeMode = objectgenerator, Internal ]
535+
{
536+
For i = 1:1:%class.Parameters.Count() {
537+
If %class.Parameters.GetAt(i).Name = "SrcVer" Set valSrcVer = %class.Parameters.GetAt(i).Default
538+
If %class.Parameters.GetAt(i).Name = "Version" Set indexVersion=i
539+
}
540+
If $D(indexVersion)&&($G(valSrcVer)["//custom_ccrs/_common/config/") {
541+
Set %class.Parameters.GetAt(indexVersion).Default = $P($G(valSrcVer),"#",2)+1
542+
Do %class.Parameters.GetAt(indexVersion).%Save()
543+
}
544+
Quit $$$OK
545+
}
546+
547+
/// Returns value the Major.Minor version for this instance, so it can be used in comparison code which makes sure certain features are used in appropriate versions
548+
ClassMethod InstanceVersion() As %Numeric [ CodeMode = expression ]
549+
{
550+
$P($SYSTEM.Version.GetNumber(),".",1,2)
551+
}
552+
516553
}

0 commit comments

Comments
 (0)