/** * disable-autopostback-488755.js * ------------------------------------------------------------ * 488755「【開発中】★建売マスターシート」の担当者系Lookupカラム(ClassF・Class171〜174)から * AutoPostBackプロパティと、ChoicesText内のLookups設定(サーバー側の自動転記)を * 削除する。転記はクライアント側スクリプト(4_3.テーブルリンクと情報取得.js の * change ハンドラ)に完全に置き換える(サーバー側Lookupとの二重転記をやめる)。 * 選択肢自体(ChoicesTextのSiteId指定)は残す(プルダウンの候補元は維持、自動転記のみ削除)。 * 189112「★マスターシート」で実施済みの対応の横展開(189112とSiteSettings構成が同一と確認済み)。 * * updatesite(full)で送信するが、他のSiteSettings(Columns他項目/GridColumns等)・ * Permissions・Title等は現状のまま一切変更しない(対象5カラムのAutoPostBack・ * Lookups削除のみ)。 * * 使い方: * node disable-autopostback-488755.js --project="★マスターシート" --env=staging * … 差分表示のみ(送信なし) * node disable-autopostback-488755.js --project="★マスターシート" --env=staging --execute * … 上記に加えて実際に送信する * ------------------------------------------------------------ */ const path = require("path"); const { resolveProjectRoot, loadServerConfig } = require("../../resolve-project"); const { findSiteDir, newModifyDir } = require("../../site-paths"); const fs = require("fs"); const { baseDir, env } = resolveProjectRoot(); const execute = process.argv.includes("--execute"); const SITE_ID = 488755; const TARGET_COLUMNS = ["ClassF", "Class171", "Class172", "Class173", "Class174"]; function maskApiKey(key) { if (!key) return key; return key.length > 8 ? key.slice(0, 4) + "****" + key.slice(-4) : "****"; } (async () => { const config = loadServerConfig(env); console.log("========================================"); console.log(` 488755 AutoPostBack無効化(${env})${execute ? "(実行)" : "(プレビューのみ)"}`); console.log("========================================"); const getUrl = `${config.BaseUrl.replace(/\/+$/, "")}/api/items/${SITE_ID}/getsite`; const getRes = await fetch(getUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ApiVersion: config.ApiVersion || "1.1", ApiKey: config.ApiKey }), }); const getJson = await getRes.json(); if (getJson.StatusCode !== 200) { console.error("[エラー] getsiteに失敗しました:", JSON.stringify(getJson).slice(0, 500)); process.exit(1); } const data = getJson.Response.Data; const siteSettings = data.SiteSettings; console.log(`[OK] 取得しました(現在のVer: ${data.Ver}, UpdatedTime: ${data.UpdatedTime})`); console.log("\n--- AutoPostBack / Lookups変更対象 ---"); let changed = 0; TARGET_COLUMNS.forEach((name) => { const col = siteSettings.Columns.find((c) => c.ColumnName === name); if (!col) { console.error(`[エラー] Column not found: ${name}`); process.exit(1); } let colChanged = false; if (col.AutoPostBack) { console.log(` ${name} (${col.LabelText}): AutoPostBack true -> 削除`); delete col.AutoPostBack; colChanged = true; } else { console.log(` ${name} (${col.LabelText}): 既にAutoPostBackなし`); } if (col.ChoicesText) { let choices; try { choices = JSON.parse(col.ChoicesText); } catch (e) { console.error(`[エラー] ${name} のChoicesTextがJSONとして解析できません: ${e.message}`); process.exit(1); } let lookupsRemoved = 0; if (Array.isArray(choices)) { choices.forEach((entry) => { if (entry && entry.Lookups) { delete entry.Lookups; lookupsRemoved++; } }); } if (lookupsRemoved > 0) { col.ChoicesText = JSON.stringify(choices); console.log(` ${name}: Lookups設定 ${lookupsRemoved}件を削除(選択肢自体(SiteId指定)は維持)`); colChanged = true; } else { console.log(` ${name}: Lookups設定なし(変更なし)`); } } if (colChanged) changed++; }); console.log(`変更対象: ${changed}件(${TARGET_COLUMNS.length}件中)`); console.log("ColumnsReturnedWhenAutomaticPostbackはAutoPostBackが無効なら参照されないため、値は変更せず残す。"); console.log("他のSiteSettings(他Columns/GridColumns等)・Permissions・Title等は一切変更しません。"); const body = { ApiVersion: config.ApiVersion || "1.1", ApiKey: config.ApiKey, SiteId: SITE_ID, Title: data.Title, ReferenceType: data.ReferenceType, ParentId: data.ParentId, InheritPermission: data.InheritPermission, Permissions: data.Permissions, SiteSettings: siteSettings, }; const siteDir = findSiteDir(path.join(baseDir, "configs", env), SITE_ID); const maskedBody = { ...body, ApiKey: maskApiKey(body.ApiKey) }; const ts = new Date().toISOString().replace(/[:.]/g, "-"); if (siteDir) { const modifyDir = newModifyDir(siteDir, "autopostback-disable"); fs.writeFileSync( path.join(modifyDir, `site-${SITE_ID}_autopostback_preview_${ts}.json`), JSON.stringify(maskedBody, null, 2), "utf-8" ); console.log(`\n[OK] 送信予定内容を保存しました: ${path.join(modifyDir, `site-${SITE_ID}_autopostback_preview_${ts}.json`)}`); } if (!execute) { console.log("\n[注意] --execute が指定されていないため、送信は行っていません。"); console.log("内容を確認の上、問題なければ次を実行してください: node disable-autopostback-488755.js --execute"); process.exit(0); } console.log("\n実際に送信します(updatesite)..."); const url = `${config.BaseUrl.replace(/\/+$/, "")}/api/items/${SITE_ID}/updatesite`; const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); const text = await res.text(); console.log(`HTTP ${res.status} ${res.statusText}`); if (siteDir) { const modifyDir = newModifyDir(siteDir, "autopostback-disable"); fs.writeFileSync(path.join(modifyDir, `site-${SITE_ID}_autopostback_result_${ts}.json`), text, "utf-8"); } console.log(text); })();