From: Andrew V. <av...@us...> - 2005-03-31 10:04:14
|
Update of /cvsroot/mailmanager/mailmanager/migration In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24537/migration Modified Files: Tag: db-backend MailManager.py Log Message: Basic migration is now working. Some issues with dates still and character encoding. Index: MailManager.py =================================================================== RCS file: /cvsroot/mailmanager/mailmanager/migration/MailManager.py,v retrieving revision 1.23.2.3 retrieving revision 1.23.2.4 diff -u -d -r1.23.2.3 -r1.23.2.4 --- MailManager.py 30 Mar 2005 12:00:49 -0000 1.23.2.3 +++ MailManager.py 31 Mar 2005 10:03:00 -0000 1.23.2.4 @@ -7,7 +7,11 @@ __version__ = '$Revision$' +from Products.MailManager.utility import addZSQLMethods +from Products.FileSystemSite.DirectoryView import manage_addDirectoryView import zLOG +import os +from psycopg import Binary def migrate(self): """Upgrade a MailManager instance to the current version. @@ -18,10 +22,16 @@ Note that some of the existing ZODB objects will stay (such as categories and filters) as they are not to be migrated. """ - from Products.MailManager import MailManager + + # Add the sql methods + manage_addDirectoryView(self, os.path.join('MailManager', 'sql')) + addZSQLMethods(self) + + # Set the schema to blank - this will use the default schema + self.schema = '' # Migrate the users first - for username, dict in self.agent.items(): + for username, dict in self.agents.items(): user = self.acl_users.getUser(username) roles = user.getRoles() self.sql.addUser(username=username, @@ -35,24 +45,64 @@ # Now the accounts for account in self.accounts.objectValues(): + print 'Migrating Account %s' % account.id self.sql.addAccount(email=account.id, - assign_user=account.assign_user, - assign_group=account.assign_group, - notify_user=account.notify_agent, + assign_user=account.assign_user or '', + assign_group=account.assign_group or '', + notify_user=str(bool(account.notify_agent)), mail_server=account.mail_server, + mail_username=account.mail_username, + mail_password=account.mail_password, + server_type=account.mailtype, default_priority=account.default_priority, - default_category0=account.default_category0, - default_category1=account.default_category1, - default_category2=account.default_category2) + default_category0=account.default_category0 or '', + default_category1=account.default_category1 or '', + default_category2=account.default_category2 or '') # And the tickets for each account for ticket in account.objectValues(): + print 'Migrating Ticket %s' % ticket.id self.sql.addTicket(id=ticket.id, - subject=ticket.title, - assigned=ticket.getOwner(1)[1], + subject=ticket.title or '', + from_name=ticket.from_name, + from_email=ticket.from_email, + assigned=ticket.getOwnerTuple()[1], status=ticket.status, priority=ticket.priority, - category0=ticket.category0, - category1=ticket.category1, - category2=ticket.category2) + category0=ticket.category0 or '', + category1=ticket.category1 or '', + category2=ticket.category2 or '', + unread=str(bool(ticket.unread)), + date_opened=ticket.date_opened) + # Now messages in each ticket + for message in ticket.objectValues(): + id = self.sql.getNextMessageId()[0].id + self.sql.addMessage(id=id, + ticket_id=ticket.id, + message_id=message.get('message-id'), + from_name=message.from_name, + subject=message.title, + body=message.body, + body_charset=message._body_charset, + html_body=message.html_body)) + # And finally the attachments in the messages + for attach in message.objectValues(): + self.sql.addAttachment(message_id=id, + title=attach.title, + content_type=attach.getContentType(), + is_file=attach.isfile, + body=Binary(attach.manage_FTPget()), + dangerous='False') + # Ticket history + for hist in ticket.history: + self.sql.addHistory(ticket_id=ticket.id, + subject=hist.get('subject', ''), + assigned=hist.get('assigned', ''), + status=hist.get('status', ''), + priority=hist.get('priority', 0), + category0=hist.get('category0', ''), + category1=hist.get('category1', ''), + category2=hist.get('category2', ''), + changed_by=hist.get('by', '')) + # Need date here too return self.manage_main(self) |