Ejemplo n.º 1
0
 def testImageMigration(self):
     gif = getImage()
     foo = self.folder[self.folder.invokeFactory('ATImage', id='foo',
         title='an image', image=gif, subject=('foo', 'bar'),
         contributors=('me'))]
     # fake old content from before applying the replacement profile
     foo._setPortalTypeName('Image')
     foo.reindexObject(idxs=('portal_type', ))
     # check to be migrated content
     self.assertTrue(isinstance(foo, ATImage), 'not an image?')
     self.assertEqual(foo.Title(), 'an image')
     self.assertEqual(foo.getContentType(), 'image/gif')
     self.assertEqual(foo.getPortalTypeName(), 'Image')
     self.assertEqual(foo.Subject(), ('foo', 'bar'))
     self.assertEqual(foo.Contributors(), ('me', ))
     # migrate & check migrated content item
     self.assertEqual(migrateATBlobImages(self.portal),
         'Migrating /plone/Members/test_user_1_/foo (Image -> Image)\n')
     foo = self.folder['foo']
     self.assertTrue(isinstance(foo, ATBlob), 'not a blob?')
     self.assertTrue(isinstance(foo.getField('image'), BlobField), 'no blob?')
     self.assertEqual(foo.Title(), 'an image')
     self.assertEqual(foo.getContentType(), 'image/gif')
     self.assertEqual(foo.getPortalTypeName(), 'Image')
     self.assertEqual(foo.Subject(), ('foo', 'bar'))
     self.assertEqual(foo.Contributors(), ('me', ))
     blob = foo.getImage().getBlob().open('r')
     self.assertEqual(blob.read(), gif)
Ejemplo n.º 2
0
def convertToBlobs(context):
    """Convert files and images to blobs.

    We disable link integrity checks here, as the migration only
    removes objects to recreate them fresh, so in the end nothing is
    permanently removed.
    """
    logger.info('Started migration of files to blobs.')
    from plone.app.blob.migrations import migrateATBlobFiles
    sprop = getToolByName(context, 'portal_properties').site_properties
    if sprop.hasProperty('enable_link_integrity_checks'):
        ori_enable_link_integrity_checks = sprop.getProperty('enable_link_integrity_checks')
        if ori_enable_link_integrity_checks:
            logger.info('Temporarily disabled link integrity checking')
            sprop.enable_link_integrity_checks = False
    else:
        ori_enable_link_integrity_checks = None

    output = migrateATBlobFiles(context)
    count = len(output.split('\n')) - 1
    logger.info('Migrated %s files to blobs.' % count)

    logger.info('Started migration of images to blobs.')
    from plone.app.blob.migrations import migrateATBlobImages
    output = migrateATBlobImages(context)
    count = len(output.split('\n')) - 1
    logger.info('Migrated %s images to blobs.' % count)
    if ori_enable_link_integrity_checks:
        logger.info('Restored original link integrity checking setting')
        sprop.enable_link_integrity_checks = ori_enable_link_integrity_checks
Ejemplo n.º 3
0
def convertToBlobs(context):
    """Convert files and images to blobs.

    We disable link integrity checks here, as the migration only
    removes objects to recreate them fresh, so in the end nothing is
    permanently removed.
    """
    logger.info('Started migration of files to blobs.')
    from plone.app.blob.migrations import migrateATBlobFiles
    sprop = getToolByName(context, 'portal_properties').site_properties
    if sprop.hasProperty('enable_link_integrity_checks'):
        ori_enable_link_integrity_checks = sprop.getProperty(
            'enable_link_integrity_checks')
        if ori_enable_link_integrity_checks:
            logger.info('Temporarily disabled link integrity checking')
            sprop.enable_link_integrity_checks = False
    else:
        ori_enable_link_integrity_checks = None

    output = migrateATBlobFiles(context)
    count = len(output.split('\n')) - 1
    logger.info('Migrated %s files to blobs.' % count)

    logger.info('Started migration of images to blobs.')
    from plone.app.blob.migrations import migrateATBlobImages
    output = migrateATBlobImages(context)
    count = len(output.split('\n')) - 1
    logger.info('Migrated %s images to blobs.' % count)
    if ori_enable_link_integrity_checks:
        logger.info('Restored original link integrity checking setting')
        sprop.enable_link_integrity_checks = ori_enable_link_integrity_checks
