diff --git a/server/migrate-v1 b/server/migrate-v1 index 6fc4f82..6c93b76 100755 --- a/server/migrate-v1 +++ b/server/migrate-v1 @@ -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)) - 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()) + 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(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,12 +245,16 @@ def _import_post_content_for_post( 'data', 'posts', row['name'] + '-custom-thumb') - post_content = read_file(source_content_path) - files.save(posts.get_post_content_path(post), post_content) - if os.path.exists(source_thumb_path): + 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(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) - posts.generate_post_thumbnail(post) + 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): rows = list(exec_query(v1_session, 'SELECT * FROM posts'))