-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
RLPPTM-1.20.3 (2023-03-03 14:03:46) | ||
RLPPTM-1.21.0 (2023-03-10 15:03:25) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Database upgrade script | ||
# | ||
# RLPPTM Template Version 1.20.3 => 1.21.0 | ||
# | ||
# Execute in web2py folder after code upgrade like: | ||
# python web2py.py -S eden -M -R applications/eden/modules/templates/RLPPTM/upgrade/1.20.3-1.21.0.py | ||
# | ||
import sys | ||
|
||
#from core import S3Duplicate | ||
from templates.RLPPTM.models.org import ProviderRepresentative | ||
|
||
# Override auth (disables all permission checks) | ||
auth.override = True | ||
|
||
# Initialize failed-flag | ||
failed = False | ||
|
||
# Info | ||
def info(msg): | ||
sys.stderr.write("%s" % msg) | ||
sys.stderr.flush() | ||
def infoln(msg): | ||
sys.stderr.write("%s\n" % msg) | ||
sys.stderr.flush() | ||
|
||
# Load models for tables | ||
rtable = s3db.org_representative | ||
|
||
# Paths | ||
IMPORT_XSLT_FOLDER = os.path.join(request.folder, "static", "formats", "s3csv") | ||
TEMPLATE_FOLDER = os.path.join(request.folder, "modules", "templates", "RLPPTM") | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Upgrade user roles | ||
# | ||
if not failed: | ||
info("Upgrade user roles") | ||
|
||
bi = s3base.BulkImporter() | ||
filename = os.path.join(TEMPLATE_FOLDER, "auth_roles.csv") | ||
|
||
try: | ||
error = bi.import_roles(filename) | ||
except Exception as e: | ||
error = sys.exc_info()[1] or "unknown error" | ||
if error: | ||
infoln("...failed") | ||
infoln(error) | ||
failed = True | ||
else: | ||
infoln("...done") | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Update representative verification status | ||
# | ||
if not failed: | ||
info("Update representative verification status...") | ||
|
||
rows = db(rtable.deleted == False).select(rtable.id) | ||
|
||
updated = 0 | ||
for row in rows: | ||
representative = ProviderRepresentative(row.id) | ||
representative.update_verification() | ||
updated += 1 | ||
tick = "+" if representative.record.status == "APPROVED" else "-" | ||
info(tick) | ||
|
||
infoln("...done (%s records updated)" % updated) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Finishing up | ||
# | ||
if failed: | ||
db.rollback() | ||
infoln("UPGRADE FAILED - Action rolled back.") | ||
else: | ||
db.commit() | ||
infoln("UPGRADE SUCCESSFUL.") | ||
|
||
# END ========================================================================= |