Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.Extensions.migrations Namespace Reference

Classes

class  StdoutStringIO

Functions

def reinstallArchetypes
def fixArchetypesTool
def migrateReferences
def migrateUIDs
def removeOldUIDs
def migrateSchemas
def migrateCatalogIndexes
def refreshCatalogs
def migrate

Variables

 USE_FULL_TRANSACTIONS = False
string EMPTY_RELATIONSHIP = 'related'
string olduididx = 'old_tmp_at_uid'

Function Documentation

Definition at line 43 of file migrations.py.

00043 
00044 def fixArchetypesTool(portal, out):
00045     at = portal.archetype_tool
00046 
00047     if not hasattr(at, '_templates'):
00048         #They come in pairs
00049         at._templates = PersistentMapping()
00050         at._registeredTemplates = PersistentMapping()
00051 
00052     if not hasattr(at, 'catalog_map'):
00053         at.catalog_map = PersistentMapping()
00054 
00055     install_uidcatalog(portal, out)
00056 

Here is the call graph for this function:

Here is the caller graph for this function:

migrate an AT site

Definition at line 272 of file migrations.py.

00272 
00273 def migrate(self):
00274     """migrate an AT site"""
00275     out = StdoutStringIO()
00276     portal = getToolByName(self,'portal_url').getPortalObject()
00277 
00278     print >>out, "Begin Migration"
00279 
00280     fixArchetypesTool(portal, out)
00281     reinstallArchetypes(portal,out)
00282     migrateSchemas(portal, out)
00283     migrateUIDs(portal, out)
00284     migrateReferences(portal,out)
00285     removeOldUIDs(portal, out)
00286     migrateCatalogIndexes(portal, out)
00287     refreshCatalogs(portal, out)
00288     print >>out, "Archetypes Migration Successful"
00289     return out.getvalue()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 241 of file migrations.py.

00241 
00242 def migrateCatalogIndexes(portal, out):
00243     def addIndex(catalog, indexName, indexType):
00244         # copy of code in utils.py:install_referenceCatalog
00245         try:
00246             catalog.addIndex(indexName, indexType, extra=None)
00247         except:
00248             pass
00249         try:
00250             if not indexName in catalog.schema():
00251                 catalog.addColumn(indexName)
00252         except:
00253             pass
00254     
00255     rc = getToolByName(portal, REFERENCE_CATALOG)
00256     add_indexes = ('targetId', 'FieldIndex'),
00257     [addIndex(rc, n, t) for n, t in add_indexes]
    

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 57 of file migrations.py.

