def __call__(self):
        query = {'portal_type': 'opengever.dossier.templatedossier'}
        objects = self.catalog_unrestricted_search(query, full_objects=True)
        review_state_mapping = {
            ('opengever_templatedossier_workflow', 'opengever_templatefolder_workflow'): {
                'templatedossier-state-active': 'templatefolder-state-active'}
            }

        # Save current ITemplateDossierProperties settings
        create_doc_properties = api.portal.get_registry_record(
            'create_doc_properties', ITemplateDossierProperties)

        with WorkflowChainUpdater(objects, review_state_mapping,
                                  migrate_workflow_history=False) as updater:
            self.install_upgrade_profile()
            for obj in ProgressLogger("Migrate type opengever.dossier.templatedossier "
                                      "to opengever.dossier.templatefolder",
                                      updater.objects):

                self.migrate_class(obj, TemplateFolder)
                obj.portal_type = 'opengever.dossier.templatefolder'
                notify(ObjectModifiedEvent(obj))

        # Restore current ITemplateDossierProperties settings
        api.portal.set_registry_record(
            'create_doc_properties',
            create_doc_properties,
            ITemplateFolderProperties)
    def __call__(self):
        catalog = self.getToolByName('portal_catalog')
        brains = catalog.unrestrictedSearchResults(portal_type='ftw.mail.mail')

        with ProgressLogger('Migrating ftw.mail.mail class', brains) as step:
            for brain in brains:
                self.migrate_obj(brain.getObject())
                step()
Exemple #3
0
    def migrate_template_dossiers(self):
        catalog = api.portal.get_tool('portal_catalog')
        brains = catalog.unrestrictedSearchResults(
            portal_type='opengever.dossier.templatedossier')

        with ProgressLogger('Migrating templatedossier class', brains) as step:
            for brain in brains:
                self.migrate_object(brain.getObject())
                step()
    def __call__(self):
        self.user_ids = [user.userid for user in ogds_service().all_users()]

        catalog = self.getToolByName('portal_catalog')
        brains = catalog.unrestrictedSearchResults(
            portal_type='opengever.document.document')
        with ProgressLogger('Resolve document author', brains) as step:
            for brain in brains:
                self.resolve_document_author(brain)
                step()
Exemple #5
0
    def lookup_objects(self, types):
        portal = getSite()
        catalog = getToolByName(portal, 'portal_catalog')

        query = {'portal_type': types}
        brains = tuple(catalog.unrestrictedSearchResults(query))

        lookup = lambda brain: portal.unrestrictedTraverse(brain.getPath())
        generator = SizedGenerator((lookup(brain) for brain in brains),
                                   len(brains))
        return ProgressLogger('Update object security', generator)
Exemple #6
0
    def __call__(self):
        self.info = getUtility(IContactInformation)
        self.user_ids = [user.userid for user in self.info.list_users()]

        catalog = self.getToolByName('portal_catalog')
        brains = catalog.unrestrictedSearchResults(
            portal_type='opengever.document.document')
        with ProgressLogger('Resolve document author', brains) as step:
            for brain in brains:
                self.resolve_document_author(brain)
                step()
    def __call__(self):
        objects = self.catalog_unrestricted_search(
            {'portal_type': 'ftw.mail.mail'}, full_objects=True)

        for mail in ProgressLogger('Migrate mail message filename', objects):
            try:
                mail.update_filename()
            except ConflictError:
                raise
            except Exception, e:
                logger.warn("Updating object {0} failed: {1}".format(
                    mail.absolute_url(), str(e)))
Exemple #8
0
    def reindex_table_searchabletext_in_chapter(self):
        catalog = self.getToolByName('portal_catalog')
        brains = catalog.unrestrictedSearchResults(portal_type='Table')

        title = 'Reindex table searchable text in parent chapter.'
        with ProgressLogger(title, brains) as step:

            for brain in brains:
                obj = self.portal.unrestrictedTraverse(brain.getPath())
                obj.reindexObject(idxs=['SearchableText'])
                parent = aq_parent(aq_inner(obj))
                parent.reindexObject(idxs=['SearchableText'])
                step()
