Skip to content

Commit

Permalink
Release RLPPTM-1.16.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Jan 24, 2022
1 parent 5b053e8 commit 72968a8
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RLPPTM-1.16.2-1-g3431ec788 (2022-01-11 00:01:51)
RLPPTM-1.16.3 (2022-01-24 14:01:52)
97 changes: 97 additions & 0 deletions modules/templates/RLPPTM/upgrade/1.16.2-1.16.3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Database upgrade script
#
# RLPPTM Template Version 1.16.2 => 1.16.3
#
# Execute in web2py folder after code upgrade like:
# python web2py.py -S eden -M -R applications/eden/modules/templates/RLPPTM/upgrade/1.16.2-1.16.3.py
#
import sys

from core import S3Duplicate

# Override auth (disables all permission checks)
auth.override = True

# Failed-flag
failed = False

# Info
def info(msg):
sys.stderr.write("%s" % msg)
def infoln(msg):
sys.stderr.write("%s\n" % msg)

# Load models for tables
#ftable = s3db.org_facility

IMPORT_XSLT_FOLDER = os.path.join(request.folder, "static", "formats", "s3csv")
TEMPLATE_FOLDER = os.path.join(request.folder, "modules", "templates", "RLPPTM")

# -----------------------------------------------------------------------------
# Deploy new CMS items
#
if not failed:
info("Deploy new CMS items")

# File and Stylesheet Paths
stylesheet = os.path.join(IMPORT_XSLT_FOLDER, "cms", "post.xsl")
filename = os.path.join(TEMPLATE_FOLDER, "cms_post.csv")

# Only import relevant CMS posts, do not update any existing ones
def cms_post_duplicate(item):
name = item.data.get("name")
if name in ("DaycareTestingInquiry",
):
S3Duplicate(noupdate=True)(item)
else:
item.skip = True

# Import, fail on any errors
try:
with open(filename, "r") as File:
resource = s3db.resource("cms_post")
resource.configure(deduplicate = cms_post_duplicate)
resource.import_xml(File,
source_type = "csv",
stylesheet = stylesheet,
)
except:
infoln("...failed")
infoln(sys.exc_info()[1])
failed = True
else:
if resource.error:
infoln("...failed")
infoln(resource.error)
failed = True
else:
infoln("...done")

# -----------------------------------------------------------------------------
# Upgrade user roles
#
if not failed:
info("Upgrade user roles")

bi = s3base.BulkImporter()
filename = os.path.join(TEMPLATE_FOLDER, "auth_roles.csv")

with open(filename, "r") as File:
try:
bi.import_roles(filename)
except Exception as e:
infoln("...failed")
infoln(sys.exc_info()[1])
failed = True
else:
infoln("...done")

# -----------------------------------------------------------------------------
# Finishing up
#
if failed:
db.rollback()
infoln("UPGRADE FAILED - Action rolled back.")
else:
db.commit()
infoln("UPGRADE SUCCESSFUL.")

0 comments on commit 72968a8

Please sign in to comment.