Changeset 1724

Show
Ignore:
Timestamp:
12/21/06 00:05:00 (2 years ago)
Author:
codeFiend
Message:

MantisImportScript:

* modified to prepopulate the session/session_attribute tables with mantis userinfo
* couple of minor typo fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mantisimportscript/mantis2trac.py

    r1721 r1724  
    425425        c.execute("""INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) 
    426426                                 VALUES        (%s, %s, %s, %s, %s, %s)""", 
    427                   (ticket, time.strftime('%s'), author, 'comment', '', comment,)) 
     427                  (ticket, time.strftime('%s'), author, 'comment', '', comment)) 
    428428        self.db().commit() 
    429429 
     
    433433        c.execute("""INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) 
    434434                                 VALUES        (%s, %s, %s, %s, %s, %s)""", 
    435                   (ticket, time.strftime('%s'), author, field, oldvalue.encode('utf-8'), newvalue.encode('utf-8'),)) 
     435                  (ticket, time.strftime('%s'), author, field, oldvalue.encode('utf-8'), newvalue.encode('utf-8'))) 
    436436        self.db().commit() 
    437437        # Now actually change the ticket because the ticket wont update itself! 
     
    449449    def getLoginName(self, cursor, userid): 
    450450        if userid not in self.loginNameCache: 
    451             cursor.execute("SELECT * FROM mantis_user_table WHERE id = %i" % int(userid)) 
    452             loginName = cursor.fetchall() 
    453  
    454             if loginName: 
    455                 loginName = loginName[0]['username'] 
     451            cursor.execute("SELECT username,email,realname,last_visit FROM mantis_user_table WHERE id = %i" % int(userid)) 
     452            result = cursor.fetchall() 
     453 
     454            if result: 
     455                loginName = result[0]['username'] 
     456                print 'Adding user %s to sessions table' % loginName 
     457                c = self.db().cursor() 
     458 
     459                # pre-populate the session table and the realname/email table with user data 
     460                try: 
     461                    c.execute( 
     462                    """INSERT IGNORE INTO session  
     463                        (sid, authenticated, last_visit)  
     464                    VALUES 
     465                        (%s, 1, %s)""",(result[0]['username'].encode('utf-8'), result[0]['last_visit'].strftime('%s'))) 
     466                except: 
     467                    print 'could not insert %s into sessions table: sql error %s ' % loginName, self.db().error() 
     468                self.db().commit() 
     469                c.execute( 
     470                    """INSERT IGNORE INTO session_attribute  
     471                        (sid, authenticated, name, value) 
     472                    VALUES 
     473                        (%s, %s, %s, %s), (%s, %s, %s, %s)""", 
     474                        (result[0]['username'].encode('utf-8'), '1', 'name', result[0]['realname'].encode('utf-8'),  
     475                        result[0]['username'].encode('utf-8'), '1', 'email', result[0]['email'].encode('utf-8'))) 
     476                self.db().commit() 
    456477            else: 
    457478                print 'warning: unknown mantis userid %d, recording as anonymous' % userid 
     
    555576    components = mysql_cur.fetchall() 
    556577    for component in components: 
    557             component['owner'] = trac.getLoginName(mysql_cur, component['owner']) 
     578        component['owner'] = trac.getLoginName(mysql_cur, component['owner']) 
    558579    trac.setComponentList(components, 'category') 
    559580