diff --git a/api/admin/fixBrandColors.cfm b/api/admin/fixBrandColors.cfm new file mode 100644 index 0000000..89d627b --- /dev/null +++ b/api/admin/fixBrandColors.cfm @@ -0,0 +1,38 @@ + + + +// One-time fix: remove # prefix from BusinessBrandColor +qBefore = queryExecute(" + SELECT BusinessID, BusinessBrandColor + FROM Businesses + WHERE BusinessBrandColor LIKE :pattern +", { pattern: { value: "#%", cfsqltype: "cf_sql_varchar" } }, { datasource: "payfrit" }); + +if (qBefore.recordCount > 0) { + queryExecute(" + UPDATE Businesses + SET BusinessBrandColor = SUBSTRING(BusinessBrandColor, 2) + WHERE BusinessBrandColor LIKE :pattern + ", { pattern: { value: "#%", cfsqltype: "cf_sql_varchar" } }, { datasource: "payfrit" }); +} + +qAfter = queryExecute(" + SELECT BusinessID, BusinessBrandColor + FROM Businesses + WHERE BusinessBrandColor IS NOT NULL AND LENGTH(BusinessBrandColor) > 0 +", {}, { datasource: "payfrit" }); + +rows = []; +for (i = 1; i <= qAfter.recordCount; i++) { + arrayAppend(rows, { + "BusinessID": qAfter.BusinessID[i], + "BusinessBrandColor": qAfter.BusinessBrandColor[i] + }); +} + +writeOutput(serializeJSON({ + "OK": true, + "FIXED": qBefore.recordCount, + "CURRENT": rows +})); +