Skip to content

Commit fa06a35

Browse files
James LechtnerJames Lechtner
authored andcommitted
Fix: IPM Update Resource Conflict
1 parent f522900 commit fa06a35

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/cls/IPM/Storage/Module.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ Method GetResolvedReferences(
13361336
{
13371337
set tSC = $$$OK
13381338
try {
1339-
if '$data(pDependencyGraph) {
1339+
if pLockedDependencies && '$data(pDependencyGraph) {
13401340
set tSC = ..BuildDependencyGraph(.pDependencyGraph,,,,pPhases)
13411341
if $$$ISERR(tSC) {
13421342
quit

src/cls/IPM/Storage/ResourceReference.cls

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ Property Children As array Of %String(MAXLEN = 1, XMLPROJECTION = "NONE");
5454

5555
Index Children On Children(KEYS);
5656

57+
/// Tells us if this resource belongs to a module that will be processed as a part of the "Update" command
58+
/// If set to true, %OnBeforeSave() will not error if another resource of the same name tries to be saved
59+
/// and will instead save that resource with the other module as new
60+
/// This is useful for an "Update" command where a resource was moved from one module to another.
61+
/// If the resource's new module gets updated first, we don't want to error on a resource listed in two modules
62+
/// when it will only be in one in the final environment once the resource's previous home gets updated
63+
Property MarkedForUpdate As %Boolean [ InitialExpression = 0 ];
64+
5765
Method ProcessorGet() As %IPM.ResourceProcessor.Abstract
5866
{
5967
// Similar to LifecycleGet in Module.
@@ -344,6 +352,21 @@ ClassMethod NonNullResourceNameOpen(
344352
quit tResult
345353
}
346354

355+
/// When given a name for a resource, set its MarkedForUpdate flag
356+
/// See property description for more details on the usage of MarkedForUpdate
357+
ClassMethod MarkResourceForUpdate(
358+
resourceName As %String,
359+
marking As %Boolean = 1)
360+
{
361+
set resource = ..NonNullResourceNameOpen(resourceName,,.sc)
362+
if (resource = $$$NULLOREF) {
363+
// If unable to find a resource with this name, do nothing
364+
quit
365+
}
366+
set resource.MarkedForUpdate = marking
367+
$$$ThrowOnError(resource.%Save())
368+
}
369+
347370
ClassMethod GetStatus(
348371
InternalName As %String,
349372
Output pReferenced As %Boolean,
@@ -432,6 +455,11 @@ Method %OnBeforeSave(insert As %Boolean) As %Status [ Private, ServerOnly = 1 ]
432455
if $$$ISERR(tSC) {
433456
quit
434457
}
458+
if (tOtherInstance.MarkedForUpdate) {
459+
// If other instance marked for update, then we should overwrite it with this instead of throwing an error
460+
$$$ThrowOnError(..%DeleteId(tExistingID))
461+
quit
462+
}
435463
if (tOtherInstance.Module.Name = ..Module.Name) {
436464
set tMsg = $$$FormatText("Resource '%1' is listed more than once in module '%2'",..Name,..Module.Name)
437465
} else {
@@ -542,6 +570,9 @@ Storage Default
542570
<Value name="10">
543571
<Value>IsAPI</Value>
544572
</Value>
573+
<Value name="11">
574+
<Value>MarkedForUpdate</Value>
575+
</Value>
545576
</Data>
546577
<DataLocation>{%%PARENT}("Resources")</DataLocation>
547578
<DefaultData>ResourceReferenceDefaultData</DefaultData>

src/cls/IPM/Utils/Module.cls

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,26 @@ ClassMethod LoadNewModule(
11731173
}
11741174
}
11751175

1176+
// Mark relevant resources for update
1177+
if ($get(params("cmd")) = "update") {
1178+
set tSC = moduleCurrent.GetResolvedReferences(.resourceArray, 1)
1179+
set moduleKey = ""
1180+
for {
1181+
set moduleKey = $order(resourceArray(moduleKey))
1182+
if (moduleKey = "") {
1183+
quit
1184+
}
1185+
set resourceKey = ""
1186+
for {
1187+
set resourceKey = $order(resourceArray(moduleKey, resourceKey))
1188+
if (resourceKey = "") {
1189+
quit
1190+
}
1191+
do ##class(%IPM.Storage.ResourceReference).MarkResourceForUpdate(resourceKey)
1192+
}
1193+
}
1194+
}
1195+
11761196
// This loads the new version of the module into storage. Overrides the module context of the currently installed module, if it exists.
11771197
set tSC = $system.OBJ.Load(pDirectory_"module.xml",$select(tVerbose:"d",1:"-d"),,.tLoadedList)
11781198
$$$ThrowOnError(tSC)

0 commit comments

Comments
 (0)