Created
April 10, 2019 15:59
-
-
Save mattlevine/2f3c7078ac6066134750106f650f7c5c to your computer and use it in GitHub Desktop.
An example of how to conditionally load a config.xml.cfm
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
<cfscript> | |
// this is to avoid loading the config if it is already up to date in the DB | |
loadXML = checkLoad(siteBean, rsSites); | |
function checkLoad(siteBean, rsSites) { | |
var loadXML = false; | |
var siteid = siteBean.getSiteID(); | |
// read the JSON file, which contains the modification date of the last loaded config for each site | |
var themeDir = expandPath(siteBean.getThemeAssetPath()); | |
var fileInfo = getFileInfo("#themeDir#/config.xml.cfm"); | |
var fileDate = fileInfo.lastModified; | |
var scd_path = "#themeDir#/site_config_dates.json"; | |
if (!structKeyExists(request, 'siteConfigDates')) { | |
if (fileExists(scd_path)) | |
request.siteConfigDates = deserializeJSON(fileRead(scd_path)); | |
else | |
request.siteConfigDates = {}; | |
// check if a site has been deleted | |
for (var scd_siteid in request.siteConfigDates) { | |
var found = false; | |
for (var i=1; i <= rsSites.recordcount; i++) { | |
var rs_siteid = rsSites['siteid'][i]; | |
if (rs_siteid == scd_siteid) { | |
found = true; | |
break; | |
} | |
} | |
if (!found) { | |
structDelete(request.siteConfigDates, scd_siteid); | |
fileWrite(scd_path, serializeJSON(request.siteConfigDates)); | |
break; | |
} | |
} | |
} | |
// check if loading is needed and update the JSON file | |
if (!structKeyExists(request.siteConfigDates, siteid) || | |
request.siteConfigDates[siteid] != fileDate) { | |
loadXML = true; | |
request.siteConfigDates[siteid] = fileDate; | |
fileWrite(scd_path, serializeJSON(request.siteConfigDates)); | |
} | |
return loadXML; | |
} | |
</cfscript> | |
<cfif loadXML> | |
... | |
</cfif> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment