@@ -327,22 +327,44 @@ Method OnBeforeTimestamp(InternalName As %String)
327
327
Method OnAfterSave (InternalName As %String , Object As %RegisteredObject = {$$$NULLOREF}) As %Status
328
328
{
329
329
set sc = $$$OK
330
+ quit :$get (%gscSkipSaveHooks ) sc
330
331
try {
331
332
set InternalName = ##class (SourceControl.Git.Utils ).NormalizeInternalName (.InternalName ,.fromWebApp ,.fullExternalName )
332
333
set context = ##class (SourceControl.Git.PackageManagerContext ).ForInternalName (InternalName )
333
- if ##class (SourceControl.Git.Utils ).IsNamespaceInGit () && ..IsInSourceControl (InternalName ) {
334
- if fromWebApp {
335
- if fullExternalName = ##class (SourceControl.Git.Utils ).FullExternalName (InternalName ) {
336
- // Reimport item into database
337
- $$$ThrowOnError(##class (SourceControl.Git.Utils ).ImportItem (InternalName ,,1 ,1 ))
334
+ if ##class (SourceControl.Git.Utils ).IsNamespaceInGit () {
335
+ // If this is a production class and production decomposition is enabled, call recursively on all modified production items.
336
+ if ##class (SourceControl.Git.Utils ).ItemIsProductionToDecompose (InternalName ) {
337
+ do ##class (SourceControl.Git.Production ).GetModifiedItemsAfterSave (InternalName , .productionItems )
338
+ set key = $order (productionItems (" " ))
339
+ while (key '= " " ) {
340
+ if productionItems (key ) = " D" {
341
+ set itemFilename = ..FullExternalName (key )
342
+ if ##class (SourceControl.Git.Utils ).IsInSourceControl (key ) && ##class (%File ).Exists (itemFilename ) {
343
+ $$$ThrowOnError(##class (SourceControl.Git.Change ).AddDeletedToUncommitted (itemFilename , key ))
344
+ $$$ThrowOnError(##class (SourceControl.Git.Utils ).DeleteExternalFile (key ))
345
+ }
346
+ } elseif '..IsInSourceControl (key ) {
347
+ $$$ThrowOnError(##class (SourceControl.Git.Utils ).AddToSourceControl (key ))
348
+ } else {
349
+ $$$ThrowOnError(..OnAfterSave (key ))
350
+ }
351
+ set key = $order (productionItems (key ))
338
352
}
339
- } else {
340
- set filename = ##class (SourceControl.Git.Utils ).FullExternalName (InternalName )
341
- $$$ThrowOnError(##class (SourceControl.Git.Utils ).RemoveRoutineTSH (InternalName ))
342
- set forceExport = (InternalName '= " " ) && ($data (..Modified (InternalName )))
343
- $$$ThrowOnError(##class (SourceControl.Git.Utils ).ExportItem (InternalName ,,forceExport ))
344
- if '##class (SourceControl.Git.Change ).IsUncommitted (filename ) {
345
- $$$ThrowOnError(##class (SourceControl.Git.Change ).SetUncommitted (filename , " edit" , InternalName , $username , " " , 1 , " " , " " , 0 ))
353
+ }
354
+ if ..IsInSourceControl (InternalName ) {
355
+ if fromWebApp {
356
+ if fullExternalName = ##class (SourceControl.Git.Utils ).FullExternalName (InternalName ) {
357
+ // Reimport item into database
358
+ $$$ThrowOnError(##class (SourceControl.Git.Utils ).ImportItem (InternalName ,,1 ,1 ))
359
+ }
360
+ } else {
361
+ set filename = ##class (SourceControl.Git.Utils ).FullExternalName (InternalName )
362
+ $$$ThrowOnError(##class (SourceControl.Git.Utils ).RemoveRoutineTSH (InternalName ))
363
+ set forceExport = (InternalName '= " " ) && ($data (..Modified (InternalName )))
364
+ $$$ThrowOnError(##class (SourceControl.Git.Utils ).ExportItem (InternalName ,,forceExport ))
365
+ if '##class (SourceControl.Git.Change ).IsUncommitted (filename ) {
366
+ $$$ThrowOnError(##class (SourceControl.Git.Change ).SetUncommitted (filename , " edit" , InternalName , $username , " " , 1 , " " , " " , 0 ))
367
+ }
346
368
}
347
369
}
348
370
}
@@ -400,9 +422,41 @@ Method ExternalName(InternalName As %String) As %String
400
422
quit ##class (SourceControl.Git.Utils ).ExternalName (InternalName )
401
423
}
402
424
425
+ ClassMethod FullExternalName (InternalName As %String ) As %String
426
+ {
427
+ quit ##class (SourceControl.Git.Utils ).FullExternalName (InternalName )
428
+ }
429
+
403
430
Method IsReadOnly (InternalName As %String ) As %Boolean
404
431
{
405
- quit ##class (SourceControl.Git.Utils ).Locked ()
432
+ set settings = ##class (SourceControl.Git.Settings ).%New ()
433
+ quit (##class (SourceControl.Git.Utils ).Locked ()
434
+ && '$get (^IRIS .Temp (" sscProd" ,$job ," bypassLock" )))
435
+ || (##class (SourceControl.Git.Utils ).ItemIsProductionToDecompose ($get (InternalName ))
436
+ && 'settings .decomposeProdAllowIDE
437
+ && '##class (SourceControl.Git.Production ).IsEnsPortal ())
438
+ }
439
+
440
+ /// Called before the item is saved to the database it is passed
441
+ /// a reference to the current temporary storage of this item so that it
442
+ /// can be modified before the save completes. If you quit with an error
443
+ /// value then it will abort the save.
444
+ Method OnBeforeSave (InternalName As %String , Location As %String = " " , Object As %RegisteredObject = {$$$NULLOREF}) As %Status
445
+ {
446
+ set st = $$$OK
447
+ if ##class (SourceControl.Git.Utils ).ItemIsProductionToDecompose (InternalName ) {
448
+ do ##class (SourceControl.Git.Production ).GetModifiedItemsBeforeSave (InternalName ,,.productionItems )
449
+ set key = $order (productionItems (" " ))
450
+ while (key '= " " ) {
451
+ // if any modified items in this production class are checked out by a different user, fail the check.
452
+ set st = ..GetStatus (key , .IsInSourceControl , .Editable , .IsCheckedOut , .UserCheckedOut )
453
+ quit :$$$ISERR(st )
454
+ if 'Editable set st = $$$ERROR($$$GeneralError," Item is checked out by another user: " _UserCheckedOut )
455
+ quit :$$$ISERR(st )
456
+ set key = $order (productionItems (key ))
457
+ }
458
+ }
459
+ return st
406
460
}
407
461
408
462
/// Check the status of the given item
@@ -411,7 +465,7 @@ Method IsReadOnly(InternalName As %String) As %Boolean
411
465
Method GetStatus (ByRef InternalName As %String , ByRef IsInSourceControl As %Boolean , ByRef Editable As %Boolean , ByRef IsCheckedOut As %Boolean , ByRef UserCheckedOut As %String ) As %Status
412
466
{
413
467
set context = ##class (SourceControl.Git.PackageManagerContext ).ForInternalName (.InternalName )
414
- set Editable ='..IsReadOnly (),IsCheckedOut =1 ,UserCheckedOut =" "
468
+ set Editable ='..IsReadOnly ($get ( InternalName ) ),IsCheckedOut =1 ,UserCheckedOut =" "
415
469
set filename =##class (SourceControl.Git.Utils ).FullExternalName (.InternalName )
416
470
set IsInSourceControl =(filename '=" " &&($$$FileExists(filename )))
417
471
if filename =" " quit $$$OK
0 commit comments