Beispiel #1
0
    def checkinResource(self, object, message='', user=None):
        """
        Checkin a new version of an object to the repository

        object  : the new object
        message : a string describing the changes
        user    : the name of the user creating the new version
        """

        objectId = object.objectId
        vf = self.getVersionFolder(objectId)
        
        # Initialize history if it doesn't exist yet
        if not vf.objectIds():
            version = "1.1"
            addLatestReference(vf, 'latest', '', version)
        else:
            # Sanity check: if latest version isn't the base of these changes, it's a problem
            # if not self.isLatestVersion(object):
            version = object.getVersion()
            if (version != vf.latest.getVersion()):
                raise CommitError, "Version mismatch: version %s checked out, but latest is %s" % (version, vf.latest.getVersion())
            version = incrementMinor(version)
            
        # Clone the object as a new revision of this collection
        #self._log("Cloning %s" % obj, zLOG.INFO)
        zLOG.LOG("VersionFolder", zLOG.INFO, "Cloning %s (%s)" % (object, self.REQUEST['PATH_INFO']))
        vf.manage_clone(object, version)
        clone = getattr(vf, version)

        # Explicity set repository/versioning metadata
        # FIXME: This should be taken care of by the workflow tool
        try:
            clone.setVersion(version)
        except AttributeError:
            clone.version = version
        try:
            clone.setRevised(DateTime())
        except AttributeError:
            clone.revised = DateTime()
        clone.submitter = user
        clone.submitlog = message
        # The state must be public so the object uses the correct method for viewing (ewwww!)
        clone.state = 'public'

        # Reset the 'latest' reference
        vf.latest.edit(clone.Title(), version)
        self.catalog.catalog_object(vf.latest)

        #Push metadata into DB
        self.portal_moduledb.insertModuleVersion(clone)

        # Generate collxml and stuff it into the DB as well
        xml = clone.restrictedTraverse('source_create')()
        # We know this will be a new file, so just insert it.
        res = self.portal_moduledb.sqlInsertFile(file = Binary(xml), media_type='text/xml')
        fid = res[0].fileid
        # This step depends on the InsertModuleVersion call, above
        self.portal_moduledb.sqlInsertModuleFile(moduleid=clone.objectId, version=clone.version, fileid=fid, filename='collection.xml',mimetype='text/xml')
