Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
osqa-to-askbot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gruppo Ask
osqa-to-askbot
Commits
d1d7bf60
Commit
d1d7bf60
authored
Mar 06, 2017
by
Pietro Albini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate questions, answers and comments
Votes are missing though.
parent
d630d700
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
osqa_migrator/migrator.py
osqa_migrator/migrator.py
+105
-0
No files found.
osqa_migrator/migrator.py
View file @
d1d7bf60
...
@@ -50,6 +50,10 @@ class Migrator:
...
@@ -50,6 +50,10 @@ class Migrator:
"""Start the migration process"""
"""Start the migration process"""
self
.
migrate_users
()
self
.
migrate_users
()
self
.
migrate_user_logins
()
self
.
migrate_user_logins
()
self
.
migrate_tags
()
self
.
migrate_nodes
(
"question"
)
self
.
migrate_nodes
(
"answer"
)
self
.
migrate_nodes
(
"comment"
)
def
migrate_users
(
self
):
def
migrate_users
(
self
):
"""Migrate users to Askbot"""
"""Migrate users to Askbot"""
...
@@ -136,3 +140,104 @@ class Migrator:
...
@@ -136,3 +140,104 @@ class Migrator:
# Update the next ID value
# Update the next ID value
self
.
set_next_id
(
"django_authopenid_userassociation"
,
"id"
,
last_id
+
1
)
self
.
set_next_id
(
"django_authopenid_userassociation"
,
"id"
,
last_id
+
1
)
def
migrate_tags
(
self
):
"""Migrate tags"""
existing
=
[
n
[
0
]
for
n
in
self
.
askbot_query
(
"SELECT id FROM tag;"
)]
last_id
=
0
for
tag
in
self
.
osqa
.
table_items
(
"forum_tag"
,
what
=
"tags"
,
order
=
"id"
):
last_id
=
tag
[
"id"
]
if
tag
[
"id"
]
in
existing
:
continue
new
=
self
.
models
.
Tag
()
new
.
id
=
tag
[
"id"
]
new
.
name
=
tag
[
"name"
]
new
.
created_by_id
=
tag
[
"created_by_id"
]
new
.
used_count
=
tag
[
"used_count"
]
new
.
save
()
self
.
set_next_id
(
"tag"
,
"id"
,
last_id
+
1
)
def
migrate_nodes
(
self
,
node
):
"""Migrate questions"""
# Load existing nodes
existing
=
[
n
[
0
]
for
n
in
self
.
askbot_query
(
"SELECT id FROM askbot_post WHERE post_type = %s;"
,
node
)]
existing_threads
=
[
n
[
0
]
for
n
in
self
.
askbot_query
(
"SELECT id FROM askbot_thread;"
,
node
)]
last_id
=
0
last_thread_id
=
0
table
=
"forum_node WHERE node_type = '%s'"
%
node
for
node
in
self
.
osqa
.
table_items
(
table
,
what
=
"%ss"
%
node
,
order
=
"id"
):
last_id
=
node
[
"id"
]
# Check if the node already exists
if
node
[
"id"
]
in
existing
:
continue
author
=
self
.
models
.
User
.
objects
.
get
(
id
=
node
[
"author_id"
])
# If it's a question, create a new thread
if
node
[
"node_type"
]
==
"question"
:
last_thread_id
=
node
[
"id"
]
# Do this only if the thread doesn't exist
if
node
[
"id"
]
not
in
existing_threads
:
thread
=
self
.
models
.
Thread
()
thread
.
id
=
node
[
"id"
]
thread
.
title
=
node
[
"title"
]
last_activity_by
=
node
[
"author_id"
]
if
node
[
"last_activity_by_id"
]:
last_activity_by
=
node
[
"last_activity_by_id"
]
thread
.
last_activity_by_id
=
last_activity_by
thread
.
last_activity_at
=
node
[
"last_activity_at"
]
thread
.
view_count
=
node
[
"extra_count"
]
thread
.
tagnames
=
node
[
"tagnames"
]
thread
.
save
()
# Migrate post data
post
=
self
.
models
.
Post
()
post
.
post_type
=
node
[
"node_type"
]
post
.
id
=
node
[
"id"
]
post
.
author_id
=
node
[
"author_id"
]
post
.
text
=
node
[
"body"
]
post
.
added_at
=
node
[
"added_at"
]
# Attach parents
if
node
[
"parent_id"
]:
post
.
parent_id
=
node
[
"parent_id"
]
if
node
[
"node_type"
]
==
"question"
:
post
.
thread_id
=
node
[
"id"
]
elif
node
[
"node_type"
]
==
"answer"
:
post
.
thread_id
=
node
[
"parent_id"
]
elif
node
[
"node_type"
]
==
"comment"
:
post
.
thread_id
=
self
.
models
.
Post
.
objects
\
.
get
(
id
=
node
[
"parent_id"
])
\
.
thread_id
post
.
save
()
post
.
parse_and_save
(
author
)
# Mark answers as accepted if needed
if
node
[
"marked"
]
and
node
[
"node_type"
]
==
"answer"
:
post
.
thread
.
accepted_answer
=
post
post
.
endorsed
=
True
post
.
endorsed_at
=
self
.
django
.
utils
.
timezone
.
now
()
post
.
thread
.
save
()
post
.
add_revision
(
author
=
author
,
revised_at
=
node
[
"added_at"
],
text
=
node
[
"body"
],
comment
=
""
,
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment