1 | from StringIO import StringIO |
---|
2 | |
---|
3 | from Products.Archetypes.public import listTypes |
---|
4 | from Products.Archetypes.Extensions.utils import installTypes, install_subskin |
---|
5 | from Products.CMFCore.utils import getToolByName |
---|
6 | |
---|
7 | from Products.CacheSetup import config |
---|
8 | from Products.CacheSetup.Extensions import utils |
---|
9 | from Products.CacheSetup.Extensions import policy_utils |
---|
10 | from Products.CacheSetup.enabler import enableCacheFu |
---|
11 | |
---|
12 | |
---|
13 | def install(self, reinstall=False): |
---|
14 | out = StringIO() |
---|
15 | |
---|
16 | utils.installDependencies(self, out) |
---|
17 | |
---|
18 | installTypes(self, out, listTypes(config.PROJECT_NAME), config.PROJECT_NAME, refresh_references=0) |
---|
19 | install_subskin(self, out, config.GLOBALS) |
---|
20 | |
---|
21 | utils.setupWorkflows(self, out) |
---|
22 | utils.setupCacheTool(self, out) |
---|
23 | utils.setupSquidTool(self, out) |
---|
24 | utils.setupPortalFactory(self, out) |
---|
25 | utils.setupFolderViews(self, out) |
---|
26 | utils.setupSiteProperties(self, out) |
---|
27 | utils.setupConfiglet(self, out) |
---|
28 | |
---|
29 | # clean up old cache policy and migrate changed schemas |
---|
30 | if reinstall: |
---|
31 | policy_utils.updateOldCachePolicy(self, out) |
---|
32 | utils.updateSchemas(self, out) |
---|
33 | |
---|
34 | # add new cache policies |
---|
35 | policy_utils.addCachePolicies(self, out) |
---|
36 | |
---|
37 | out.write("Successfully installed %s." % config.PROJECT_NAME) |
---|
38 | return out.getvalue() |
---|
39 | |
---|
40 | def uninstall(self, reinstall=False): |
---|
41 | out = StringIO() |
---|
42 | |
---|
43 | utils.restorePortalFactory(self, out) |
---|
44 | utils.restoreSquidTool(self, out) |
---|
45 | utils.restoreFolderViews(self, out) |
---|
46 | utils.restoreSiteProperties(self, out) |
---|
47 | utils.removeConfiglet(self, out) |
---|
48 | |
---|
49 | # Remove the old cached_macros folder left by version 1.0x |
---|
50 | # We also manually uncatalog it and any children since it's probably broken now |
---|
51 | cache_tool = getToolByName(self, config.CACHE_TOOL_ID) |
---|
52 | if getattr(cache_tool, 'cached_macros', None) is not None: |
---|
53 | print >> out, 'Removed and uncataloged cache_macros folder left by previous version.' |
---|
54 | catalog = getToolByName(self, 'portal_catalog', None) |
---|
55 | results = catalog.searchResults(Type=['Macro Folder','MacroCacheRule']) |
---|
56 | for result in results: |
---|
57 | catalog.uncatalog_object(result.getPath()) |
---|
58 | cache_tool.manage_delObjects('cached_macros') |
---|
59 | |
---|
60 | # Disabling Cachefu will remove PageCacheManager & PolicyHTTPCaches |
---|
61 | # and restore old CachingPolicyManager and ResourceRegistry settings |
---|
62 | # We bypass 'setEnabled' here since 'getEnabled' will always return |
---|
63 | # False while the filesystem and installed versions don't match. |
---|
64 | if not reinstall and config.PAGE_CACHE_MANAGER_ID in self.objectIds(): |
---|
65 | utils._updateChangedSchema(cache_tool, None) # for version 1.0x |
---|
66 | cache_tool.getField('enabled').set(cache_tool, False) |
---|
67 | enableCacheFu(self, False) |
---|
68 | |
---|
69 | # uninstall/reinstall the CMFSquidTool product also |
---|
70 | qi = getToolByName(self, 'portal_quickinstaller') |
---|
71 | if reinstall: |
---|
72 | qi.reinstallProducts(['CMFSquidTool']) |
---|
73 | else: |
---|
74 | qi.uninstallProducts(['CMFSquidTool']) |
---|
75 | |
---|
76 | return out.getvalue() |
---|