def update(user):

    phab = Phabricator(config.phab_user,
                       config.phab_cert,
                       config.phab_host)

    pmig = phabdb.phdb(db=config.rtmigrate_db,
                       user=config.rtmigrate_user,
                       passwd=config.rtmigrate_passwd)

    phabm = phabmacros('', '', '')
    phabm.con = phab

    if phabdb.is_bot(user['userphid']):
        log("%s is a bot no action" % (user['user']))
        return True

    epriority = phabdb.get_user_relations_comments_priority(user['user'],
                                                            pmig)
    if epriority and len(epriority[0]) > 0:
        if epriority[0][0] == ipriority['update_success_comments']:
            log('Skipping %s as already updated' % (user['user']))
            return True

    if not user['issues']:
        log("%s has no issues to update" % (user['user'],))
        return True

    for i in user['issues']:
        comdetails = pmig.sql_x("SELECT comments, \
                                        xcomments \
                                        FROM rt_meta \
                                        WHERE id = %s", (int(i),))
        jcom, jxcom = comdetails[0]
        coms = json.loads(jcom)
        xcoms = json.loads(jxcom)

        for key, xi in xcoms.iteritems():
            content = xi['content']
            if xi["creator"] == user['user']:
                log("Updating comment %s for %s" % (xi['xctransaction'], user['user']))
                phabdb.set_comment_author(xi['xctransaction'], user['userphid'])
                phabdb.set_comment_content(xi['xctransaction'], xi['content'])

    current = phabdb.get_user_migration_comment_history(user['user'],
                                                        pmig)
    if current:
        success = ipriority['update_success_comments']
        log(phabdb.set_user_relations_comments_priority(success,
                                                        user['user'],
                                                        pmig))
    else:
        log('%s user does not exist to update' % (user['user']))
        return False
    pmig.close()
    log(util.purge_cache())
    return True
        phabdb.set_task_id(issue.id, phid)
        id = issue.id
    else:
        id = new_task['id']

    if config.have_db_access:
        if author_phid:
            phabdb.set_task_author(author_phid, id)
        phabdb.set_task_ctime(phid, issue.created_at.strftime("%s"))
        phabdb.set_task_mtime(phid, issue.updated_at.strftime("%s"))

    if issue.state != "open":
        api.set_status(id, "resolved")
        if config.have_db_access:
            if issue.closed_at:
                tphid = phabdb.last_state_change(phid)
                phabdb.set_transaction_time(tphid, issue.closed_at.strftime("%s"))
    for (author, date, comment) in issue.comments:
        print "Adding comment from %s" % author
        author_phid = api.get_phid_by_username(author)
        if author_phid is None or config.have_db_access is False:
            comment = "> Comment originally made by **%s** on //%s//\n\n%s" % (author, date, comment)
        api.task_comment(id, comment)
        if config.have_db_access:
            tphid = phabdb.last_comment(phid)
            phabdb.set_comment_time(tphid, date.strftime("%s"))
            if author_phid:
                phabdb.set_comment_author(tphid, author_phid)

util.purge_cache()
Esempio n. 3
0
    else:
        id = new_task['id']

    if config.have_db_access:
        if author_phid:
            phabdb.set_task_author(author_phid, id)
        phabdb.set_task_ctime(phid, issue.created_at.strftime("%s"))
        phabdb.set_task_mtime(phid, issue.updated_at.strftime("%s"))

    if issue.state != "open":
        api.set_status(id, "resolved")
        if config.have_db_access:
            if issue.closed_at:
                tphid = phabdb.last_state_change(phid)
                phabdb.set_transaction_time(tphid,
                                            issue.closed_at.strftime("%s"))
    for (author, date, comment) in issue.comments:
        print "Adding comment from %s" % author
        author_phid = api.get_phid_by_username(author)
        if author_phid is None or config.have_db_access is False:
            comment = "> Comment originaly made by **%s** on //%s//\n\n%s" % (
                author, date, comment)
        api.task_comment(id, comment)
        if config.have_db_access:
            tphid = phabdb.last_comment(phid)
            phabdb.set_comment_time(tphid, date.strftime("%s"))
            if author_phid:
                phabdb.set_comment_author(tphid, author_phid)

util.purge_cache()