class IdMapper(dict):\r
def __getitem__(self, key):\r
key = int(key)\r
- return super(IdMapper, self).get(key, key)\r
+ return super(IdMapper, self).get(key, 1)\r
\r
def __setitem__(self, key, value):\r
super(IdMapper, self).__setitem__(int(key), int(value))\r
username = sxu.get('displayname', sxu.get('displaynamecleaned', sxu.get('realname', UnknownUser())))\r
\r
if not isinstance(username, UnknownUser) and username in user_by_name:\r
- if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:\r
- osqau = user_by_name[username]\r
- create = False\r
- uidmapper[sxu.get('id')] = osqau.id\r
- else:\r
- inc = 1\r
- while ("%s %d" % (username, inc)) in user_by_name:\r
- inc += 1\r
+ #if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:\r
+ # osqau = user_by_name[username]\r
+ # create = False\r
+ # uidmapper[sxu.get('id')] = osqau.id\r
+ #else:\r
+ inc = 1\r
+ while ("%s %d" % (username, inc)) in user_by_name:\r
+ inc += 1\r
\r
- username = "%s %d" % (username, inc)\r
+ username = "%s %d" % (username, inc)\r
\r
sxbadges = sxu.get('badgesummary', None)\r
badges = {'1':'0','2':'0','3':'0'}\r
\r
osqau.save()\r
\r
- s = orm.SubscriptionSettings(user=osqau)\r
- s.save()\r
+ try:\r
+ orm.SubscriptionSettings.objects.get(user=osqau)\r
+ except:\r
+ s = orm.SubscriptionSettings(user=osqau)\r
+ s.save()\r
\r
- user_by_name[osqau.username] = osqau\r
+ uidmapper[osqau.id] = osqau.id\r
else:\r
new_about = sxu.get('aboutme', None)\r
if new_about and osqau.about != new_about:\r
merged_users.append(osqau.id)\r
osqau.save()\r
\r
+ user_by_name[osqau.username] = osqau\r
\r
openid = sxu.get('openid', None)\r
if openid and openidre.match(openid):\r
\r
def postimport(dump, uidmap, tagmap):\r
history = {}\r
+ accepted = {}\r
all = {}\r
\r
for h in readTable(dump, "PostHistory"):\r
posts = readTable(dump, "Posts")\r
\r
for sxpost in posts:\r
- accepted = {}\r
-\r
postclass = sxpost.get('posttypeid') == '1' and orm.Question or orm.Answer\r
\r
post = postclass(\r
post.closed_at = datetime.now()\r
\r
if sxpost.get('acceptedanswerid', None):\r
+ post.accepted_answer_id = int(sxpost.get('acceptedanswerid'))\r
accepted[int(sxpost.get('acceptedanswerid'))] = post\r
\r
else:\r
post.parent_id = sxpost['parentid']\r
\r
if int(post.id) in accepted:\r
- question = accepted[int(post.id)]\r
- question.accepted_answer_id = post\r
- question.save()\r
-\r
post.accepted = True\r
post.accepted_at = datetime.now()\r
- post.accepted_by_id = question.author_id\r
+ post.accepted_by_id = accepted[int(post.id)].author_id\r
\r
all[int(post.id)] = post\r
\r
id = currid,\r
node_type = "comment",\r
added_at = readTime(sxc['creationdate']),\r
- author_id = uidmap[sxc['userid']],\r
+ author_id = uidmap[sxc.get('userid', 1)],\r
body = sxc['text'],\r
parent_id = sxc.get('postid'),\r
vote_up_count = 0,\r
oc.deleted_by_id = uidmap[sxc['deletionuserid']]\r
oc.author_id = uidmap[sxc['deletionuserid']]\r
else:\r
- oc.author_id = uidmap[sxc['userid']]\r
+ oc.author_id = uidmap[sxc.get('userid', 1)]\r
\r
\r
posts[oc.id] = oc\r
\r
\r
PG_SEQUENCE_RESETS = """\r
+SELECT setval('"auth_user_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user";\r
SELECT setval('"auth_user_groups_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_groups";\r
SELECT setval('"auth_user_user_permissions_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_user_permissions";\r
SELECT setval('"activity_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "activity";\r