From 70aed00d97695aa5adabe784bde60510ad68c83b Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 2 Apr 2022 16:33:23 -0500 Subject: [PATCH] added command to fix legacy property issues --- app/__init__.py | 12 ++++++++++-- app/commands.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 4c3a915..c3a1fa5 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,5 +1,5 @@ import os -from flask import Flask, url_for, g, redirect, render_template +from flask import Flask, url_for, g, redirect from functools import wraps from flask_assets import Environment from webassets import Bundle @@ -12,7 +12,14 @@ from flask_wtf.csrf import CSRFProtect from flask_apscheduler import APScheduler from app.luclient import register_luclient_jinja_helpers -from app.commands import init_db, init_accounts, load_property, gen_image_cache, gen_model_cache +from app.commands import ( + init_db, + init_accounts, + load_property, + gen_image_cache, + gen_model_cache, + fix_clone_ids +) from app.models import Account, AccountInvitation, AuditLog import logging @@ -90,6 +97,7 @@ def create_app(): app.cli.add_command(load_property) app.cli.add_command(gen_image_cache) app.cli.add_command(gen_model_cache) + app.cli.add_command(fix_clone_ids) register_logging(app) register_settings(app) diff --git a/app/commands.py b/app/commands.py index dfecd8d..bd815a4 100644 --- a/app/commands.py +++ b/app/commands.py @@ -47,6 +47,23 @@ def init_accounts(): return +@click.command("fix_clone_ids") +@with_appcontext +def fix_clone_ids(): + """Fix incorrect prop_clone_id's""" + properties = Property.query.all() + count = 0 + for prop in properties: + char = CharacterInfo.query.filter(CharacterInfo.id == prop.owner_id).first() + if char.prop_clone_id != prop.clone_id: + count += 1 + prop.clone_id = char.prop_clone_id + prop.save() + + print(f"Fixed {count} props") + return + + @click.command("load_property") @click.argument('zone') @click.argument('player')