Revision as of 22:33, 5 January 2010 by SIMU-NOVA (Talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

function upgradeClass()


As nodes are loaded from the database, it is possible that the structure of their classes may have changed since the last time that the node was saved. If this has happened, it might be necessary for the node to be re-initialized, so that it can be properly converted from its old version to the new version.

The way to accomplish this is via this function, which causes upgrade logic to be called for each class on the node. This may also require an additional field in the class to track the version.


When the node is loaded from the database, each of the node's ClassMethods scripts are checked for this function. If it is present, it is run.

function upgradeClass()

It has no parameters, but the me node is set.


For a fictional class SomeClass with fields versionOfSomeClass and someOtherField, the following function could be in script SomeClassClassMethods:

function upgradeClass()
  where me is kindof SomeClass
    if me.versionOfSomeClass < 5
      me.someOtherField = blah
      me.versionOfSomeClass = 5

Note: The order that upgradeClass() is called when the node has multiple classes can be a tricky issue. It does process a class' parents before processing the class, but the order that parents are processed is arbitrary and if the same class is inherited more than once, it's upgradeClass() function will be called more than once. Similarly, each glommed class is then processed.

Personal tools