Beispiel #2
0
    def checkinResource(self, object, message='', user=None):
        """
        Checkin a new version of an object to the repository

        object  : the new object
        message : a string describing the changes
        user    : the name of the user creating the new version
        """

        objectId = object.objectId
        vf = self.getVersionFolder(objectId)
        
        # Initialize history if it doesn't exist yet
        if not vf.objectIds():
            version = "1.1"
            addLatestReference(vf, 'latest', '', version)
        else:
            # Sanity check: if latest version isn't the base of these changes, it's a problem
            # if not self.isLatestVersion(object):
            version = object.getVersion()
            if (version != vf.latest.getVersion()):
                raise CommitError, "Version mismatch: version %s checked out, but latest is %s" % (version, vf.latest.getVersion())
            version = incrementMinor(version)
            
        # Clone the object as a new revision of this collection
        #self._log("Cloning %s" % obj, zLOG.INFO)
        zLOG.LOG("VersionFolder", zLOG.INFO, "Cloning %s (%s)" % (object, self.REQUEST['PATH_INFO']))
        vf.manage_clone(object, version)
        clone = getattr(vf, version)

        # Explicity set repository/versioning metadata
        # FIXME: This should be taken care of by the workflow tool
        try:
            clone.setVersion(version)
        except AttributeError:
            clone.version = version
        try:
            clone.setRevised(DateTime())
        except AttributeError:
            clone.revised = DateTime()
        clone.submitter = user
        clone.submitlog = message
        # The state must be public so the object uses the correct method for viewing (ewwww!)
        clone.state = 'public'

        # Reset the 'latest' reference
        vf.latest.edit(clone.Title(), version)
        self.catalog.catalog_object(vf.latest)

        #Push metadata into DB
        self.portal_moduledb.insertModuleVersion(clone)

        # Generate collxml and stuff it into the DB as well
        xml = clone.restrictedTraverse('source_create')()
        # We know this will be a new file, so just insert it.
        res = self.portal_moduledb.sqlInsertFile(file = Binary(xml), media_type='text/xml')
        fid = res[0].fileid
        # This step depends on the InsertModuleVersion call, above
        self.portal_moduledb.sqlInsertModuleFile(moduleid=clone.objectId, version=clone.version, fileid=fid, filename='collection.xml',mimetype='text/xml')
    def _create_collection(self, key, data):
        """Create a collection in ZODB from data in the postgres db"""
        moduledb_tool = getToolByName(self, 'portal_moduledb')

        # Get collection tree
        tree = moduledb_tool.sqlGetCollectionTree(id=data['id'],
                                                  version=data['version'],
                                                  aq_parent=self).tuples()

        if not tree or tree[0][0] is None:
            logger.debug('Unable to get collection tree for %s' % key)
            # can't get the collection tree, nothing to do
            raise KeyError(key)

        tree = simplejson.loads(tree[0][0].decode('utf-8'))

        # Create a version folder (e.g. /plone/content/col11554)
        storage = self.getStorageForType('Collection')
        if data['id'] not in self.objectIds():
            vf = VersionFolder(data['id'], storage=storage.id)
            self._setObject(data['id'], vf, set_owner=0)
            logger.debug('Created VersionFolder %s' %
                         '/'.join(vf.getPhysicalPath()))
        vf = getattr(self, data['id'])

        # Create a collection (e.g. /plone/content/col11554/1.1)
        collection = _createObjectByType('Collection', vf, data['version'])
        collection.objectId = data['id']
        collection.version = data['version']
        collection.created = DateTime(data['_created'].isoformat())
        collection.revised = DateTime(data['_revised'].isoformat())
        collection.setKeywords(data['_keywords'].split(', '))
        collection.setAbstract(data['abstract'])
        for k, v in dict(title=data['name'],
                         authors=data['authors'],
                         maintainers=data['maintainers'],
                         licensors=data['licensors'],
                         license=data['license'],
                         _parent_id=data['parent_id'],
                         _parent_version=data['parent_version'],
                         parentAuthors=data['parentAuthors'],
                         language=data['language'],
                         subject=data['_subject'].split(', ')).items():
            setattr(collection, k, v)
        if data.has_key('print_style'):
            collection.parameters.manage_addProperty('printstyle',
                                                     data['print_style'],
                                                     'string')
        logger.debug('Created collection %s' %
                     '/'.join(collection.getPhysicalPath()))
        logger.debug(str(collection.propertyItems()))

        # Code copied from publishObject
        self.cache.clearSearchCache()
        #FIXME: these things shouldn't be done here, but with some sort of
        # event system hitcount update
        hitcount = getToolByName(self, 'portal_hitcount', None)
        if hitcount:
            hitcount.registerObject(data['id'], DateTime())
        # Not going to trigger pdf production here
        # (storage.notifyObjectRevised), should be in cnx-publishing
        # instead

        modules = []

        def create_objects(contents, folder):
            # Create the top level objects
            for node in contents:
                new_folder = None
                if node['id'] == 'subcol' or node['id'].startswith('col'):
                    new_folder = _createObjectByType(
                        'SubCollection', folder,
                        folder.generateUniqueId('SubCollection'))
                    new_folder.title = node['title']
                    logger.debug('Created subcollection: %s' % new_folder)
                elif node['id'].startswith('m'):
                    if node['id'] not in self.objectIds():
                        # Create the module if it doesn't exist
                        module = self[node['id']]
                    obj = _createObjectByType('PublishedContentPointer',
                                              folder, node['id'])
                    obj.moduleId = node['id']
                    obj.version = 'latest'
                    # FIXME - should track if original was set to latest, but
                    # that info is not sent properly to the DB, nor returned
                    # in the json
                    # if node['latest']:
                    #    obj.version = 'latest'
                    # else:
                    #    obj.version = node['version']
                    modules.append((node['id'], node['version']))
                    logger.debug('Created PublishedContentPointer %s@%s' %
                                 (obj.getModuleId(), obj.getVersion()))

                # Create all the objects in "contents"
                if new_folder:
                    create_objects(node.get('contents') or [], new_folder)

        # Create SubCollections and PublishedContentPointer according to
        # the collection tree
        create_objects(tree['contents'], collection)
        # Copied from Products.RhaptosRepository.VersionFolder.checkinResource
        if 'latest' not in vf.objectIds():
            addLatestReference(vf, 'latest', collection.Title(),
                               collection.version)
            logger.debug('Added latest reference')
        else:
            if collection.version.split('.') > vf.latest.version.split('.'):
                vf.latest.edit(collection.Title(), collection.version)

        collection.submitter = data['submitter']
        collection.submitlog = data['submitlog']
        collection.state = 'public'
        logger.debug('Finished creating collection')

        # Create collection.xml if it doesn't exist in postgres
        filenames = moduledb_tool.sqlGetModuleFilenames(
            id=data['id'], version=data['version']).tuples()
        if filenames and 'collection.xml' not in str(filenames):
            logger.debug('Create collection.xml for %s' % key)
            xml = collection.restrictedTraverse('source_create')()
            res = moduledb_tool.sqlInsertFile(file=Binary(xml),
                                              media_type='text/xml')
            fid = res[0].fileid

            moduledb_tool.sqlInsertModuleFile(moduleid=collection.objectId,
                                              version=collection.version,
                                              fileid=fid,
                                              filename='collection.xml',
                                              mimetype='text/xml',
                                              aq_parent=self)

        pubobj = storage.getObject(data['id'], 'latest')
        self.catalog.catalog_object(pubobj)
        logger.debug('Add %s to catalog' % '/'.join(pubobj.getPhysicalPath()))
