|
| 1 | +Class SourceControl.Git.DiscardState Extends (%Persistent, %JSON.Adaptor) |
| 2 | +{ |
| 3 | + |
| 4 | +Property FullExternalName As %String(MAXLEN = "") [ Required ]; |
| 5 | + |
| 6 | +Property InternalName As %String [ Required ]; |
| 7 | + |
| 8 | +Property Contents As %Stream.GlobalCharacter(LOCATION = "^DiscardStateContents"); |
| 9 | + |
| 10 | +Property Username As %String [ Required ]; |
| 11 | + |
| 12 | +Property Branch As %String [ Required ]; |
| 13 | + |
| 14 | +Property Timestamp As %TimeStamp [ Required ]; |
| 15 | + |
| 16 | +Method RestoreToFileTree() |
| 17 | +{ |
| 18 | + set fileStream = ##class(%Stream.FileCharacter).%OpenId(..FullExternalName,,.sc) |
| 19 | + $$$ThrowOnError(sc) |
| 20 | + do fileStream.CopyFrom(..Contents) |
| 21 | + $$$ThrowOnError(fileStream.%Save()) |
| 22 | + do ##class(SourceControl.Git.Utils).ImportItem(..InternalName, 1, 1) |
| 23 | + do ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(..InternalName) |
| 24 | + $$$ThrowOnError(..%DeleteId(..%Id())) |
| 25 | +} |
| 26 | + |
| 27 | +ClassMethod SaveDiscardState(InternalName As %String) As %Status |
| 28 | +{ |
| 29 | + set discardState = ..%New() |
| 30 | + set discardState.FullExternalName = ##class(SourceControl.Git.Utils).FullExternalName(InternalName) |
| 31 | + set discardState.InternalName = InternalName |
| 32 | + |
| 33 | + set fileStream = ##class(%Stream.FileCharacter).%New() |
| 34 | + set fileStream.Filename = discardState.FullExternalName |
| 35 | + do fileStream.%Open() |
| 36 | + do discardState.Contents.CopyFrom(fileStream) |
| 37 | + do fileStream.%Close() |
| 38 | + set discardState.Username = $USERNAME |
| 39 | + set discardState.Branch = ##class(SourceControl.Git.Utils).GetCurrentBranch() |
| 40 | + set discardState.Timestamp = $zdatetime($horolog, 3) |
| 41 | + |
| 42 | + set st = discardState.%Save() |
| 43 | + |
| 44 | + quit st |
| 45 | +} |
| 46 | + |
| 47 | +ClassMethod DiscardStatesInBranch() As %DynamicArray |
| 48 | +{ |
| 49 | + set currentBranch = ##class(SourceControl.Git.Utils).GetCurrentBranch() |
| 50 | + set statement = "SELECT ID FROM SourceControl_Git.DiscardState WHERE branch = ?" |
| 51 | + set resultSet = ##class(%SQL.Statement).%ExecDirect(, statement, currentBranch) |
| 52 | + set discardStates = [] |
| 53 | + while resultSet.%Next() { |
| 54 | + set discardState = ..%OpenId(resultSet.ID) |
| 55 | + do discardState.%JSONExportToString(.JSONStr) |
| 56 | + set discardStateObject = ##class(%DynamicAbstractObject).%FromJSON(JSONStr) |
| 57 | + set discardStateObject.Id = resultSet.ID |
| 58 | + do discardStates.%Push(discardStateObject) |
| 59 | + } |
| 60 | + |
| 61 | + quit discardStates |
| 62 | +} |
| 63 | + |
| 64 | +Storage Default |
| 65 | +{ |
| 66 | +<Data name="DiscardStateDefaultData"> |
| 67 | +<Value name="1"> |
| 68 | +<Value>%%CLASSNAME</Value> |
| 69 | +</Value> |
| 70 | +<Value name="2"> |
| 71 | +<Value>FullExternalName</Value> |
| 72 | +</Value> |
| 73 | +<Value name="3"> |
| 74 | +<Value>InternalName</Value> |
| 75 | +</Value> |
| 76 | +<Value name="4"> |
| 77 | +<Value>Contents</Value> |
| 78 | +</Value> |
| 79 | +<Value name="5"> |
| 80 | +<Value>Username</Value> |
| 81 | +</Value> |
| 82 | +<Value name="6"> |
| 83 | +<Value>Branch</Value> |
| 84 | +</Value> |
| 85 | +<Value name="7"> |
| 86 | +<Value>Timestamp</Value> |
| 87 | +</Value> |
| 88 | +</Data> |
| 89 | +<DataLocation>^SourceControl22B9.DiscardStateD</DataLocation> |
| 90 | +<DefaultData>DiscardStateDefaultData</DefaultData> |
| 91 | +<ExtentSize>1</ExtentSize> |
| 92 | +<IdLocation>^SourceControl22B9.DiscardStateD</IdLocation> |
| 93 | +<IndexLocation>^SourceControl22B9.DiscardStateI</IndexLocation> |
| 94 | +<Property name="%%CLASSNAME"> |
| 95 | +<AverageFieldSize>2</AverageFieldSize> |
| 96 | +<OutlierSelectivity>.999999:</OutlierSelectivity> |
| 97 | +<Selectivity>0.0001%</Selectivity> |
| 98 | +</Property> |
| 99 | +<Property name="%%ID"> |
| 100 | +<AverageFieldSize>3</AverageFieldSize> |
| 101 | +<Selectivity>1</Selectivity> |
| 102 | +</Property> |
| 103 | +<Property name="Branch"> |
| 104 | +<AverageFieldSize>8</AverageFieldSize> |
| 105 | +<OutlierSelectivity>.999999:"branch"</OutlierSelectivity> |
| 106 | +<Selectivity>0.0001%</Selectivity> |
| 107 | +</Property> |
| 108 | +<Property name="Contents"> |
| 109 | +<OutlierSelectivity>.999999:$lb("15","%Stream.GlobalCharacter","^DiscardStateContents")</OutlierSelectivity> |
| 110 | +<Selectivity>0.0001%</Selectivity> |
| 111 | +</Property> |
| 112 | +<Property name="FullExternalName"> |
| 113 | +<AverageFieldSize>53</AverageFieldSize> |
| 114 | +<OutlierSelectivity>.999999:"C:\temp\USER\cls\medicine\cls\medicine\testfile.cls"</OutlierSelectivity> |
| 115 | +<Selectivity>0.0001%</Selectivity> |
| 116 | +</Property> |
| 117 | +<Property name="InternalName"> |
| 118 | +<AverageFieldSize>23</AverageFieldSize> |
| 119 | +<OutlierSelectivity>.999999:"medicine.testfile.CLS"</OutlierSelectivity> |
| 120 | +<Selectivity>0.0001%</Selectivity> |
| 121 | +</Property> |
| 122 | +<Property name="Timestamp"> |
| 123 | +<AverageFieldSize>21</AverageFieldSize> |
| 124 | +<OutlierSelectivity>.999999:"2024-08-12 14:09:28"</OutlierSelectivity> |
| 125 | +<Selectivity>0.0001%</Selectivity> |
| 126 | +</Property> |
| 127 | +<Property name="Username"> |
| 128 | +<AverageFieldSize>13</AverageFieldSize> |
| 129 | +<OutlierSelectivity>.999999:"UnknownUser"</OutlierSelectivity> |
| 130 | +<Selectivity>0.0001%</Selectivity> |
| 131 | +</Property> |
| 132 | +<SQLMap name="IDKEY"> |
| 133 | +<BlockCount>-4</BlockCount> |
| 134 | +</SQLMap> |
| 135 | +<StreamLocation>^SourceControl22B9.DiscardStateS</StreamLocation> |
| 136 | +<Type>%Storage.Persistent</Type> |
| 137 | +} |
| 138 | + |
| 139 | +} |
0 commit comments