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