34
34
from axiom.item import Item, _PowerupConnector, declareLegacyItem
35
35
from axiom.attributes import AND, integer, text, reference, bytes, boolean
36
36
from axiom.userbase import LoginSystem
37
from axiom.dependency import installOn
37
from axiom.dependency import installOn, uninstallFrom, installedOn
39
39
from xmantissa.ixmantissa import (
40
40
ISiteRootPlugin, ISessionlessSiteRootPlugin, IProtocolFactoryFactory,
708
def _makeSiteConfiguration(oldSite, couldHavePorts):
709
if oldSite.store.parent is not None:
708
def _makeSiteConfiguration(currentVersion, oldSite, couldHavePorts):
709
from xmantissa.publicweb import AnonymousSite
711
newSite = oldSite.upgradeVersion(
712
'mantissa_web_powerup', currentVersion, 6,
713
hitCount=oldSite.hitCount)
715
if newSite.store.parent is not None:
718
# SiteConfiguration dependsOn LoginSystem. LoginSystem was probably
719
# installed by the mantissa axiomatic command. During the dependency
720
# system conversion, that command was changed to use installOn on the
721
# LoginSystem. However, no upgrader was supplied to create the new
722
# dependency state. Consequently, there may be none. Consequently, a new
723
# LoginSystem will be created if an item which dependsOn LoginSystem is
724
# installed. This would be bad. So, set up the necessary dependency state
725
# here, before instantiating SiteConfiguration. -exarkun
727
# Addendum: it is almost certainly the case that there are not legitimate
728
# configurations which lack a LoginSystem. However, a large number of
729
# database upgrade tests construct unrealistic databases. One aspect of
730
# the unrealism is that they lack a LoginSystem. Therefore, rather than
731
# changing all the bogus stubs and regenerating the stubs, I will just
732
# support the case where LoginSystem is missing. However, note that a
733
# LoginSystem upgrader may invalidate this check and result in a duplicate
734
# being created anyway. -exarkun
735
loginSystem = oldSite.store.findUnique(LoginSystem, default=None)
736
if loginSystem is not None and installedOn(loginSystem) is None:
737
installOn(loginSystem, oldSite.store)
739
uninstallFrom(oldSite.store, oldSite)
712
741
site = SiteConfiguration(
713
742
store=oldSite.store,
715
744
hostname=getattr(oldSite, "hostname", None) or u"localhost")
716
745
installOn(site, site.store)
747
anonymousAvatar = AnonymousSite(store=oldSite.store)
748
installOn(anonymousAvatar, oldSite.store)
718
750
if couldHavePorts:
719
751
for tcp in site.store.query(TCPPort, TCPPort.factory == oldSite):
720
752
tcp.factory = site
721
753
for ssl in site.store.query(SSLPort, SSLPort.factory == oldSite):
722
754
ssl.factory = site
724
oldSite.store.powerDown(oldSite, IService)
726
756
if oldSite.portNumber is not None:
728
758
store=oldSite.store,
734
764
certificateFile = oldSite.certificateFile
735
765
if securePortNumber is not None and certificateFile:
736
766
oldCertPath = site.store.dbdir.preauthChild(certificateFile)
737
if oldCertPath.exists():
738
newCertPath = site.store.newFilePath('server.pem')
739
oldCertPath.copyTo(newCertPath)
742
portNumber=oldSite.securePortNumber,
743
certificatePath=newCertPath,
745
installOn(port, site.store)
767
newCertPath = site.store.newFilePath('server.pem')
768
oldCertPath.moveTo(newCertPath)
771
portNumber=oldSite.securePortNumber,
772
certificatePath=newCertPath,
774
installOn(port, site.store)
776
newSite.deleteFromStore()
748
779
declareLegacyItem(
754
785
certificateFile = bytes(default=None)))
756
787
def upgradeWebSite1To6(oldSite):
757
newSite = oldSite.upgradeVersion(
758
'mantissa_web_powerup', 1, 6,
759
hitCount=oldSite.hitCount)
760
_makeSiteConfiguration(oldSite, False)
788
return _makeSiteConfiguration(1, oldSite, False)
762
789
upgrade.registerUpgrader(upgradeWebSite1To6, 'mantissa_web_powerup', 1, 6)
764
791
declareLegacyItem(
773
800
def upgradeWebSite2to6(oldSite):
774
801
# This is dumb and we should have a way to run procedural upgraders.
775
newSite = oldSite.upgradeVersion(
776
'mantissa_web_powerup', 2, 6,
777
hitCount=oldSite.hitCount)
802
newSite = _makeSiteConfiguration(2, oldSite, False)
778
803
staticMistake = newSite.store.findUnique(StaticSite,
779
804
StaticSite.prefixURL == u'static/mantissa',
783
808
staticMistake.store.powerDown(staticMistake, ISessionlessSiteRootPlugin)
784
809
staticMistake.deleteFromStore()
786
_makeSiteConfiguration(oldSite, False)
788
812
upgrade.registerUpgrader(upgradeWebSite2to6, 'mantissa_web_powerup', 2, 6)
797
821
httpLog = bytes(default=None)))
799
823
def upgradeWebsite3to6(oldSite):
800
newSite = oldSite.upgradeVersion(
801
'mantissa_web_powerup', 3, 6,
802
hitCount=oldSite.hitCount)
803
_makeSiteConfiguration(oldSite, False)
824
return _makeSiteConfiguration(3, oldSite, False)
805
825
upgrade.registerUpgrader(upgradeWebsite3to6, 'mantissa_web_powerup', 3, 6)
807
827
declareLegacyItem(
815
835
httpLog=bytes(default=None)))
817
837
def upgradeWebsite4to6(oldSite):
818
newSite = oldSite.upgradeVersion(
819
'mantissa_web_powerup', 4, 6,
820
hitCount=oldSite.hitCount)
821
_makeSiteConfiguration(oldSite, False)
838
return _makeSiteConfiguration(4, oldSite, False)
823
839
upgrade.registerUpgrader(upgradeWebsite4to6, 'mantissa_web_powerup', 4, 6)
825
841
declareLegacyItem(
834
850
Create a L{SiteConfiguration} if this is a site store's L{WebSite}.
836
newSite = oldSite.upgradeVersion(
837
oldSite.typeName, 5, 6,
838
hitCount=oldSite.hitCount)
839
_makeSiteConfiguration(oldSite, True)
852
return _makeSiteConfiguration(5, oldSite, True)
841
853
upgrade.registerUpgrader(upgradeWebsite5to6, WebSite.typeName, 5, 6)