def _processDeletion(self, policy, rules, deletion_source, documentId, content, ctx=None): # all of this seems a little expensive for inline to index/unindex factory = DescriptorFactory(policy) descriptor = factory(content) rule_id, path = self._index[documentId] rule = rules._getOb(rule_id, None) if rule is None: # try to find any matching rule # print "XXX", "Rule not found", rule_id mastering = policy.getContentMastering() if not mastering.prepare(descriptor): print "XXX" * 2, "Can't process deletion" return else: # we know which rule to use if ctx is None: portal = getToolByName(policy, "portal_url").getPortalObject() ctx = getDeployExprContext(content, portal) rule.process(descriptor, ctx) record = DeletionRecord(policy, descriptor) record.rule_id = rule.getId() deletion_source.addRecord(record) del self._index[documentId] self._length(-1)
def transform(self, descriptor, rendered, file_path): if not self.enabled: return rendered portal = getToolByName(self,'portal_url').getPortalObject() content = descriptor.getContent() context = getDeployExprContext(content, portal) for fr in self.rules.objectValues('Content Transform Rule'): if not fr.valid(context): continue try: script = getTransform(fr.script_id) except: log.warning('Content Transform Script %s Not Found'%str(fr.script_id)) continue try: rendered = script(descriptor, rendered, file_path) except: log.warning('Content Transform Exception from %s on %s '%( fr.script_id, descriptor.content_url) ) return rendered
def prepare(self, descriptor): """ prepare a descriptor for deployment by finding and applying a deployment/content/mime rule for it. """ portal = getToolByName(self, 'portal_url').getPortalObject() c = descriptor.getContent() ctx = getDeployExprContext(c, portal) mappings = self.rules.objectValues() for m in mappings: if m.isValid( c, ctx): m.process( descriptor, ctx ) return True log.debug('no rule for (%s)->(%s)'%(str(c.portal_type), descriptor.content_url)) return None
def index_object(self, documentId, obj, threshold=None): # policy execution directly populates through the # recordObject api. # this implementation focuses on checking whether an # object is already deployed, and if it is then we check # whether or not it still matches to a content rule # if doesn't then we create a deletion record for it. # in order to process workflow changes, the policy index id # needs to be added as a dummy workflow variable. # note of caution filters operate out of band from this... # XXX for completeness we should do filter matching as well. if not self._index.has_key(documentId): return 1 obj = unwrap_object(obj) policy = self._getPolicy() deletion_source = policy._getOb(DefaultConfiguration.DeletionSource, None) if deletion_source is None: # XXX log me return 1 portal = getToolByName(self, "portal_url").getPortalObject() ctx = getDeployExprContext(obj, portal) match_found = None rules = policy.getContentMastering().rules for rule in rules.objectValues(): if rule.isValid(obj, ctx): match_found = rule break if match_found is not None: return 1 self._processDeletion(policy, rules, deletion_source, documentId, obj, ctx) return 1