This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/admin/fixShakeFlavors.cfm
John Mizerek 1210249f54 Normalize database column and table names across entire codebase
Update all SQL queries, query result references, and ColdFusion code to match
the renamed database schema. Tables use plural CamelCase, PKs are all `ID`,
column prefixes stripped (e.g. BusinessName→Name, UserFirstName→FirstName).

Key changes:
- Strip table-name prefixes from all column references (Businesses, Users,
  Addresses, Hours, Menus, Categories, Items, Stations, Orders,
  OrderLineItems, Tasks, TaskCategories, TaskRatings, QuickTaskTemplates,
  ScheduledTaskDefinitions, ChatMessages, Beacons, ServicePoints, Employees,
  VisitorTrackings, ApiPerfLogs, tt_States, tt_Days, tt_AddressTypes,
  tt_OrderTypes, tt_TaskTypes)
- Rename PK references from {TableName}ID to ID in all queries
- Rewrite 7 admin beacon files to use ServicePoints.BeaconID instead of
  dropped lt_Beacon_Businesses_ServicePoints link table
- Rewrite beacon assignment files (list, save, delete) for new schema
- Fix FK references incorrectly changed to ID (OrderLineItems.OrderID,
  Categories.MenuID, Tasks.CategoryID, ServicePoints.BeaconID)
- Update Addresses: AddressLat→Latitude, AddressLng→Longitude
- Update Users: UserPassword→Password, UserIsEmailVerified→IsEmailVerified,
  UserIsActive→IsActive, UserBalance→Balance, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 15:39:12 -08:00

159 lines
4.8 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<!--- Only allow from localhost --->
<cfif NOT (cgi.remote_addr EQ "127.0.0.1" OR cgi.remote_addr EQ "::1" OR findNoCase("localhost", cgi.server_name))>
<cfoutput>#serializeJSON({"OK": false, "ERROR": "admin_only"})#</cfoutput>
<cfabort>
</cfif>
<cfscript>
/**
* Fix Real Ice Cream Shake modifier structure
*
* Current (wrong):
* Real Ice Cream Shake (5808)
* ├── Chocolate (6294) - marked as template
* ├── Strawberry (6292) - marked as template
* └── Vanilla (6293) - marked as template
*
* Correct:
* Real Ice Cream Shake (5808)
* └── Choose Flavor (NEW - modifier group, REQUIRED)
* ├── Chocolate
* ├── Strawberry
* └── Vanilla
*
* Steps:
* 1. Create "Choose Flavor" modifier group under Shake (5808)
* 2. Re-parent the three flavors under the new group
* 3. Remove template flag from flavors
* 4. Mark "Choose Flavor" as the template
* 5. Create lt_ItemID_TemplateItemID entry for Shake -> Choose Flavor
* 6. Set RequiresChildSelection=1 on the shake item
*/
response = { "OK": false, "steps": [] };
try {
shakeItemID = 5808;
chocolateID = 6294;
strawberryID = 6292;
vanillaID = 6293;
categoryID = 46; // Fries and Shakes
// Step 1: Create "Choose Flavor" modifier group under Shake
queryExecute("
INSERT INTO Items (
CategoryID,
Name,
Description,
ParentItemID,
Price,
IsActive,
IsCheckedByDefault,
RequiresChildSelection,
MaxNumSelectionReq,
IsCollapsible,
SortOrder,
IsModifierTemplate,
AddedOn
) VALUES (
:categoryID,
'Choose Flavor',
'',
:shakeItemID,
0,
1,
0,
1,
1,
1,
0,
1,
NOW()
)
", {
categoryID: categoryID,
shakeItemID: shakeItemID
}, { datasource: "payfrit" });
// Get the new Choose Flavor ID
qNewGroup = queryExecute("
SELECT ID FROM Items
WHERE Name = 'Choose Flavor'
AND ParentItemID = :shakeItemID
ORDER BY ID DESC
LIMIT 1
", { shakeItemID: shakeItemID }, { datasource: "payfrit" });
chooseFlavorID = qNewGroup.ID;
arrayAppend(response.steps, "Created 'Choose Flavor' group with ID: " & chooseFlavorID);
// Step 2: Re-parent the three flavors under Choose Flavor
queryExecute("
UPDATE Items
SET ParentItemID = :chooseFlavorID,
IsModifierTemplate = 0,
IsCheckedByDefault = 0
WHERE ItemID IN (:chocolateID, :strawberryID, :vanillaID)
", {
chooseFlavorID: chooseFlavorID,
chocolateID: chocolateID,
strawberryID: strawberryID,
vanillaID: vanillaID
}, { datasource: "payfrit" });
arrayAppend(response.steps, "Re-parented Chocolate, Strawberry, Vanilla under Choose Flavor");
// Step 3: Set Vanilla as default (common choice)
queryExecute("
UPDATE Items SET IsCheckedByDefault = 1 WHERE ItemID = :vanillaID
", { vanillaID: vanillaID }, { datasource: "payfrit" });
arrayAppend(response.steps, "Set Vanilla as default flavor");
// Step 4: Remove old template links for the flavors
queryExecute("
DELETE FROM lt_ItemID_TemplateItemID
WHERE TemplateItemID IN (:chocolateID, :strawberryID, :vanillaID)
", {
chocolateID: chocolateID,
strawberryID: strawberryID,
vanillaID: vanillaID
}, { datasource: "payfrit" });
arrayAppend(response.steps, "Removed old template links for flavor items");
// Step 5: Create lt_ItemID_TemplateItemID for Shake -> Choose Flavor
queryExecute("
INSERT INTO lt_ItemID_TemplateItemID (ItemID, TemplateItemID, SortOrder)
VALUES (:shakeItemID, :chooseFlavorID, 0)
ON DUPLICATE KEY UPDATE SortOrder = 0
", {
shakeItemID: shakeItemID,
chooseFlavorID: chooseFlavorID
}, { datasource: "payfrit" });
arrayAppend(response.steps, "Created template link: Shake -> Choose Flavor");
// Step 6: Set RequiresChildSelection on shake
queryExecute("
UPDATE Items
SET RequiresChildSelection = 1
WHERE ItemID = :shakeItemID
", { shakeItemID: shakeItemID }, { datasource: "payfrit" });
arrayAppend(response.steps, "Set RequiresChildSelection=1 on Shake item");
response["OK"] = true;
response["chooseFlavorID"] = chooseFlavorID;
} catch (any e) {
response["ERROR"] = e.message;
response["DETAIL"] = e.detail;
}
writeOutput(serializeJSON(response));
</cfscript>