00057 
00058 def migrateReferences(portal, out):
00059     # FIRST
00060     # a 1.2 -> 1.3 (new annotation style) migration path
00061     
00062     at = getToolByName(portal, TOOL_NAME)
00063     rc = getToolByName(portal, REFERENCE_CATALOG)
00064     uc = getToolByName(portal, UID_CATALOG)
00065 
00066     count=0
00067     
00068     # Old 1.2 style references are stored inside archetype_tool on the 'ref'
00069     # attribute
00070     refs = getattr(at, 'refs', None)
00071     if refs is not None:
00072         print >>out, 'migrating reference from Archetypes 1.2'
00073         count=0
00074         print >>out, "Old references are stored in %s, so migrating them to new style reference annotations.\n" % (TOOL_NAME)
00075         allbrains = uc()
00076         for brain in allbrains:
00077             sourceObj = brain.getObject()
00078             sourceUID = getattr(aq_base(sourceObj), olduididx, None)
00079             if sourceUID is None: continue
00080             # references migration starts
00081             for targetUID, relationship in refs.get(sourceUID, []):
00082                 # get target object
00083                 targetBrains = uc(**{olduididx:targetUID})
00084                 assert(len(targetBrains) == 1,'catalog query for OLD uid (%s) returned %d results instead of 1' % (targetUID,len(targetBrains)))
00085                 targetObj=targetBrains[0].getObject()
00086                 # fix empty relationship
00087                 if not relationship:
00088                     relationship = EMPTY_RELATIONSHIP
00089                 # create new style reference
00090                 rc.addReference(sourceObj, targetObj, relationship)
00091                 count+=1        
00092                 if not count % 10:
00093                     print >>out, '.',
00094                 # avoid eating up all RAM
00095                 if not count % 250:
00096                     print >>out, '*',
00097                     transaction.savepoint(optimistic=True)
00098             print >>out, "\n%s old references migrated." % count
00099         # after all remove the old-style reference attribute
00100         delattr(at, 'refs')
00101         print >>out, 'Done\n'
00102         if USE_FULL_TRANSACTIONS:
00103             transaction.commit()
00104         else:
00105             transaction.savepoint(optimistic=True)
00106     
00107     else:
00108         # SECOND
00109         # a 1.3.b2 -> 1.3 (new annotation style) migration path
00110         # We had a reference catalog, make sure its doing annotation
00111         # based references
00112     
00113         # reference metadata cannot be restored since reference-catalog is no more
00114         # a btree and in AT 1.3.b2 reference_catalog was a btreefolder
00115 
00116         print >>out, 'migrating reference from Archetypes 1.3. beta2\n'
00117 
00118         refs = rc()
00119         rc.manage_catalogClear()
00120         for brain in refs:
00121             sourceObject = rc.lookupObject(brain.sourceUID)
00122             if sourceObject is None: continue
00123             targetObject=rc.lookupObject(brain.targetUID)
00124             if not targetObject:
00125                 print >>out,  'mirateReferences: Warning: no targetObject found for UID ',brain.targetUID
00126                 continue
00127             relationship = brain.relationship
00128             # fix empty relationship
00129             if not relationship:
00130                 relationship = EMPTY_RELATIONSHIP
00131             sourceObject.addReference(targetObject, relationship = relationship)
00132             count+=1
00133             if not count % 10:
00134                 print >>out, '.',
00135             # avoid eating up all RAM
00136             if not count % 250:
00137                 print >>out, '*',
00138                 transaction.savepoint(optimistic=True)
00139 
00140         print >>out, "%s old references migrated (reference metadata not restored)." % count
00141         print >>out, '\nDone\n'
00142         if USE_FULL_TRANSACTIONS:
00143             transaction.commit()
00144         else:
00145             transaction.savepoint(optimistic=True)
00146 
00147     print >>out, "Migrated References"
00148 
00149 
00150     #Reindex for new UUIDs
00151     uc.manage_reindexIndex()
00152     rc.manage_reindexIndex()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 232 of file migrations.py.

00232 
00233 def migrateSchemas(portal, out):
00234     at = getToolByName(portal, TOOL_NAME)
00235     msg = at.manage_updateSchema(update_all=1)
00236     if USE_FULL_TRANSACTIONS:
00237         transaction.commit()
00238     else:
00239         transaction.savepoint(optimistic=True)
00240     print >>out, msg

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Extensions.migrations.migrateUIDs (   portal,
  out 
)

Definition at line 155 of file migrations.py.

