Ignore:
Timestamp:
Aug 9, 2010 6:07:08 PM (14 years ago)
Author:
mylan
Message:

#222: Added migratioin old Products.qPloneCaptchaField to quintagroup.pfg.captcha fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.pfg.captcha/branches/migration/quintagroup/pfg/captcha/setuphandlers.py

    r2711 r2729  
    22from zope.component import queryMultiAdapter 
    33 
    4 from quintagroup.canonicalpath.interfaces  import ICanonicalLink 
    5 from quintagroup.canonicalpath.adapters import PROPERTY_LINK 
    6  
    74logger = logging.getLogger('quintagroup.pfg.captcha') 
    85 
    9 def isNeedMigration(plone_tools): 
     6capcha_fields = [] 
     7 
     8def migrateToPackage(context): 
     9    """Collect old Products.qPloneCaptchaFields fields (before types tool setup). 
     10    """ 
     11    global captcha_fields 
     12    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None: 
     13        return 
     14 
     15    site = context.getSite() 
     16    plone_tools = queryMultiAdapter((site, site.REQUEST), name="plone_tools") 
    1017    ptypes = plone_tools.types() 
    1118    cftype = getattr(ptypes, 'CaptchaField', None) 
    12     return cftype and getattr(cftype, 'product', "") == "qPloneCaptchaField" 
     19    if cftype and getattr(cftype, 'product', "") == "qPloneCaptchaField": 
     20        catalog = plone_tools.catalog() 
     21        captcha_fields = [(cf.id, cf.getObject().aq_parent) \ 
     22                          for cf in catalog.search({'portal_type':'CaptchaField'})] 
     23        logger.info("Old Products.qPloneCaptchaField fields collected.") 
    1324 
    14 def migrateToPackage(context): 
    15     """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha ob. 
     25 
     26def afterTypesTool(context): 
     27    """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha fields 
     28    (after types tool setup). 
    1629    """ 
    17     if context.readDataFile('_uninstall.txt') is None: 
     30    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None: 
    1831        return 
    19     site = context.getSite() 
    20     plone_tools = queryMultiAdapter((site, setuptool.REQUEST), name="plone_tools") 
    2132 
    22     if isNeedMigration(plone_tools): 
    23         pass 
    24         ## Find old objects:  
    25         #for cf in catalog.search({'portal_type':'CaptchaField'}): 
    26         #   get parent obj, del old CaptchaField and create new one  
    27         # Then remove old portal type "CaptchaField" 
    28         # for path in plone_tools.catalog().search() 
    29         # recriateCaptchaFields(plone_tools) 
    30         # removeOldPortalType(plone_tools) 
     33    for cf_id, form in captcha_fields: 
     34        form.manage_delObjects(cf_id) 
     35        form.invokeFactory("CaptchaField", cf_id) 
     36        logger.info("Fixed CaptchaField in '%s'" % form.getId()) 
     37    logger.info("Finish Captcha field fixing") 
Note: See TracChangeset for help on using the changeset viewer.