server/tools: migrate files incrementally

This commit is contained in:
rr- 2016-07-17 21:06:24 +02:00
parent b7f2982c9e
commit 247a1e9bbe

View file

@ -123,15 +123,17 @@ def import_users(v1_data_dir, v1_session, v2_session, no_data=False):
}[row['avatarStyle']]
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(
v1_data_dir, 'public_html', 'data', 'avatars', str(user.user_id))
target_avatar_path = 'avatars/' + user.name.lower() + '.png'
if not no_data and not files.has(target_avatar_path):
avatar_content = read_file(source_avatar_path)
image = images.Image(avatar_content)
image.resize_fill(
int(config.config['thumbnails']['avatar_width']),
int(config.config['thumbnails']['avatar_height']))
files.save('avatars/' + user.name.lower() + '.png', image.to_png())
files.save(target_avatar_path, image.to_png())
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.commit()
@ -243,11 +245,15 @@ def _import_post_content_for_post(
'data',
'posts',
row['name'] + '-custom-thumb')
target_content_path = posts.get_post_content_path(post)
target_thumb_path = posts.get_post_thumbnail_backup_path(post)
if not files.has(target_content_path):
post_content = read_file(source_content_path)
files.save(posts.get_post_content_path(post), post_content)
if os.path.exists(source_thumb_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)
files.save(posts.get_post_thumbnail_backup_path(post), thumb_content)
files.save(target_thumb_path, thumb_content)
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):