def saveVersion(kls, obj, version):
        portal_archivist = getToolByName(obj, 'portal_archivist')
        objectdata = version['object']
        sys_metadata = version['sys_metadata']
        metadata = {}
        autoapply = True

        prep = portal_archivist.prepare(obj, metadata, sys_metadata)

        # set the originator of the save operation for the referenced
        # objects
        clone = prep.clone.object
        if sys_metadata['originator'] is None:
            sys_metadata['originator'] = "%s.%s.%s" % (
                prep.history_id,
                clone.version_id,
                clone.location_id,
            )
        clone = wrap(clone, aq_parent(aq_inner(obj)))
        ContentObjectMigrator._set(clone, objectdata)  # set obj values...
        # What comes now is the current hardcoded policy:
        #
        # - recursively save inside references, then set a version aware
        #   reference
        # - on outside references only set a version aware reference
        #   (if under version control)
        inside_refs = map(
            lambda original_refs, clone_refs:
            (original_refs, clone_refs.getAttribute()),
            prep.original.inside_refs, prep.clone.inside_refs)
        for orig_ref, clone_ref in inside_refs:
            #self._recursiveSave(orig_ref, app_metadata, sys_metadata,
            #                    autoapply)
            raise
            clone_ref.setReference(orig_ref, remove_info=True)

        outside_refs = map(lambda oref, cref: (oref, cref.getAttribute()),
                           prep.original.outside_refs, prep.clone.outside_refs)
        for orig_ref, clone_ref in outside_refs:
            clone_ref.setReference(orig_ref, remove_info=True)

        portal_archivist.save(prep, autoregister=autoapply)

        # just to ensure that the working copy has the correct
        # ``version_id``
        prep.copyVersionIdFromClone()
    def _retrieve(self, obj, selector, preserve, countPurged):
        """Retrieve a former state.

        Puts the returned version into same context as the working copy is
        (to make attribute access acquirable).
        """
        # We make a savepoint so that we can undo anything that happened
        # during the transaction.  There may be resource managers which do not
        # support savepoints, those will raise errors here, which means that
        # retrieve and getHistory should not be used as a part of more
        # complex transactions.
        saved = transaction.savepoint()
        vd = self._recursiveRetrieve(
            obj=obj, selector=selector, preserve=preserve, inplace=False, countPurged=countPurged
        )
        saved.rollback()
        wrapped = wrap(vd.data.object, aq_parent(aq_inner(obj)))
        return VersionData(wrapped, vd.preserved_data, vd.sys_metadata, vd.app_metadata)
Exemple #3
0
    def _retrieve(self, obj, selector, preserve, countPurged):
        """Retrieve a former state.

        Puts the returned version into same context as the working copy is
        (to make attribute access acquirable).
        """
        # We make a savepoint so that we can undo anything that happened
        # during the transaction.  There may be resource managers which do not
        # support savepoints, those will raise errors here, which means that
        # retrieve and getHistory should not be used as a part of more
        # complex transactions.
        saved = transaction.savepoint()
        vd = self._recursiveRetrieve(obj=obj, selector=selector,
                                     preserve=preserve, inplace=False,
                                     countPurged=countPurged)
        saved.rollback()
        wrapped = wrap(vd.data.object, aq_parent(aq_inner(obj)))
        return VersionData(wrapped, vd.preserved_data,
                           vd.sys_metadata, vd.app_metadata)
    def saveVersion(kls, obj, version):
        portal_archivist = getToolByName(obj, 'portal_archivist')
        objectdata = version['object']
        sys_metadata = version['sys_metadata']
        metadata = {}
        autoapply = True

        prep = portal_archivist.prepare(obj, metadata, sys_metadata)

        # set the originator of the save operation for the referenced
        # objects
        clone = prep.clone.object
        if sys_metadata['originator'] is None:
            sys_metadata['originator'] = "%s.%s.%s" % (prep.history_id,
                                                       clone.version_id,
                                                       clone.location_id, )
        clone = wrap(clone, aq_parent(aq_inner(obj)))
        ContentObjectMigrator._set(clone, objectdata)  # set obj values...
        # What comes now is the current hardcoded policy:
        #
        # - recursively save inside references, then set a version aware
        #   reference
        # - on outside references only set a version aware reference
        #   (if under version control)
        inside_refs = map(lambda original_refs, clone_refs:
                          (original_refs, clone_refs.getAttribute()),
                          prep.original.inside_refs, prep.clone.inside_refs)
        for orig_ref, clone_ref in inside_refs:
            #self._recursiveSave(orig_ref, app_metadata, sys_metadata,
            #                    autoapply)
            raise
            clone_ref.setReference(orig_ref, remove_info=True)

        outside_refs = map(lambda oref, cref: (oref, cref.getAttribute()),
                           prep.original.outside_refs, prep.clone.outside_refs)
        for orig_ref, clone_ref in outside_refs:
            clone_ref.setReference(orig_ref, remove_info=True)

        portal_archivist.save(prep, autoregister=autoapply)

        # just to ensure that the working copy has the correct
        # ``version_id``
        prep.copyVersionIdFromClone()