def __call__(self): """ Create a new revision based on an existing item IRevisionFile """ revisionfile_info = IRevisionFileInfo(self.context) revision_folder = revisionfile_info.revision_folder() revision_info = IRevisionInfo(revision_folder) next_code = revision_info.next_code() try: _copy(revision_folder, self.context, revision_folder, self.context.getId(), next_code) cloned_revision = getattr(revision_folder, next_code) member = getMultiAdapter((self.context, self.request), name=u'plone_portal_state').member() creator = member.getId() cloned_revision.setCreators([creator]) plone_utils = getToolByName(self.context, 'plone_utils') plone_utils.changeOwnershipOf(cloned_revision, member.getId()) cloned_revision.setRelatedItems(self.context.getRelatedItems()) cloned_revision.setEffectiveDate(None) cloned_revision.reindexObject() cloned_revision.reindexObjectSecurity() except ConflictError: raise except Exception: IStatusMessage(self.request).addStatusMessage(_(u'cloned_revision_error', default=u'Error'), type='error') else: IStatusMessage(self.request).addStatusMessage(_(u'cloned_revision_ok', default=u'Revision cloned correctly'), type='info') self.request.response.redirect("/".join(revision_folder.getPhysicalPath()))
def __call__(self): """ Create a new revision folder based on an existing item """ context_id = self.context.getId() parent = getMultiAdapter((self.context, self.request), name=u'plone_context_state').parent() try: uniqueid = parent.generateUniqueId('Folder') uniqueid = parent.invokeFactory('Folder', uniqueid) folderish_obj = getattr(parent, uniqueid) folderish_obj.setTitle(self.context.Title()) alsoProvides(folderish_obj, IRevision) revision_info = IRevisionInfo(folderish_obj) next_code = revision_info.next_code() transaction.savepoint(optimistic=True) _move(parent, self.context, folderish_obj, context_id, next_code) revisionfile = getattr(folderish_obj, next_code) alsoProvides(revisionfile, IRevisionFile) _move(parent, folderish_obj, parent, uniqueid, context_id) newcontext = getattr(parent, context_id) ppw = getToolByName(newcontext, 'portal_placeful_workflow', None) if ppw: portal_type = self.context.portal_type priority_utility = queryUtility(IRevisionWorkflowUtility, name=portal_type) priority_utility = not priority_utility and queryUtility(IRevisionWorkflowUtility) policy_id = priority_utility and priority_utility.policy_id() if policy_id and ppw.isValidPolicyName(policy_id): old_sm = SecurityManagement.getSecurityManager() try: SecurityManagement.newSecurityManager(None, SpecialUsers.system) newcontext.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig() config = ppw.getWorkflowPolicyConfig(newcontext) config.setPolicyIn(policy=policy_id) config.setPolicyBelow(policy=policy_id, update_security=True) finally: SecurityManagement.setSecurityManager(old_sm) newcontext.reindexObject() newcontext.reindexObjectSecurity() except ConflictError: raise except Exception: view_url = getMultiAdapter((self.context, self.request), name=u'plone_context_state').view_url() self.request.response.redirect(view_url) IStatusMessage(self.request).addStatusMessage(_(u'enabled_revision_error', default=u'Error'), type='error') else: view_url = getMultiAdapter((folderish_obj, self.request), name=u'plone_context_state').view_url() self.request.response.redirect(view_url) IStatusMessage(self.request).addStatusMessage(_(u'enabled_revision_ok', default=u'Revision created correctly'), type='info')