Ejemplo n.º 4
0
 def testImageMigration(self):
     gif = getImage()
     foo = self.folder[self.folder.invokeFactory('ATImage',
                                                 id='foo',
                                                 title='an image',
                                                 image=gif,
                                                 subject=('foo', 'bar'),
                                                 contributors=('me'))]
     # fake old content from before applying the replacement profile
     foo._setPortalTypeName('Image')
     foo.reindexObject(idxs=('portal_type', ))
     # check to be migrated content
     self.assertTrue(isinstance(foo, ATImage), 'not an image?')
     self.assertEqual(foo.Title(), 'an image')
     self.assertEqual(foo.getContentType(), 'image/gif')
     self.assertEqual(foo.getPortalTypeName(), 'Image')
     self.assertEqual(foo.Subject(), ('foo', 'bar'))
     self.assertEqual(foo.Contributors(), ('me', ))
     # migrate & check migrated content item
     self.assertEqual(
         migrateATBlobImages(self.portal),
         'Migrating /plone/Members/test_user_1_/foo (Image -> Image)\n')
     foo = self.folder['foo']
     self.assertTrue(isinstance(foo, ATBlob), 'not a blob?')
     self.assertTrue(isinstance(foo.getField('image'), BlobField),
                     'no blob?')
     self.assertEqual(foo.Title(), 'an image')
     self.assertEqual(foo.getContentType(), 'image/gif')
     self.assertEqual(foo.getPortalTypeName(), 'Image')
     self.assertEqual(foo.Subject(), ('foo', 'bar'))
     self.assertEqual(foo.Contributors(), ('me', ))
     blob = foo.getImage().getBlob().open('r')
     self.assertEqual(blob.read(), gif)
Ejemplo n.º 5
0
 def testCatalogAfterImageMigration(self):
     gif = getImage()
     foo = self.folder[self.folder.invokeFactory('ATImage', id='foo',
         title='an image', image=gif, subject=('foo', 'bar'),
         contributors=('me'))]
     # fake old content from before applying the replacement profile
     foo._setPortalTypeName('Image')
     foo.reindexObject(idxs=('portal_type',))
     # remember the catalog data so it can be checked
     catalog = self.portal.portal_catalog
     rid = catalog(id='foo')[0].getRID()
     index_data = catalog.getIndexDataForRID(rid)
     meta_data = catalog.getMetadataForRID(rid)
     # migrate & check migrated content item
     self.assertEqual(migrateATBlobImages(self.portal),
         'Migrating /plone/Members/test_user_1_/foo (Image -> Image)\n')
     foo = self.folder['foo']
     brain = catalog(id='foo')[0]
     self.assertEqual(foo.UID(), brain.UID)
     self.assertEqual(foo.getObjSize(), brain.getObjSize)
     self.assertEqual(foo.getPortalTypeName(), brain.Type)
     # compare pre-migration and current catalog data...
     okay = ('meta_type', 'Type', 'object_provides', 'Language')
     for key, value in catalog.getIndexDataForRID(brain.getRID()).items():
         if not key in okay:
             self.assertEqual(index_data[key], value, 'index: %s' % key)
     okay = ('meta_type', 'getIcon')
     for key, value in catalog.getMetadataForRID(brain.getRID()).items():
         if not key in okay:
             self.assertEqual(meta_data[key], value, 'meta: %s' % key)
     # also make sure the `Type` index has been updated correctly
     brains = catalog(Type='Image')
     self.assertEqual([b.getObject() for b in brains], [foo])
