!=========================================================================
! Copyright (C) GemTalk Systems 1986-2014.  All Rights Reserved.
!
! Name - upgrade_img.topaz
!
! Purpose - common filein script shared by various upgrade image scripts .
!   The calling script responsible for login/logout and output push
!
! $Id: upgrade_img.topaz 36605 2015-06-09 19:42:49Z otisa $
!
!========================================================================


! filein methods for kernel classes that are created in bom.c
set SOURCESTRINGCLASS String
fileformat 8bit

input $upgradeDir/filein1.topaz

! now load the error dictionaries
input $upgradeDir/errordict.gs
input $upgradeDir/errors.gs
commit

! Temporarily disable TransactionBoundaryDefaultPolicy
expectvalue true
run
(TransactionBoundaryDefaultPolicy respondsTo: #uninstall)
  ifTrue: [ TransactionBoundaryDefaultPolicy uninstall ].
true
%
commit

! Temporarily restore classes in #ObsoleteClasses and #GsCompilerClasses to Globals
input $upgradeDir/addHiddenToGlobals.gs
commit

input $upgradeDir/obsolete_classes.gs
commit

input $upgradeDir/bomnew.gs
commit

! fresh session to see complete symbolList created in bom.gs
logout
login

! create classes and filein methods for classes created in GemStone Smalltalk
input $upgradeDir/filein2.topaz

run
SystemRepository _setVersion .
^ true
%

! final fixup of various methods with foward refs and other stuff relating
! to objectSecurityPolicies and user profiles.
input $upgradeDir/bomlastconv.gs

! dereference instances of GsClassDocumentation from old versions of classes. 
run
(Globals includesKey: #GsRdbConnection) ifTrue:[
  Globals removeKey: #GsRdbConnection .
  GsFile gciLogServer:'removed from Globals'.
].
(Object _objectForOop: 104705) ifNotNil:[:cls |
  ObsoleteClasses at: #ObsoleteGsRdbConnection put: cls .
  GsFile gciLogServer:'added to ObsoleteClasses'.
].
true
%

expectvalue %SmallInteger
run
  | count blk |
  count := 0 .
  blk := [:v |
    v isBehavior ifTrue:[
      v classHistory do:[:cls |
        cls _unsafeAt: 15 put: (cls timeStamp) .  "cls timeStamp: cls timeStamp" 
        GsFile gciLogServer:'wrote ' , cls name .
        count := count + 1 .
      ].
    ].
  ].
  Globals values do: blk .
  ObsoleteClasses values do: blk .
  count
%
commit

logout


!========================================================================
!   Upgrade UserSecurityData objects
!========================================================================
! Must do this before changing any passwords
input $upgradeDir/upgradeSecurityData.topaz

! Resets DataCurator password 
input $upgradeDir/gcuser.gs
input $upgradeDir/nameless.gs


! Blows away existing Session Methods ... must be restored after upgrade complete
input $upgradeDir/sessionmethods.topaz
input $upgradeDir/installMonticello.topaz

set gemstone $stoneName user SystemUser pass swordfish
login

! Not needed in 2.x to 3.0 conversion:
! input $upgradeDir/upgradeAllSymbols.topaz

input $upgradeDir/removeemptycateg.gs

expectvalue %String
run
(Globals includesKey: 'DbfOrigin') ifFalse:[
   "dbf originated prior to v3.2.0, revert to 3.1.0.x equality based hash"
    Symbol removeSelector: #hash .
    QuadByteSymbol removeSelector: #hash .
    ^ 'reverted'
  ].
^ 'no change'
%
commit

!========================================================================
!   Set the imageVersion
!========================================================================

input $upgradeDir/version.topaz
  
!========================================================================
!   Cluster the image
!========================================================================
expectvalue true
run
  "stop/restart the symbolVm before clustering AllSymbols"
System stopSymbolCreationSession .
[ 
  System symbolCreationSessionId == 0 
] whileFalse:[ System sleep: 1 ].
System startSymbolCreationSession
%

input $upgradeDir/clusterimage.gs

expectvalue true
commit

time

!========================================================================
expectvalue %SmallInteger
send UserGlobals at: #ErrCount put: ErrorCount
expectvalue true
commit

iferror
expectvalue 0
send UserGlobals at: #ErrCount put: ErrorCount

expectvalue true
commit

