def remap_views(self): maps = self.view_maps if not maps: return views_i = {"FieldIndex": ['getLayout', 'default_page']} context = self.context catalog = self.context.portal_catalog setup_catalog( self.context, indexes=views_i, metadatas=[], ) upgrades.commit(context) try: for view in maps.keys(): brains = catalog.search({'getLayout': view}) for brain in brains: log( 'Changing view: %s %s->%s' % ( brain.getPath(), view, maps[view] )) try: obj = brain.getObject() obj.setLayout(maps[view]) catalog.reindexObject(obj, ['getLayout']) except Exception, e: log('Cant change layout: %s (%s)' % ( brain.getPath(), e)) continue catalog.uniqueValuesFor('getLayout') upgrades.commit(context)
def postupgrade(self): """Mark products as correctly installed by the quickinstaller""" upgrades.log('postupgrade') context = self.context upgrades.quickinstall_addons( self.context, self.products, [], upgrades=self.upproducts) upgrades.commit(context)
def delete_broken(self, not_deleted=None): if not_deleted is None: not_deleted = [] catalog = getToolByName(self.context, 'portal_catalog') uid_catalog = getToolByName(self.context, 'uid_catalog') ref_catalog = getToolByName(self.context, 'reference_catalog') not_deleted = [] notstop = True while notstop: objects, brokens = self.get_allobjs() for path in brokens: if ( not self.delete_path(path) and (not path in not_deleted) ): not_deleted.append(path) objects2, broken2 = self.get_allobjs() if not len(broken2) < len(brokens): notstop = False else: upgrades.log('Another pass to delete items') if len(broken2): catalog.refreshCatalog(clear=1) uid_catalog.refreshCatalog(clear=1) ref_catalog.refreshCatalog(clear=1) upgrades.commit(self.context)
def rebuild_catalog(self): context = self.context upgrades.upgrade_plone(context) catalog = getToolByName(self.context, 'portal_catalog') upgrades.log('Recataloging items') brains = catalog.search({}) lb = len(brains) for i, itm in enumerate(brains): try: obj = context.unrestrictedTraverse(itm.getPath()) uid = '/'.join(obj.getPhysicalPath()) if not uid in catalog._catalog.uids: catalog.catalog_object(obj) catalog.indexObject(obj) # let the objects be wrapped now by plone.indexer if IIndexableObject.providedBy(obj): interface.noLongerProvides(obj, IIndexableObject) catalog.reindexObject(obj, [ "allowedRolesAndUsers", "object_provides", "sortable_title", "getObjPositionInParent", "getObjSize", "is_folderish", "syndication_enabled", "is_default_page", "getIcon"] ) except Exception, e: upgrades.log('pb cataloging %s; %s' % (itm.getPath(), e)) if i % 10 == 0: upgrades.log('Recatalog: %s on %s (%s %s)' % ( i, lb, (i / (1.0 * lb) * 100), '%')) upgrades.commit(context)
def migrate_fileTestCgwb_to_blob(self): upgrades.log('Migrating FileTestCgwb to blob') walker = CustomQueryWalker(self.context, FileTestCgwbMigrator, full_transaction=True) walker.go() upgrades.commit(self.context)
def remap_views(self): maps = self.view_maps if not maps: return views_i = {"FieldIndex": ['getLayout', 'default_page']} context = self.context catalog = self.context.portal_catalog setup_catalog( self.context, indexes=views_i, metadatas=[], ) upgrades.commit(context) try: for view in maps.keys(): brains = catalog.search({'getLayout': view}) for brain in brains: log('Changing view: %s %s->%s' % (brain.getPath(), view, maps[view])) try: obj = brain.getObject() obj.setLayout(maps[view]) catalog.reindexObject(obj, ['getLayout']) except Exception, e: log('Cant change layout: %s (%s)' % (brain.getPath(), e)) continue catalog.uniqueValuesFor('getLayout') upgrades.commit(context)
def rebuild_catalog(self): context = self.context upgrades.upgrade_plone(context) catalog = getToolByName(self.context, 'portal_catalog') upgrades.log('Recataloging items') brains = catalog.search({}) lb = len(brains) for i, itm in enumerate(brains): try: obj = context.unrestrictedTraverse(itm.getPath()) uid = '/'.join(obj.getPhysicalPath()) if not uid in catalog._catalog.uids: catalog.catalog_object(obj) catalog.indexObject(obj) # let the objects be wrapped now by plone.indexer if IIndexableObject.providedBy(obj): interface.noLongerProvides(obj, IIndexableObject) catalog.reindexObject(obj, [ "allowedRolesAndUsers", "object_provides", "sortable_title", "getObjPositionInParent", "getObjSize", "is_folderish", "syndication_enabled", "is_default_page", "getIcon" ]) except Exception, e: upgrades.log('pb cataloging %s; %s' % (itm.getPath(), e)) if i % 10 == 0: upgrades.log('Recatalog: %s on %s (%s %s)' % (i, lb, (i / (1.0 * lb) * 100), '%')) upgrades.commit(context)
def postupgrade(self): """Mark products as correctly installed by the quickinstaller""" upgrades.log('postupgrade') context = self.context upgrades.quickinstall_addons(self.context, self.products, [], upgrades=self.upproducts) upgrades.commit(context)
def migrate_btrees(self): """ https://dev.plone.org/ticket/9912 """ upgrades.log('Migrating to BTrees') ret = BTreeMigrationView(self.context, self.request)() upgrades.commit(self.context) return ret
def to_blob(self): portal_setup = getToolByName(self.context, 'portal_setup') upgrade_dcmi_metadata(portal_setup) portal_setup.runAllImportStepsFromProfile( 'profile-plone.app.registry:default') portal_setup.runAllImportStepsFromProfile( 'profile-plone.app.blob:default') upgrades.commit(self.context)
def migrate_fileTestCgwb_to_blob(self): upgrades.log('Migrating FileTestCgwb to blob') walker = CustomQueryWalker( self.context, FileTestCgwbMigrator, full_transaction=True) walker.go() upgrades.commit(self.context)
def to_blob_f(self): """To avoid conflicts during the plonemigration loop, run the blob migration now""" portal = getToolByName(self.context, 'portal_url').getPortalObject() migrator = FMigrator walker = CustomQueryWalker(portal, migrator, full_transaction=True) upgrades.log('Migrating files to blob') walker.go() upgrades.commit(self.context)
def upgrade_plone(self): """Run the plone_migration tool upgrade loop""" pm = getToolByName(self.context, 'portal_migration') if pm.needUpgrading(): upgrades.log(upgrades.upgrade_plone(self.context)) upgrades.commit(self.context) if pm.needUpgrading(): raise Exception("Plone did not upgrade") else: upgrades.commit(self.context)
def totinymce(self): log('Migrating to tinymce') context = self.context acl_users = getToolByName(self.context, 'acl_users') users = acl_users.getUserNames() portal_membership = getToolByName(self.context, 'portal_membership') for user in users + ['admin']: member = portal_membership.getMemberById(user) log('Tinymce editor for %s' % user) member.wysiwyg_editor = "TinyMCE" member.setMemberProperties({'wysiwyg_editor': 'TinyMCE'}) upgrades.commit(context)
def move_custom(self): """Wipe out the portal_skins/custom CMF layer content""" upgrades.move_custom(self.context, ignores=[ 'logo_intra.jpg', 'global_logo', 'portlet_', 'list_emails', 'find_by_mail', 'list_subscriptions', ]) upgrades.commit(self.context)
def upgrade_plone(self): """Run the plone_migration tool upgrade loop""" pm = getToolByName(self.context, 'portal_migration') if pm.needUpgrading(): upgrades.log( upgrades.upgrade_plone(self.context) ) upgrades.commit(self.context) if pm.needUpgrading(): raise Exception("Plone did not upgrade") else: upgrades.commit(self.context)
def move_custom(self): """Wipe out the portal_skins/custom CMF layer content""" upgrades.move_custom( self.context, ignores=[ 'logo_intra.jpg', 'global_logo', 'portlet_', 'list_emails', 'find_by_mail', 'list_subscriptions', ]) upgrades.commit(self.context)
def remove_cachefu(self): """Remove cache fu (done often too late in plonemigration)""" alphas.removeBrokenCacheFu(self.context) knowns = [ self.path + '/portal_cache_settings', self.path + '/portal_squid', self.path + '/CacheSetup_PageCache', self.path + '/caching_policy_manager', self.path + '/HTTPCache', self.path + '/CacheSetup_OFSCache', self.path + '/CacheSetup_ResourceRegistryCache', ] upgrades.commit(self.context) not_deleted = [] for path in knowns: if (not self.delete_path(path) and (not path in not_deleted)): not_deleted.append(path) manage_addCachingPolicyManager(self.context) addCacheHandlers(self.context) addCacheForResourceRegistry(self.context)
def migrate_description(self): catalog = self.context.portal_catalog portal_transforms = getToolByName(self.context, 'portal_transforms') upgrades.log('Migrating html description to text') reindex = [] for itm in catalog.search({}): obj = itm.getObject() desc = obj.getField('description').getRaw(obj) schema = obj.Schema() if desc: indexes = [] data = portal_transforms.convert( 'html_to_text', desc ).getData() if data != desc: obj.getField('description').set(obj, data) indexes.append('description') if 'text' in schema.keys(): text = obj.getField('text').getRaw(obj) p = '<p> </p>' if text: nval = ('%s\n' '%s\n' '%s\n' '%s\n' '%s') % ( desc, p, p, p, text) else: nval = desc obj.getField('text').set(obj, nval) indexes.append('text') # postpone the index to a later step if indexes: reindex.append((obj, indexes)) self.migrate_reindexdescription(reindex) upgrades.log( 'Migrating html description to text: finished') upgrades.commit(self.context)
def delete_broken(self, not_deleted=None): if not_deleted is None: not_deleted = [] catalog = getToolByName(self.context, 'portal_catalog') uid_catalog = getToolByName(self.context, 'uid_catalog') ref_catalog = getToolByName(self.context, 'reference_catalog') not_deleted = [] notstop = True while notstop: objects, brokens = self.get_allobjs() for path in brokens: if (not self.delete_path(path) and (not path in not_deleted)): not_deleted.append(path) objects2, broken2 = self.get_allobjs() if not len(broken2) < len(brokens): notstop = False else: upgrades.log('Another pass to delete items') if len(broken2): catalog.refreshCatalog(clear=1) uid_catalog.refreshCatalog(clear=1) ref_catalog.refreshCatalog(clear=1) upgrades.commit(self.context)
def remove_cachefu(self): """Remove cache fu (done often too late in plonemigration)""" alphas.removeBrokenCacheFu(self.context) knowns = [ self.path + '/portal_cache_settings', self.path + '/portal_squid', self.path + '/CacheSetup_PageCache', self.path + '/caching_policy_manager', self.path + '/HTTPCache', self.path + '/CacheSetup_OFSCache', self.path + '/CacheSetup_ResourceRegistryCache', ] upgrades.commit(self.context) not_deleted = [] for path in knowns: if ( not self.delete_path(path) and (not path in not_deleted) ): not_deleted.append(path) manage_addCachingPolicyManager(self.context) addCacheHandlers(self.context) addCacheForResourceRegistry(self.context)
def migrate_description(self): catalog = self.context.portal_catalog portal_transforms = getToolByName(self.context, 'portal_transforms') upgrades.log('Migrating html description to text') reindex = [] for itm in catalog.search({}): obj = itm.getObject() desc = obj.getField('description').getRaw(obj) schema = obj.Schema() if desc: indexes = [] data = portal_transforms.convert('html_to_text', desc).getData() if data != desc: obj.getField('description').set(obj, data) indexes.append('description') if 'text' in schema.keys(): text = obj.getField('text').getRaw(obj) p = '<p> </p>' if text: nval = ('%s\n' '%s\n' '%s\n' '%s\n' '%s') % (desc, p, p, p, text) else: nval = desc obj.getField('text').set(obj, nval) indexes.append('text') # postpone the index to a later step if indexes: reindex.append((obj, indexes)) self.migrate_reindexdescription(reindex) upgrades.log('Migrating html description to text: finished') upgrades.commit(self.context)
def doStep(self, tool): ctx = getToolByName(tool, 'portal_url').getPortalObject() ret = getattr(self, '_oldm_doStep')(tool) upgrades.commit(ctx) return ret
def pack(self): upgrades.log('Packing database') upgrades.commit(self.context) self.context._p_jar._db.pack()
def cleanup_profile(self): ps = getToolByName(self.context, 'portal_setup') cleanup_profile = 'profile-%s:cleanup' % PRODUCT if ps.profileExists(cleanup_profile): ps.runAllImportStepsFromProfile(cleanup_profile) upgrades.commit(self.context)
def remove_ttw(self): context = self.context ttw = getToolByName(context, 'portal_view_customizations') [ttw.manage_delObjects(a) for a in ttw.objectIds()] upgrades.commit(context)
def mark_migrated(context, step_id): value = migration_infos(context) value[step_id] = True upgrades.commit(context)
obj.setLayout(maps[view]) catalog.reindexObject(obj, ['getLayout']) except Exception, e: log('Cant change layout: %s (%s)' % ( brain.getPath(), e)) continue catalog.uniqueValuesFor('getLayout') upgrades.commit(context) finally: setup_catalog( self.context, indexes=[], metadatas=[], remove_indexes=views_i["FieldIndex"], remove_metadatas=views_i["FieldIndex"], ) upgrades.commit(context) @onlyonce def postupgrade(self): """Mark products as correctly installed by the quickinstaller""" upgrades.log('postupgrade') context = self.context upgrades.quickinstall_addons( self.context, self.products, [], upgrades=self.upproducts) upgrades.commit(context) @onlyonce def rebuild_catalog(self): context = self.context upgrades.upgrade_plone(context) catalog = getToolByName(self.context, 'portal_catalog')
catalog.reindexObject(obj, ['getLayout']) except Exception, e: log('Cant change layout: %s (%s)' % (brain.getPath(), e)) continue catalog.uniqueValuesFor('getLayout') upgrades.commit(context) finally: setup_catalog( self.context, indexes=[], metadatas=[], remove_indexes=views_i["FieldIndex"], remove_metadatas=views_i["FieldIndex"], ) upgrades.commit(context) @onlyonce def postupgrade(self): """Mark products as correctly installed by the quickinstaller""" upgrades.log('postupgrade') context = self.context upgrades.quickinstall_addons(self.context, self.products, [], upgrades=self.upproducts) upgrades.commit(context) @onlyonce def rebuild_catalog(self): context = self.context upgrades.upgrade_plone(context)