Ejemplo n.º 6
0
    def testCatalogAfterImageMigration(self):
        gif = getImage()
        foo = self.folder[self.folder.invokeFactory('ATImage',
                                                    id='foo',
                                                    title='an image',
                                                    image=gif,
                                                    subject=('foo', 'bar'),
                                                    contributors=('me'))]

        # fake old content from before applying the replacement profile
        foo._setPortalTypeName('Image')
        foo.reindexObject(idxs=('portal_type', ))

        # remember the catalog data so it can be checked
        catalog = self.portal.portal_catalog
        rid = catalog(id='foo')[0].getRID()
        index_data = catalog.getIndexDataForRID(rid)
        meta_data = catalog.getMetadataForRID(rid)

        # migrate
        self.assertEqual(
            migrateATBlobImages(self.portal),
            'Migrating /plone/Members/test_user_1_/foo (Image -> Image)\n')
        foo = self.folder['foo']

        # Re-index date based indexes. It seems they're not properly re-indexed
        # after the migration is executed. Without this the tests may fail
        # due to to timing issues. Remember DateTimeIndex have resolution of
        # 1 minute.
        foo.reindexObject(idxs=('Date', 'created', 'modified', 'effective'))

        # check migrated content item
        brain = catalog(id='foo')[0]
        self.assertEqual(foo.UID(), brain.UID)
        self.assertEqual(foo.getObjSize(), brain.getObjSize)
        self.assertEqual(foo.getPortalTypeName(), brain.Type)

        # compare pre-migration and current catalog data...
        okay = ('meta_type', 'Type', 'object_provides', 'Language')
        for key, value in catalog.getIndexDataForRID(brain.getRID()).items():
            if not key in okay:
                self.assertEqual(
                    index_data[key], value, 'index: %s, old: %s, new: %s' %
                    (key, index_data[key], value))
        okay = ('meta_type', 'getIcon')
        for key, value in catalog.getMetadataForRID(brain.getRID()).items():
            if not key in okay:
                self.assertEqual(meta_data[key], value, 'meta: %s' % key)
        # also make sure the `Type` index has been updated correctly
        brains = catalog(Type='Image')
        self.assertEqual([b.getObject() for b in brains], [foo])
Ejemplo n.º 7
0
    def testCatalogAfterImageMigration(self):
        gif = getImage()
        foo = self.folder[self.folder.invokeFactory('ATImage', id='foo',
            title='an image', image=gif, subject=('foo', 'bar'),
            contributors=('me'))]

        # fake old content from before applying the replacement profile
        foo._setPortalTypeName('Image')
        foo.reindexObject(idxs=('portal_type', ))

        # remember the catalog data so it can be checked
        catalog = self.portal.portal_catalog
        rid = catalog(id='foo')[0].getRID()
        index_data = catalog.getIndexDataForRID(rid)
        meta_data = catalog.getMetadataForRID(rid)

        # migrate
        self.assertEqual(migrateATBlobImages(self.portal),
            'Migrating /plone/Members/test_user_1_/foo (Image -> Image)\n')
        foo = self.folder['foo']

        # Re-index date based indexes. It seems they're not properly re-indexed
        # after the migration is executed. Without this the tests may fail
        # due to to timing issues. Remember DateTimeIndex have resolution of
        # 1 minute.
        foo.reindexObject(idxs=('Date', 'created', 'modified', 'effective'))

        # check migrated content item
        brain = catalog(id='foo')[0]
        self.assertEqual(foo.UID(), brain.UID)
        self.assertEqual(foo.getObjSize(), brain.getObjSize)
        self.assertEqual(foo.getPortalTypeName(), brain.Type)

        # compare pre-migration and current catalog data...
        okay = ('meta_type', 'Type', 'object_provides', 'Language')
        for key, value in catalog.getIndexDataForRID(brain.getRID()).items():
            if not key in okay:
                self.assertEqual(
                    index_data[key],
                    value,
                    'index: %s, old: %s, new: %s' % (key, index_data[key], value)
                )
        okay = ('meta_type', 'getIcon')
        for key, value in catalog.getMetadataForRID(brain.getRID()).items():
            if not key in okay:
                self.assertEqual(meta_data[key], value, 'meta: %s' % key)
        # also make sure the `Type` index has been updated correctly
        brains = catalog(Type='Image')
        self.assertEqual([b.getObject() for b in brains], [foo])