Exemple #9
0
    def update_workflow_states_with_mapping(self):
        status_before_activation = self.wfs_and_states_before
        status_after_activation = self.get_workflows_and_states(
            self.get_objects())

        LOG.info('Changing workflow states of objects which were'
                 ' reset to the initial state according to mapping.')

        portal = getSite()
        wf_tool = getToolByName(portal, 'portal_workflow')
        origin_workflows = list(
            zip(*list(self.review_state_mapping.keys())))[0]

        title = 'Change workflow states'
        for path in ProgressLogger(title, status_before_activation):
            wf_before = status_before_activation[path].get('workflow')
            review_state_before = status_before_activation[path].get(
                'review_state')
            wf_after = status_after_activation[path].get('workflow')

            if wf_before not in origin_workflows:
                # This object has not a workflow which is in the
                # mapping, thus no migration is needed.
                continue

            mapping = self.review_state_mapping.get((wf_before, wf_after), {})
            new_review_state = mapping.get(review_state_before)
            if not new_review_state:
                LOG.warn('Mapping not defined for old state %s when changing'
                         ' workflow from %s to %s.' %
                         (review_state_before, wf_before, wf_after))
                continue

            obj = portal.unrestrictedTraverse(path)

            if self.migrate_workflow_history:
                self._migrate_workflow_history(obj, wf_before, wf_after)
            else:
                wf_tool.setStatusOf(
                    wf_after, obj, {
                        'review_state': new_review_state,
                        'action': 'systemupdate',
                        'actor': 'system',
                        'comments': '',
                        'time': DateTime()
                    })

            if self.update_security:
                update_security_for(obj, reindex_security=True)
                obj.reindexObject(idxs=self.indexes)
    def __call__(self):
        objects = self.catalog_unrestricted_search(
            {'portal_type': 'ftw.mail.mail'}, full_objects=True)

        for mail in ProgressLogger('Initialize ftw.mail caches', objects):
            # initialize attributes (lazy attribute loading)
            mail.Title()

            # initialize cached data
            mail._message = vars(mail).get('message')
            mail._update_attachment_infos()
            mail._reset_header_cache()

            # preserve title, move from 'title' to '_title'
            mail.title = vars(mail).get('title')
Exemple #11
0
    def __call__(self):
        catalog = self.getToolByName('portal_catalog')
        brains = catalog.unrestrictedSearchResults(
            portal_type='opengever.document.document')

        id_normalizer = getUtility(IIDNormalizer)

        with ProgressLogger('Normalize filenames', brains) as step:
            for brain in brains:
                doc = brain.getObject()
                if doc.file:
                    basename, ext = os.path.splitext(doc.file.filename)
                    if basename != id_normalizer.normalize(doc.title):
                        doc.file.filename = ''.join(
                            [id_normalizer.normalize(doc.title), ext])
                step()
    def _update_document_metadata(self):
        """Update the getIcon metadata on documents.
        """
        catalog = api.portal.get_tool('portal_catalog')
        brains = catalog.unrestrictedSearchResults(
            portal_type='opengever.document.document')

        # A getIcon value of 'application.png' indicates that the mimetype
        # coulnd't be resolved for this document - only consider these
        brains = filter(lambda b: b.getIcon == 'application.png', brains)

        msg = 'Reindexing getIcon metadata for documents'
        with ProgressLogger(msg, brains) as step:
            for brain in brains:
                catalog.reindexObject(brain.getObject(),
                                      idxs=['getIcon'],
                                      update_metadata=1)
                step()
Exemple #13
0
    def get_workflows_and_states(self, objects):
        title = 'Get workflows and review states'

        wftool = None
        result = {}
        for obj in ProgressLogger(title, objects):
            if wftool is None:
                wftool = getToolByName(obj, 'portal_workflow')

            path = '/'.join(obj.getPhysicalPath())
            workflow = self._get_workflow_id_for(obj, wftool)
            if workflow:
                review_state = wftool.getInfoFor(obj, 'review_state')
            else:
                review_state = None

            result[path] = {'workflow': workflow, 'review_state': review_state}

        return result
    def __call__(self):
        catalog = api.portal.get_tool('portal_catalog')

        objects = self.catalog_unrestricted_search(
            {'portal_type': 'ftw.mail.mail'}, full_objects=True)

        info = 'Fixing mails with incorrectly decoded text'
        for mail in ProgressLogger(info, objects):
            try:
                need_reindexing = set()
                need_reindexing.update(fix_document_author(mail))
                need_reindexing.update(fix_title(mail))

                if need_reindexing:
                    catalog.reindexObject(mail, idxs=need_reindexing)
            except ConflictError:
                raise
            except Exception, e:
                log.warn("Updating object {0} failed: {1}".format(
                    mail.absolute_url(), str(e)))
 def get_dossiers(self, query, message):
     brains = self.catalog_unrestricted_search(query)
     return ProgressLogger(message, brains)