source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/Extensions/policy_utils.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 13 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1from Products.CacheSetup import config
2from Products.CacheSetup.Extensions import policy_1, policy_2
3
4POLICIES = (policy_1, policy_2)
5
6def updateOldCachePolicy(portal, out):
7    ct = getattr(portal, config.CACHE_TOOL_ID)
8    rules = getattr(ct, config.RULES_ID, None)
9    if rules is not None and rules.portal_type == 'RuleFolder':
10        # this is an old policy so make it a new-style policy folder
11        oldpolicy_id = "old-policy"
12        oldpolicy_title = "Old Cache Policy - saved from previous install"
13        ct.addPolicyFolder(oldpolicy_id, oldpolicy_title)
14        oldpolicy = getattr(ct, oldpolicy_id)
15        folder_ids = [config.RULES_ID, config.HEADERSETS_ID]
16        cp = ct.manage_copyObjects(folder_ids)
17        oldpolicy.manage_pasteObjects(cp)
18        for folder in oldpolicy.objectValues():
19            folder.unmarkCreationFlag()
20            for item in folder.objectValues():
21                item.unmarkCreationFlag()
22        ct.setActivePolicyId(oldpolicy_id)
23        ct.manage_delObjects(folder_ids)
24        # let's also migrate cacheConfig
25        cache_config = ct.getCacheConfig()
26        if cache_config in ('zserver','apache'):
27            ct.setProxyPurgeConfig('no-purge')
28        elif cache_config == 'squid':
29            ct.setProxyPurgeConfig('no-rewrite')
30        else:
31            ct.setProxyPurgeConfig('custom-rewrite')
32    else:
33        # this is cachefu version 1.1+
34        # let's retitle old policies to avoid confusion
35        suffix_save = "saved from previous install"
36        suffix_copy = "copy"
37        policies = [p for p in ct.objectValues() if p.portal_type=="CachePolicy"]
38        for policy in policies:
39            policy_title = policy.Title()
40            suffix = suffix_save in policy_title and suffix_copy or suffix_save
41            policy.setTitle('%s - %s' % (policy_title, suffix))
42
43def addCachePolicies(portal, out):
44    # We'll extend this later
45    # preferably using GenericSetup profiles
46    ct = getattr(portal, config.CACHE_TOOL_ID)
47    for p in POLICIES:
48        # fix any id collisions
49        if getattr(ct, p.POLICY_ID, None) is not None:
50            count = 1
51            while getattr(ct, '%s-backup%s' % (p.POLICY_ID, count), None) is not None:
52                count = count + 1
53            newId = '%s-backup%s' % (p.POLICY_ID, count)
54            ct.manage_renameObjects([p.POLICY_ID], [newId])
55        # now add the new policy
56        ct.addPolicyFolder(p.POLICY_ID, p.POLICY_TITLE)
57        rules = ct.getRules(p.POLICY_ID)
58        p.addCacheRules(rules)
59        header_sets = ct.getHeaderSets(p.POLICY_ID)
60        p.addHeaderSets(header_sets)
61    # Lets move the new policies to the top of the list
62    policy_ids = [p.POLICY_ID for p in POLICIES]
63    ct.moveObjectsToTop(policy_ids)
64
65
Note: See TracBrowser for help on using the repository browser.