-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.py
77 lines (57 loc) · 2.21 KB
/
restore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import db_interface
back_db = db_interface.DbInterface('host', 'username', 'password', 'forum')
live_db = db_interface.DbInterface('host', 'username', 'password', 'forum')
user_id = 483941
def re_insert_post_by_id(db_back, db_live, post_id):
# Make sure post wasn't added while adding a thread back
post_check = db_live.get_post_by_id(post_id)
if post_check:
return
# Get original post
post = db_back.get_post_by_id(post_id)
# If the position is 0, means it's a thread starter
if post.position == 0:
re_insert_thread_by_id(db_back, db_live, post.thread_id)
return
# insert post
db_live.insert_post(post)
print 'Inserted post '
# bump thread's reply count
thread = db_live.get_thread_by_id(post.thread_id)
if thread:
thread.bump_reply_count()
db_live.update_thread(thread)
print 'Updated thread '
thread_posts = db_live.get_posts_by_thread_id(post.thread_id)
for (thread_post) in thread_posts:
if thread_post.post_date > post.post_date:
thread_post.bump_position()
db_live.update_post(thread_post)
print 'Bumped posts position'
# handle attachments
attachments = db_back.get_attachments_for_post_id(post.post_id)
for (attachment) in attachments:
db_live.insert_attachment(attachment)
print 'Inserted attachment'
def re_insert_thread_by_id(db_back, db_live, thread_id):
# get original thread
original_thread = db_back.get_thread_by_id(thread_id)
original_posts = db_back.get_posts_by_thread_id(thread_id)
# re-insert them
db_live.insert_thread(original_thread)
print 'Inserted thread'
for (post) in original_posts:
db_live.insert_post(post)
print 'Inserted post'
# handle attachments
attachments = db_back.get_attachments_for_post_id(post.post_id)
for (attachment) in attachments:
db_live.insert_attachment(attachment)
print 'Inserted attachment'
post_ids = back_db.get_post_ids_by_user_id(user_id)
for (post_id) in post_ids:
post_id = post_id[0]
print 'Post id: ' + str(post_id)
re_insert_post_by_id(back_db, live_db, post_id)
back_db.db.close()
live_db.db.close()