[1] | 1 | from Products.Archetypes.public import listTypes |
---|
| 2 | from Products.Archetypes.Extensions.utils import installTypes, install_subskin |
---|
| 3 | from Products.CMFCore.WorkflowTool import addWorkflowFactory |
---|
| 4 | from Products.CMFFormController.FormAction import FormActionKey |
---|
| 5 | from Products.CMFCore import CMFCorePermissions |
---|
| 6 | from Products.CMFCore.utils import getToolByName |
---|
| 7 | from Products.CMFDefault.Link import Link |
---|
| 8 | from StringIO import StringIO |
---|
| 9 | |
---|
| 10 | from Products.qClickTrackingTool.ClickTracker import ClickTracker |
---|
| 11 | from Products.qClickTrackingTool.Workflow import createWorkflow |
---|
| 12 | from Products.qClickTrackingTool.ClickTracker import ClickTracker |
---|
| 13 | from Products.qClickTrackingTool.config import * |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | def write_object_properties(self, obj, out): |
---|
| 17 | properties = {} |
---|
| 18 | pc = getToolByName(self, 'portal_clicktracker') |
---|
| 19 | if getObjectsType(self, pc, out) == 'Link': |
---|
| 20 | properties['id'] = obj.id |
---|
| 21 | properties['title'] = obj.title |
---|
| 22 | properties['description'] = obj.description |
---|
| 23 | properties['remote_url'] = obj.getRemoteUrl() |
---|
| 24 | else: |
---|
| 25 | properties['id'] = obj.id |
---|
| 26 | properties['title'] = obj.Title() |
---|
| 27 | properties['description'] = obj.Description() |
---|
| 28 | properties['remote_url'] = obj.getRemoteUrl() |
---|
| 29 | |
---|
| 30 | return properties |
---|
| 31 | |
---|
| 32 | def update_object(self, obj, properties, out): |
---|
| 33 | obj.update(title = properties['title'], |
---|
| 34 | description = properties['description'], |
---|
| 35 | url = properties['remote_url']) |
---|
| 36 | |
---|
| 37 | def convert_objects(self, container, new_type, out): |
---|
| 38 | pt = getToolByName(self, 'portal_types') |
---|
| 39 | if getObjectsType(self, container, out): |
---|
| 40 | for o in listFolderItems(container)[:]: |
---|
| 41 | prop = write_object_properties(self, o, out) |
---|
| 42 | container._delObject(o.id) |
---|
| 43 | fti = pt.getTypeInfo('ClickTracker') |
---|
| 44 | fti.manage_changeProperties(allowed_content_types = (new_type,)) |
---|
| 45 | container.invokeFactory(id = prop['id'], type_name=new_type) |
---|
| 46 | campaign=getattr(container, prop['id']) |
---|
| 47 | update_object(self, campaign, prop, out) |
---|
| 48 | |
---|
| 49 | def listFolderItems(container): |
---|
| 50 | res = [] |
---|
| 51 | ids = container.objectIds() |
---|
| 52 | for ob_id in ids: |
---|
| 53 | res.append(container._getOb(ob_id)) |
---|
| 54 | return res |
---|
| 55 | |
---|
| 56 | def getObjectsType(self, container, out): |
---|
| 57 | pt = getToolByName(self, 'portal_types') |
---|
| 58 | ids = container.objectIds() |
---|
| 59 | if ids: |
---|
| 60 | obj = container._getOb(ids[0]) |
---|
| 61 | type_obj = obj.meta_type |
---|
| 62 | else: |
---|
| 63 | print >> out, "Portal click tracker is empty..." |
---|
| 64 | type_obj = None |
---|
| 65 | |
---|
| 66 | return type_obj |
---|
| 67 | |
---|
| 68 | def setPortalFactoryType(self, out,): |
---|
| 69 | pf=getToolByName(self, 'portal_factory') |
---|
| 70 | ftypes=list(pf.getFactoryTypes()) |
---|
| 71 | if TYPE_NAME not in ftypes: |
---|
| 72 | ftypes.append(TYPE_NAME) |
---|
| 73 | pf.manage_setPortalFactoryTypes(listOfTypeIds=ftypes) |
---|
| 74 | else: |
---|
| 75 | print >>out, " %s type already in portal_factory..." %TYPE_NAME |
---|
| 76 | |
---|
| 77 | print >> out, "Set %s type to portal_factory" %TYPE_NAME |
---|
| 78 | |
---|
| 79 | def install_tool(self, out, tool='ClickTracker'): |
---|
| 80 | portal=getToolByName(self, 'portal_url').getPortalObject() |
---|
| 81 | pt = getToolByName(self, 'portal_types') |
---|
| 82 | if not TOOLID in portal.objectIds(): |
---|
| 83 | addPloneTool=portal.manage_addProduct[PROJECTNAME].manage_addTool(tool) |
---|
| 84 | else: |
---|
| 85 | qi=getToolByName(self, 'portal_quickinstaller') |
---|
| 86 | p=qi._getOb(PROJECTNAME, None) |
---|
| 87 | oldVersion=p.getInstalledVersion() |
---|
| 88 | newVersion= qi.getProductVersion(PROJECTNAME) |
---|
| 89 | pc = getToolByName(self, 'portal_clicktracker') |
---|
| 90 | if oldVersion<newVersion: |
---|
| 91 | convert_objects(self, pc, TYPE_NAME, out) |
---|
| 92 | |
---|
| 93 | def customizing_FormController(self, out): |
---|
| 94 | fc = getToolByName(self, 'portal_form_controller') |
---|
| 95 | fc.addFormAction('validate_integrity', |
---|
| 96 | 'success', |
---|
| 97 | 'campaign', |
---|
| 98 | None, |
---|
| 99 | 'redirect_to', |
---|
| 100 | 'string:portal_url/portal_clicktracker/portal_clicktracker_view') |
---|
| 101 | def install_configlet(self, out): |
---|
| 102 | control_panel=getToolByName(self,'portal_controlpanel') |
---|
| 103 | control_panel.registerConfiglet(PROJECTNAME, |
---|
| 104 | 'Click Tracking Tool', |
---|
| 105 | 'string:${portal_url}/%s/portal_clicktracker_view' % TOOLID, |
---|
| 106 | permission=MANAGE_CLICKTRACKINGTOOL_PERMISSION, |
---|
| 107 | imageUrl='link_icon.gif', |
---|
| 108 | category='Products', |
---|
| 109 | ) |
---|
| 110 | print >> out, "Installed configlet.,," |
---|
| 111 | |
---|
| 112 | def install_workflow(self, out): |
---|
| 113 | portal_workflow=getToolByName(self, 'portal_workflow') |
---|
| 114 | |
---|
| 115 | #register the workflow in the system |
---|
| 116 | addWorkflowFactory(createWorkflow, |
---|
| 117 | id=C_WORKFLOWID, |
---|
| 118 | title='Campaign Workflow') |
---|
| 119 | |
---|
| 120 | portal_workflow.manage_addWorkflow(id=C_WORKFLOWID, workflow_type=C_WORKFLOWID +' (Campaign Workflow)') |
---|
| 121 | #set workflow for Campaign |
---|
| 122 | portal_workflow.setChainForPortalTypes( ('campaign'), C_WORKFLOWID) |
---|
| 123 | print >> out, "Installed workflow..." |
---|
| 124 | |
---|
| 125 | def fix_permissions(self, out): |
---|
| 126 | portal_workflow=getToolByName(self, 'portal_workflow') |
---|
| 127 | #remove worklow from tool |
---|
| 128 | portal_workflow.setChainForPortalTypes( ('ClickTracker (qClickTrackingTool)'), '') |
---|
| 129 | #set permission for portal_clicktracker |
---|
| 130 | pc=getToolByName(self, 'portal_clicktracker') |
---|
| 131 | pc.manage_permission(CMFCorePermissions.ListFolderContents, ('Manager', 'Owner', 'Anonymous'), 1) |
---|
| 132 | |
---|
| 133 | print >> out, "Click Tracking Tool Permissions fixed..." |
---|
| 134 | |
---|
| 135 | def remove_configlet(self, out): |
---|
| 136 | # unregister Configlet |
---|
| 137 | control_panel=getToolByName(self,'portal_controlpanel') |
---|
| 138 | control_panel.unregisterConfiglet(PROJECTNAME) |
---|
| 139 | |
---|
| 140 | def remove_FormControllerAction(self, out): |
---|
| 141 | fc = getToolByName(self, 'portal_form_controller') |
---|
| 142 | if fc.actions.match('validate_integrity', 'success', TYPE_NAME, None): |
---|
| 143 | fc.actions.delete(FormActionKey('validate_integrity', 'success', TYPE_NAME, None, fc)) |
---|
| 144 | |
---|
| 145 | def install(self): |
---|
| 146 | |
---|
| 147 | out=StringIO(); |
---|
| 148 | |
---|
| 149 | pt = getToolByName(self, 'portal_types') |
---|
| 150 | installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME) |
---|
| 151 | setPortalFactoryType(self, out) |
---|
| 152 | install_subskin(self, out, GLOBALS) |
---|
| 153 | install_workflow(self, out) |
---|
| 154 | install_tool(self, out) |
---|
| 155 | install_configlet(self, out) |
---|
| 156 | fix_permissions(self, out) |
---|
| 157 | customizing_FormController(self, out) |
---|
| 158 | |
---|
| 159 | print >> out, "Successfully installed %s." % PROJECTNAME |
---|
| 160 | return out.getvalue() |
---|
| 161 | |
---|
| 162 | def uninstall(self): |
---|
| 163 | out = StringIO() |
---|
| 164 | |
---|
| 165 | remove_configlet(self, out) |
---|
| 166 | remove_FormControllerAction(self, out) |
---|
| 167 | |
---|
| 168 | print >> out, "Successfully uninstalled %s." % PROJECTNAME |
---|
| 169 | return out.getvalue() |
---|