@@ -54,6 +54,14 @@ Property Children As array Of %String(MAXLEN = 1, XMLPROJECTION = "NONE");
5454
5555Index 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+
5765Method 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+
347370ClassMethod 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 >
0 commit comments