source: products/quintagroup.plonegooglesitemaps/branches/1.7.1/quintagroup/plonegooglesitemaps/upgrades.py

Last change on this file was 3152, checked in by zidane, 9 years ago

fixes pep8

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1import logging
2from zope.component import queryMultiAdapter
3
4from quintagroup.canonicalpath.upgrades import CanonicalConvertor
5
6logger = logging.getLogger('quintagroup.plonegooglesitemaps')
7
8convertor = None
9
10
11def migrateCanonical(plone_tools):
12    """ Rename qSEO_canonical property into PROPERTY_LINK
13        for all portal objects, which use SEO
14    """
15    global convertor
16    types = plone_tools.types()
17    purl = plone_tools.url()
18    portal = purl.getPortalObject()
19    allCTTypes = types.listContentTypes()
20    obj_metatypes = [m.content_meta_type for m in types.objectValues() \
21                     if m.getId() in allCTTypes]
22    convertor = CanonicalConvertor(portal_url=purl())
23    portal.ZopeFindAndApply(
24                            portal,
25                            obj_metatypes=','.join(obj_metatypes),
26                            apply_func=renameProperty,
27                            search_sub=1,
28                            )
29    print convertor.getLogs()
30
31
32def renameProperty(obj, path):
33    """ Migrate canonical_path property into canonical_link
34        for obj, which use SEO
35    """
36    if convertor is not None:
37        convertor.convertIPathToLink(obj)
38
39
40def upgrade_1_0_to_1_1(setuptool):
41    """ Upgrade quintagroup.plonegooglesitemaps from version 1.0 to 1.1.
42    """
43    profile_name = 'profile-quintagroup.plonegooglesitemaps:upgrade_1_0_to_1_1'
44    setuptool.runAllImportStepsFromProfile(profile_name)
45
46
47def upgrade_1_1_to_1_2(setuptool):
48    """ Upgrade quintagroup.plonegooglesitemaps from version 1.1 to 1.2.
49    """
50    plone_tools = queryMultiAdapter((setuptool, setuptool.REQUEST),
51                                    name="plone_tools")
52    migrateCanonical(plone_tools)
53    profile_name = 'profile-quintagroup.plonegooglesitemaps:upgrade_1_1_to_1_2'
54    setuptool.runAllImportStepsFromProfile(profile_name)
Note: See TracBrowser for help on using the repository browser.