<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">

<cfscript>
bizId = 27;

// These are the items that were deactivated by fixBigDeansCategories.cfm
deactivatedIds = [11177, 11180, 11183, 11186, 11190, 11193, 11196, 11199, 11204, 11212, 11220, 11259];

qDeactivated = queryExecute("
  SELECT i.ID, i.Name, i.ParentItemID, i.IsActive, i.IsCollapsible,
         (SELECT COUNT(*) FROM Items c WHERE c.ParentItemID = i.ID) as ChildCount,
         (SELECT GROUP_CONCAT(c.Name) FROM Items c WHERE c.ParentItemID = i.ID) as Children
  FROM Items i
  WHERE i.ID IN (:ids)
  ORDER BY i.ID
", { ids: { value: arrayToList(deactivatedIds), list: true } }, { datasource: "payfrit" });

items = [];
for (row in qDeactivated) {
  arrayAppend(items, {
    "ItemID": row.ID,
    "Name": row.Name,
    "ParentID": row.ParentItemID,
    "IsActive": row.IsActive,
    "IsCollapsible": row.IsCollapsible,
    "ChildCount": row.ChildCount,
    "Children": row.Children
  });
}

writeOutput(serializeJSON({
  "OK": true,
  "Message": "These items were deactivated thinking they were fake categories",
  "DeactivatedItems": items
}));
</cfscript>