Beispiel #4
0
    def _create_collection(self, key, data):
        """Create a collection in ZODB from data in the postgres db"""
        moduledb_tool = getToolByName(self, 'portal_moduledb')

        # Get collection tree
        tree = moduledb_tool.sqlGetCollectionTree(
            id=data['id'], version=data['version'], aq_parent=self).tuples()

        if not tree or tree[0][0] is None:
            logger.debug('Unable to get collection tree for %s' % key)
            # can't get the collection tree, nothing to do
            raise KeyError(key)

        tree = simplejson.loads(tree[0][0].decode('utf-8'))

        # Create a version folder (e.g. /plone/content/col11554)
        storage = self.getStorageForType('Collection')
        if data['id'] not in self.objectIds():
            vf = VersionFolder(data['id'], storage=storage.id)
            self._setObject(data['id'], vf, set_owner=0)
            logger.debug('Created VersionFolder %s'
                         % '/'.join(vf.getPhysicalPath()))
        vf = getattr(self, data['id'])

        # Create a collection (e.g. /plone/content/col11554/1.1)
        collection = _createObjectByType('Collection', vf, data['version'])
        collection.objectId = data['id']
        collection.version = data['version']
        collection.created = DateTime(data['_created'].isoformat())
        collection.revised = DateTime(data['_revised'].isoformat())
        for k, v in dict(title=data['name'], authors=data['authors'],
                         maintainers=data['maintainers'],
                         licensors=data['licensors'],
                         _parent_id=data['parent_id'],
                         _parent_version=data['parent_version'],
                         parentAuthors=data['parentAuthors'],
                         language=data['language'],
                         subject=data['_subject'].split(', ')).items():
            setattr(collection, k, v)
        if data.has_key('print_style'):
            collection.parameters.manage_addProperty('printstyle',data['print_style'],'string')
        logger.debug('Created collection %s'
                     % '/'.join(collection.getPhysicalPath()))
        logger.debug(str(collection.propertyItems()))

        # Code copied from publishObject
        self.cache.clearSearchCache()
        #FIXME: these things shouldn't be done here, but with some sort of
        # event system hitcount update
        hitcount = getToolByName(self, 'portal_hitcount', None)
        if hitcount:
            hitcount.registerObject(data['id'], DateTime())
        # Not going to trigger pdf production here
        # (storage.notifyObjectRevised), should be in cnx-publishing
        # instead

        modules = []

        def create_objects(contents, folder):
            # Create the top level objects
            for node in contents:
                new_folder = None
                if node['id'] == 'subcol':
                    new_folder = _createObjectByType(
                        'SubCollection', folder,
                        folder.generateUniqueId('SubCollection'))
                    new_folder.title = node['title']
                    logger.debug('Created subcollection: %s' % new_folder)
                elif node['id'].startswith('m'):
                    if node['id'] not in self.objectIds():
                        # Create the module if it doesn't exist
                        module = self[node['id']]
                    obj = _createObjectByType(
                        'PublishedContentPointer', folder, node['id'])
                    obj.moduleId = node['id']
                    obj.version = 'latest'
                    # FIXME - should track if original was set to latest, but
                    # that info is not sent properly to the DB, nor returned
                    # in the json
                    # if node['latest']:
                    #    obj.version = 'latest'
                    # else:
                    #    obj.version = node['version']
                    modules.append((node['id'], node['version']))
                    logger.debug('Created PublishedContentPointer %s@%s'
                                 % (obj.getModuleId(), obj.getVersion()))

                # Create all the objects in "contents"
                if new_folder:
                    create_objects(node.get('contents') or [], new_folder)

        # Create SubCollections and PublishedContentPointer according to
        # the collection tree
        create_objects(tree['contents'], collection)
        # Copied from Products.RhaptosRepository.VersionFolder.checkinResource
        if 'latest' not in vf.objectIds():
            addLatestReference(vf, 'latest', collection.Title(),
                               collection.version)
            logger.debug('Added latest reference')
        collection.submitter = data['submitter']
        collection.submitlog = data['submitlog']
        collection.state = 'public'
        logger.debug('Finished creating collection')

        # Create collection.xml if it doesn't exist in postgres
        filenames = moduledb_tool.sqlGetModuleFilenames(
            id=data['id'], version=data['version']).tuples()
        if filenames and 'collection.xml' not in str(filenames):
            logger.debug('Create collection.xml for %s' % key)
            xml = collection.restrictedTraverse('source_create')()
            res = moduledb_tool.sqlInsertFile(file = Binary(xml), media_type='text/xml')
            fid = res[0].fileid

            moduledb_tool.sqlInsertModuleFile(
                moduleid=collection.objectId, version=collection.version,
                fileid=fid, filename='collection.xml', mimetype='text/xml',
                aq_parent=self)

        pubobj = storage.getObject(data['id'], 'latest')
        self.catalog.catalog_object(pubobj)
        logger.debug('Add %s to catalog'
                     % '/'.join(pubobj.getPhysicalPath()))