migration-hotfix
This commit is contained in:
parent
d3703ab17c
commit
3567e9f625
|
@ -38,14 +38,13 @@ def get_shout_slug(entry):
|
|||
|
||||
|
||||
def create_author_from_app(app):
|
||||
user = None
|
||||
userdata = None
|
||||
if app:
|
||||
try:
|
||||
with local_session() as session:
|
||||
# check if email is used
|
||||
user = session.query(User).where(User.email == app['email']).first()
|
||||
if not user:
|
||||
print('[migration] creating user...')
|
||||
# print('[migration] app %r' % app)
|
||||
name = app.get('name')
|
||||
if name:
|
||||
slug = translit(name, "ru", reversed=True).lower()
|
||||
|
@ -63,10 +62,12 @@ def create_author_from_app(app):
|
|||
slug += '-author'
|
||||
user = session.query(User).where(User.slug == slug).first()
|
||||
else:
|
||||
print(f'[migration] author @{slug} is found by email')
|
||||
# print(f'[migration] author @{slug} is found by email')
|
||||
pass
|
||||
|
||||
else:
|
||||
print(f'[migration] author @{slug} is found')
|
||||
# print(f'[migration] author @{slug} is found')
|
||||
pass
|
||||
|
||||
|
||||
# create user with application data
|
||||
|
@ -81,13 +82,13 @@ def create_author_from_app(app):
|
|||
"createdAt": ts,
|
||||
"lastSeen": ts,
|
||||
}
|
||||
# print('[migration] userdata %r' % userdata)
|
||||
user = User.create(**userdata)
|
||||
session.add(user)
|
||||
session.commit()
|
||||
|
||||
if not userdata:
|
||||
userdata = user.dict()
|
||||
except Exception as e:
|
||||
print(app)
|
||||
raise e
|
||||
return userdata
|
||||
|
||||
|
||||
|
@ -108,13 +109,23 @@ async def create_shout(shout_dict):
|
|||
|
||||
|
||||
async def get_user(entry, storage):
|
||||
app = entry.get("application")
|
||||
userdata = None
|
||||
|
||||
if app:
|
||||
userdata = create_author_from_app(app)
|
||||
# print("[migration] from app")
|
||||
|
||||
user_oid = entry.get("createdBy")
|
||||
if user_oid == "0":
|
||||
userdata = discours
|
||||
|
||||
if not userdata:
|
||||
userdata = storage["users"]["by_oid"].get(user_oid)
|
||||
# print("[migration] user from user_oid")
|
||||
|
||||
if not userdata:
|
||||
userdata = create_author_from_app(entry.get("application"))
|
||||
print("[migration] from user_oid")
|
||||
if not userdata:
|
||||
print("[migration] no app no user_oid")
|
||||
# print("[migration] no app, no user_oid")
|
||||
userdata = anondict
|
||||
# cleanup slug
|
||||
slug = userdata.get("slug", "")
|
||||
|
|
Loading…
Reference in New Issue
Block a user