fix migration 2

This commit is contained in:
knst-kotov 2022-06-25 18:06:21 +03:00
parent a075bfaf10
commit 8a009ea85d
3 changed files with 7 additions and 6 deletions

View File

@ -87,7 +87,7 @@ def topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data):
old_id = tag["createdBy"] old_id = tag["createdBy"]
tag["createdBy"] = user_id_map.get(old_id, 0) tag["createdBy"] = user_id_map.get(old_id, 0)
topic = migrateTag(tag) topic = migrateTag(tag)
topics_by_title[topic['title']] = topic #topics_by_title[topic['title']] = topic
topics_by_oid[topic['tag_id']] = topic topics_by_oid[topic['tag_id']] = topic
if not topics_by_slug.get(topic['slug']): topics_by_slug[topic['slug']] = topic if not topics_by_slug.get(topic['slug']): topics_by_slug[topic['slug']] = topic
counter += 1 counter += 1
@ -98,9 +98,9 @@ def topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data):
except Exception as e: raise e except Exception as e: raise e
topics_by_oid[topic['cat_id']] = topic topics_by_oid[topic['cat_id']] = topic
topics_by_slug[topic['slug']] = topic topics_by_slug[topic['slug']] = topic
topics_by_title[topic['title']] = topic #topics_by_title[topic['title']] = topic
counter += 1 counter += 1
export_topics = dict(topics_by_title.items()) #export_topics = dict(topics_by_title.items())
def shouts(content_data, shouts_by_slug, shouts_by_oid): def shouts(content_data, shouts_by_slug, shouts_by_oid):
''' migrating content items one by one ''' ''' migrating content items one by one '''

View File

@ -109,7 +109,7 @@ def migrate(entry, users_by_oid, topics_by_oid):
if entry.get('type') == 'Literature': if entry.get('type') == 'Literature':
media = entry.get('media', '') media = entry.get('media', '')
# print(media[0]['literatureBody']) # print(media[0]['literatureBody'])
if type(media) == list: if type(media) == list and media:
body_orig = media[0].get('literatureBody', '') body_orig = media[0].get('literatureBody', '')
if body_orig == '': if body_orig == '':
print('EMPTY BODY!') print('EMPTY BODY!')
@ -191,7 +191,7 @@ def migrate(entry, users_by_oid, topics_by_oid):
metadata = get_metadata(shout_dict) metadata = get_metadata(shout_dict)
content = frontmatter.dumps(frontmatter.Post(body, **metadata)) content = frontmatter.dumps(frontmatter.Post(body, **metadata))
ext = 'mdx' ext = 'mdx'
open('../discoursio-web/content/' + r['layout'] + '/' + r['slug'] + '.' + ext, 'w').write(content) #open('../discoursio-web/content/' + r['layout'] + '/' + r['slug'] + '.' + ext, 'w').write(content)
try: try:
shout_dict['createdAt'] = date_parse(r.get('createdAt')) if entry.get('createdAt') else ts shout_dict['createdAt'] = date_parse(r.get('createdAt')) if entry.get('createdAt') else ts
shout_dict['publishedAt'] = date_parse(entry.get('publishedAt')) if entry.get('published') else None shout_dict['publishedAt'] = date_parse(entry.get('publishedAt')) if entry.get('published') else None

View File

@ -34,6 +34,7 @@ def migrate(entry):
res['old_id'] = entry['_id'] res['old_id'] = entry['_id']
res['password'] = entry['services']['password'].get('bcrypt', '') res['password'] = entry['services']['password'].get('bcrypt', '')
del entry['services'] del entry['services']
if 'subscribedTo' in entry: #TODO: use subscribedTo
del entry['subscribedTo'] del entry['subscribedTo']
res['username'] = entry['emails'][0]['address'] res['username'] = entry['emails'][0]['address']
res['email'] = res['username'] res['email'] = res['username']