def __call__(self): """ Check values in the request, and make the right action """ if 'form.button.Cancel' in self.request.form.keys(): return self.doReturn( _("migration_error_cancel", default=u"Migration canceled."), 'info') if not 'form.button.Migrate' in self.request.form.keys(): return self.index() if not self.request.form.get( 'src_type', '') and not self.request.form.get('dst_type', ''): return self.doReturn( _("migration_error_validation", default=u"You need to fill both required fields."), 'error') migration = self.doMigration() if migration: return self.doReturn( _("migration_done_msg", default=u"Migration done."), 'info') else: return self.doReturn( _("migration_error_msg", default= u"Errors in migration process. See the log for more infos."), 'error')
def __call__(self): """ Check values in the request, and make the right action """ if 'form.button.Cancel' in self.request.form.keys(): return self.doReturn(_("migration_error_cancel", default=u"Migration canceled."), 'info') if not 'form.button.Migrate' in self.request.form.keys(): return self.index() errors = {} options = {} for field in REQUIRED_FIELDS: if not self.request.form.get(field, ''): errors[field] = True errors.update(self.validateQuery()) if errors: self.addPortalMessage(_("migration_form_errors", default=u"There was some errors. Check the fields."), "error") options['errors'] = errors return self.index(**options) migration = self.doMigration() if migration: return self.doReturn(_("migration_done_msg", default=u"Migration done."), 'info') else: return self.doReturn(_("migration_error_msg", default=u"Errors in migration process. See the log for more infos."), 'error')
def doMigration(self): """ handle migration from a portal_type to anther, and log all outputs given """ src_type = self.request.form.get('src_type', '') dst_type = self.request.form.get('dst_type', '') src_metatype = self.request.form.get('src_metatype', '') dst_metatype = self.request.form.get('dst_metatype', '') query = self.makeQuery() logger.info("*********** Migration start ***********") output = migrateContents(self.context, src_type, dst_type, src_metatype, dst_metatype, query) pu = getToolByName(self.context, "plone_utils") pu.addPortalMessage(_("Migration from ${src_type} to ${dst_type}: found ${results} items.", mapping={u"src_type": src_type, "dst_type": dst_type, "results": output.get('counter', '')}), 'info') for m in output.get('msg', []): logger.info(m) logger.info("*********** Migration done ***********") if output.get('error', []): for error in output.get('error', []): pu.addPortalMessage(error.get('msg', ''), 'error') return False return True
def doMigration(self): """ handle migration from a portal_type to anther, and log all outputs given """ portal_path = '/'.join(self.context.getPhysicalPath()) src_type = self.request.form.get('src_type', '') dst_type = self.request.form.get('dst_type', '') folder_path = self.request.form.get('folder_path', portal_path) if folder_path and (not folder_path.startswith(portal_path)): folder_path = (folder_path[0] == '/') \ and portal_path + folder_path \ or portal_path + '/' + folder_path logger.info("*********** Migration start ***********") output = migrateContents(self.context, src_type, dst_type, query={'path': folder_path}) pu = getToolByName(self.context, "plone_utils") pu.addPortalMessage( _("Migration from ${src_type} to ${dst_type}: found ${results} items.", mapping={ u"src_type": src_type, "dst_type": dst_type, "results": output.get('counter', '') }), 'info') for m in output.get('msg', []): logger.info(m) logger.info("*********** Migration done ***********") if output.get('error', []): for error in output.get('error', []): pu.addPortalMessage(error.get('msg', ''), 'error') return False return True