00155 
00156 def migrateUIDs(portal, out):
00157     count=0
00158     uc = getToolByName(portal, UID_CATALOG)    
00159     print >>out, 'Migrating uids\n'
00160     
00161     # temporary add a new index    
00162     if olduididx not in uc.indexes():
00163         uc.addIndex(olduididx, 'FieldIndex', extra=None)
00164         if not olduididx in uc.schema():
00165             uc.addColumn(olduididx)
00166     
00167     # clear UID Catalog 
00168     uc.manage_catalogClear()
00169     
00170     # rebuild UIDS on objects and in catalog
00171     allbrains = portal.portal_catalog()
00172     for brain in allbrains:
00173         # get a uid for each thingie
00174         obj = brain.getObject()
00175         if not IBaseObject.isImplementedBy(obj): 
00176             continue #its no Archetype instance, so leave it
00177         
00178         objUID = getattr(aq_base(obj), '_uid', None)        
00179         if objUID is not None: #continue    # not an old style AT?
00180             setattr(obj, olduididx, objUID) # this one can be part of the catalog
00181             delattr(obj, '_uid')
00182             setattr(obj, UUID_ATTR, None)
00183         obj._register()            # creates a new UID
00184         obj._updateCatalog(portal) # to be sure
00185         count+=1
00186         if not count % 10:
00187             print >>out, '.',
00188         # avoid eating up all RAM
00189         if not count % 250:
00190             print >>out, '*',
00191             transaction.savepoint(optimistic=True)
00192     print >>out, '\nDone\n'
00193     if USE_FULL_TRANSACTIONS:
00194         transaction.commit()
00195     else:
00196         transaction.savepoint(optimistic=True)
00197 
00198     print >>out, count, "UID's migrated."

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 258 of file migrations.py.

00258 
00259 def refreshCatalogs(portal, out):
00260     uc = getToolByName(portal, UID_CATALOG)
00261     rc = getToolByName(portal, REFERENCE_CATALOG)
00262     print >>out, 'Refreshing uid catalog'
00263     uc.refreshCatalog(clear=1)
00264     print >>out, 'Refreshing reference catalog'
00265     rc.refreshCatalog(clear=1)
00266 
00267     if USE_FULL_TRANSACTIONS:
00268         transaction.commit()
00269     else:
00270         transaction.savepoint(optimistic=True)
00271 

Here is the call graph for this function:

Here is the caller graph for this function:

let's quickinstaller (re)install Archetypes and it's dependencies

Definition at line 28 of file migrations.py.

00028 
00029 def reinstallArchetypes(portal, out):
00030     """let's quickinstaller (re)install Archetypes and it's dependencies
00031     """
00032     qi = getToolByName(portal, 'portal_quickinstaller')
00033     products = ('MimetypesRegistry', 'PortalTransforms', 'Archetypes', )
00034     print >>out, 'Reinstalling Archetypes and it\'s dependencies'
00035     for product in products:
00036         if qi.isProductInstalled(product):
00037             qi.reinstallProducts([product])
00038             print >>out, '... reinstalling %s' % product
00039         else:
00040             qi.installProducts([product])
00041             print >>out, '... installing %s' % product
00042     print >>out, 'Done\n'
       

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 199 of file migrations.py.

00199 
00200 def removeOldUIDs(portal, out):
00201     # remove temporary needed index 
00202     uc = getToolByName(portal, UID_CATALOG)    
00203     print >>out, 'Removing old uids\n'
00204     if olduididx in uc.indexes():
00205         uc.delIndex(olduididx)
00206         if olduididx in uc.schema():
00207             uc.delColumn(olduididx)
00208     count=0
00209     allbrains = uc()
00210     for brain in allbrains:
00211         #Get a uid for each thingie
00212         obj = brain.getObject()
00213         objUID = getattr(aq_base(obj), olduididx, None)        
00214         if objUID is None: continue # not an old style AT
00215         delattr(obj, olduididx)
00216         obj._updateCatalog(portal) 
00217         count+=1
00218         if not count % 10:
00219             print >>out, '.',
00220         # avoid eating up all RAM
00221         if not count % 250:
00222             print >>out, '*',
00223             transaction.savepoint(optimistic=True)
00224 
00225     if USE_FULL_TRANSACTIONS:
00226         transaction.commit()
00227     else:
00228         transaction.savepoint(optimistic=True)
00229 
00230     print >>out, "\n%s old UID attributes removed." % count
00231     print >>out, 'Done\n'

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 18 of file migrations.py.

string Archetypes.Extensions.migrations.olduididx = 'old_tmp_at_uid'

Definition at line 153 of file migrations.py.

Definition at line 15 of file migrations.py.