server/tools: migrate files incrementally
This commit is contained in:
parent
b7f2982c9e
commit
247a1e9bbe
1 changed files with 18 additions and 12 deletions
|
@ -123,15 +123,17 @@ def import_users(v1_data_dir, v1_session, v2_session, no_data=False):
|
||||||
}[row['avatarStyle']]
|
}[row['avatarStyle']]
|
||||||
v2_session.add(user)
|
v2_session.add(user)
|
||||||
|
|
||||||
if user.avatar_style == db.User.AVATAR_MANUAL and not no_data:
|
if user.avatar_style == db.User.AVATAR_MANUAL:
|
||||||
source_avatar_path = os.path.join(
|
source_avatar_path = os.path.join(
|
||||||
v1_data_dir, 'public_html', 'data', 'avatars', str(user.user_id))
|
v1_data_dir, 'public_html', 'data', 'avatars', str(user.user_id))
|
||||||
avatar_content = read_file(source_avatar_path)
|
target_avatar_path = 'avatars/' + user.name.lower() + '.png'
|
||||||
image = images.Image(avatar_content)
|
if not no_data and not files.has(target_avatar_path):
|
||||||
image.resize_fill(
|
avatar_content = read_file(source_avatar_path)
|
||||||
int(config.config['thumbnails']['avatar_width']),
|
image = images.Image(avatar_content)
|
||||||
int(config.config['thumbnails']['avatar_height']))
|
image.resize_fill(
|
||||||
files.save('avatars/' + user.name.lower() + '.png', image.to_png())
|
int(config.config['thumbnails']['avatar_width']),
|
||||||
|
int(config.config['thumbnails']['avatar_height']))
|
||||||
|
files.save(target_avatar_path, image.to_png())
|
||||||
counter = exec_scalar(v1_session, 'SELECT MAX(id) FROM users') + 1
|
counter = exec_scalar(v1_session, 'SELECT MAX(id) FROM users') + 1
|
||||||
v2_session.execute('ALTER SEQUENCE user_id_seq RESTART WITH %d' % counter)
|
v2_session.execute('ALTER SEQUENCE user_id_seq RESTART WITH %d' % counter)
|
||||||
v2_session.commit()
|
v2_session.commit()
|
||||||
|
@ -243,12 +245,16 @@ def _import_post_content_for_post(
|
||||||
'data',
|
'data',
|
||||||
'posts',
|
'posts',
|
||||||
row['name'] + '-custom-thumb')
|
row['name'] + '-custom-thumb')
|
||||||
post_content = read_file(source_content_path)
|
target_content_path = posts.get_post_content_path(post)
|
||||||
files.save(posts.get_post_content_path(post), post_content)
|
target_thumb_path = posts.get_post_thumbnail_backup_path(post)
|
||||||
if os.path.exists(source_thumb_path):
|
if not files.has(target_content_path):
|
||||||
|
post_content = read_file(source_content_path)
|
||||||
|
files.save(target_content_path, post_content)
|
||||||
|
if os.path.exists(source_thumb_path) and not files.has(target_thumb_path):
|
||||||
thumb_content = read_file(source_thumb_path)
|
thumb_content = read_file(source_thumb_path)
|
||||||
files.save(posts.get_post_thumbnail_backup_path(post), thumb_content)
|
files.save(target_thumb_path, thumb_content)
|
||||||
posts.generate_post_thumbnail(post)
|
if not files.has(posts.get_post_thumbnail_path(post)):
|
||||||
|
posts.generate_post_thumbnail(post)
|
||||||
|
|
||||||
def import_post_content(unused_post_ids, v1_data_dir, v1_session, v2_session):
|
def import_post_content(unused_post_ids, v1_data_dir, v1_session, v2_session):
|
||||||
rows = list(exec_query(v1_session, 'SELECT * FROM posts'))
|
rows = list(exec_query(v1_session, 'SELECT * FROM posts'))
|
||||||
|
|
Loading…
Reference in a new issue