GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。 NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは 別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
132 lines
5.9 KiB
JavaScript
132 lines
5.9 KiB
JavaScript
/**
|
||
* clear-relating-columns-488755.js
|
||
* ------------------------------------------------------------
|
||
* 488755「【開発中】★建売マスターシート」のSiteSettings.RelatingColumns(項目連携)を
|
||
* 恒久的に全解除する。189112「★マスターシート」で実施済みの対応の横展開
|
||
* (189112とRelatingColumns構成が同一と確認済み)。選択肢の絞り込みはクライアント側
|
||
* スクリプト(4_3.テーブルリンクと情報取得.js filterChildOptions/filterChildOptionsByApi)
|
||
* に置き換え済み。
|
||
*
|
||
* 対象の6組(送信前に必ず一覧表示、--restoreで元に戻せるよう変更前の内容を保存する):
|
||
* Id1 ブランド-シリーズ (Class033, Class035)
|
||
* Id2 営業設計 (ClassW, Class171)
|
||
* Id3 担当監督 (ClassW, Class172)
|
||
* Id4 担当IC (ClassW, Class173)
|
||
* Id5 管理設計 (ClassW, Class174)
|
||
* Id6 派生契約コード (ClassC, Class049)
|
||
*
|
||
* 使い方:
|
||
* node clear-relating-columns-488755.js --project="★マスターシート" --env=staging
|
||
* … 差分表示のみ(送信なし)
|
||
* node clear-relating-columns-488755.js --project="★マスターシート" --env=staging --execute
|
||
* … 上記に加えて実際に送信する(RelatingColumnsを空配列にする)
|
||
* node clear-relating-columns-488755.js --project="★マスターシート" --env=staging --restore --execute
|
||
* … 直前に保存したbefore内容から元に戻す
|
||
* ------------------------------------------------------------
|
||
*/
|
||
const path = require("path");
|
||
const fs = require("fs");
|
||
const { resolveProjectRoot, loadServerConfig } = require("../../resolve-project");
|
||
const { findSiteDir, newModifyDir } = require("../../site-paths");
|
||
|
||
const { baseDir, env } = resolveProjectRoot();
|
||
const execute = process.argv.includes("--execute");
|
||
const restore = process.argv.includes("--restore");
|
||
const SITE_ID = 488755;
|
||
|
||
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 項目連携(RelatingColumns) ${restore ? "復元" : "全解除"}(${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})`);
|
||
|
||
const siteDir = findSiteDir(path.join(baseDir, "configs", env), SITE_ID);
|
||
const backupPath = siteDir ? path.join(siteDir, "modify", "relating-columns-backup.json") : null;
|
||
|
||
if (restore) {
|
||
if (!backupPath || !fs.existsSync(backupPath)) {
|
||
console.error(`[エラー] バックアップが見つかりません: ${backupPath}`);
|
||
console.error("先に(--restoreなしで)実行してRelatingColumnsを解除していないと復元できません。");
|
||
process.exit(1);
|
||
}
|
||
const backup = JSON.parse(fs.readFileSync(backupPath, "utf-8"));
|
||
console.log(`\n[バックアップから復元] RelatingColumns ${backup.length}件`);
|
||
siteSettings.RelatingColumns = backup;
|
||
} else {
|
||
const before = siteSettings.RelatingColumns || [];
|
||
console.log(`\n--- 現在のRelatingColumns(${before.length}件) ---`);
|
||
before.forEach((r) => console.log(` Id${r.Id} ${r.Title}: ${JSON.stringify(r.Columns)}`));
|
||
|
||
if (before.length === 0) {
|
||
console.log("既に0件です。変更ありません。");
|
||
} else if (siteDir) {
|
||
fs.mkdirSync(path.dirname(backupPath), { recursive: true });
|
||
fs.writeFileSync(backupPath, JSON.stringify(before, null, 2), "utf-8");
|
||
console.log(`\n[OK] 変更前の内容をバックアップしました: ${backupPath}`);
|
||
}
|
||
siteSettings.RelatingColumns = [];
|
||
console.log("RelatingColumns -> 空配列(全解除)");
|
||
}
|
||
console.log("他のSiteSettings(Columns等)・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 maskedBody = { ...body, ApiKey: maskApiKey(body.ApiKey) };
|
||
const ts = new Date().toISOString().replace(/[:.]/g, "-");
|
||
if (siteDir) {
|
||
const modifyDir = newModifyDir(siteDir, restore ? "relating-columns-restore" : "relating-columns-clear");
|
||
fs.writeFileSync(
|
||
path.join(modifyDir, `site-${SITE_ID}_preview_${ts}.json`),
|
||
JSON.stringify(maskedBody, null, 2),
|
||
"utf-8"
|
||
);
|
||
console.log(`\n[OK] 送信予定内容を保存しました: ${path.join(modifyDir, `site-${SITE_ID}_preview_${ts}.json`)}`);
|
||
}
|
||
|
||
if (!execute) {
|
||
console.log("\n[注意] --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}`);
|
||
console.log(text);
|
||
})();
|