def test_archeologist_returns_modifyable_persistent_reference(self): dossier = create(Builder('dossier')) document = create(Builder('document') .within(dossier) .attach_file_containing( bumblebee_asset('example.docx').bytes(), u'example.docx')) create_document_version(document, version_id=1) create_document_version(document, version_id=2) repository = api.portal.get_tool('portal_repository') archived_obj = Archeologist( document, repository.retrieve(document, selector=1)).excavate() annotations = IAnnotations(archived_obj) self.assertNotIn(TEST_ANNOTATION_KEY, annotations) annotations[TEST_ANNOTATION_KEY] = 'can touch this!' archived_obj.some_attr = 'can touch this!' transaction.commit() archived_obj = Archeologist( document, repository.retrieve(document, selector=1)).excavate() annotations = IAnnotations(archived_obj) self.assertIn(TEST_ANNOTATION_KEY, annotations) self.assertEqual('can touch this!', annotations[TEST_ANNOTATION_KEY]) self.assertEqual('can touch this!', archived_obj.some_attr)
def fix_document_title(self, document): """Make sure document title is unicode.""" if not document: return document.title = safe_unicode(document.title) for version in self.repository.getHistory(document): archived_document = Archeologist(document, version).excavate() archived_document.title = safe_unicode(archived_document.title) archived_document._p_changed = True self.journal_fixer.fix_entries(document)
def test_ftw_journal_is_not_versioned_archeologist(self): """This test confirms that the Archeologist's view of the historic annotations is consistent with CMFEdition's APIs. """ self.login(self.regular_user) self.create_version(self.document) repo_tool = api.portal.get_tool('portal_repository') shadow_history = repo_tool.getHistoryMetadata(self.document) self.assertEquals(2, len(shadow_history)) for version_number in range(len(shadow_history)): archeologist = Archeologist( self.document, repo_tool.retrieve(self.document, selector=version_number)) archived_obj = archeologist.excavate() archived_ann = IAnnotations(archived_obj) self.assertNotIn(self.JOURNAL_KEY, archived_ann)
def test_archeologist_returns_modifyable_persistent_reference(self): self.login(self.regular_user) create_document_version(self.document, version_id=1) create_document_version(self.document, version_id=2) repository = api.portal.get_tool('portal_repository') archived_obj = Archeologist( self.document, repository.retrieve(self.document, selector=1)).excavate() annotations = IAnnotations(archived_obj) self.assertNotIn(TEST_ANNOTATION_KEY, annotations) annotations[TEST_ANNOTATION_KEY] = 'can touch this!' archived_obj.some_attr = 'can touch this!' archived_obj = Archeologist( self.document, repository.retrieve(self.document, selector=1)).excavate() annotations = IAnnotations(archived_obj) self.assertIn(TEST_ANNOTATION_KEY, annotations) self.assertEqual('can touch this!', annotations[TEST_ANNOTATION_KEY]) self.assertEqual('can touch this!', archived_obj.some_attr)
def main(app, argv=sys.argv[1:]): options, args = parser.parse_args() mode = options.mode.lower() if options.mode else None if not options.mode: parser.print_help() parser.error( 'Please specify the "mode" with "bin/instance run <yourscript> -m ' 'reindex | history | store | activate"\n' ) if options.plone_path: plone = app.unrestrictedTraverse(options.plone_path) else: plone = get_first_plone_site(app) setup_plone(plone) converter = getUtility(IBumblebeeConverter) if mode == 'reindex': LOG.info("Start indexing objects...") converter.reindex() return transaction.commit() elif mode == 'history': LOG.info("Start creating checksums for portal repository ...") repository = api.portal.get_tool('portal_repository') catalog = api.portal.get_tool('portal_catalog') brains = catalog.unrestrictedSearchResults( {'object_provides': 'ftw.bumblebee.interfaces.IBumblebeeable'}) for brain in ProgressLogger( 'Create checksums for objects in portal repository', brains, logger=LOG): obj = brain.getObject() versions = repository.getHistory(obj) if IOGMailMarker.providedBy(obj): if len(versions) > 0: LOG.warning('Found mail with versions: {}'.format('/'.join(obj.getPhysicalPath()))) continue for version in versions: # we have to calculate the checksum on the "restored" object # returned by `portal_repository`. The archived object does not # contain an accessible file without `portal_repository` magic. version_checksum = IBumblebeeDocument(version.object).calculate_checksum() archived_obj = Archeologist(obj, version).excavate() annotations = IAnnotations(archived_obj) annotations[DOCUMENT_CHECKSUM_ANNOTATION_KEY] = version_checksum archived_obj._p_changed = True return transaction.commit() elif mode == 'store': LOG.info("Start storing objects...") if not options.reset: LOG.warning( "You started storing without reseting the timestamp. " "Already converted objects will be skipped.") return converter.store(deferred=True, reset_timestamp=options.reset) elif mode == 'activate': api.portal.set_registry_record( 'is_feature_enabled', True, interface=IGeverBumblebeeSettings) LOG.info("activating bumblebee feature in registry.") return transaction.commit() else: parser.print_help() parser.error('You entered an invalid mode: {}\n'.format(mode))