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>
96 lines
3.6 KiB
JavaScript
96 lines
3.6 KiB
JavaScript
"use strict";
|
||
/*
|
||
* Check001(退職済み)の運用をやめるため、(1)マスタ全レコードのCheck001をfalseへ一括リセットし、
|
||
* (2)SiteSettings.Columns / EditorColumnHash.General からCheck001の項目定義を除去する。
|
||
* 既定はドライラン(対象件数・現状設定の表示のみ)。実際に送信するには --execute を付ける。
|
||
*
|
||
* 実行: node scripts/remove-check001.js [--execute]
|
||
*/
|
||
const { getSite: fetchSite, getSiteItems, updateSiteItem } = require("../src/lib/pleasanterClient");
|
||
const { saveSiteSnapshot } = require("../src/lib/siteConfigStore");
|
||
|
||
const BASE_URL = process.env.PLEASANTER_BASE_URL;
|
||
const API_KEY = process.env.PLEASANTER_API_KEY;
|
||
const SITE_ID = process.env.PLEASANTER_MASTER_SITE_ID;
|
||
|
||
if (!BASE_URL || !API_KEY || !SITE_ID) {
|
||
console.error("PLEASANTER_BASE_URL / PLEASANTER_API_KEY / PLEASANTER_MASTER_SITE_ID が未設定");
|
||
process.exit(1);
|
||
}
|
||
|
||
async function getSite() {
|
||
const data = await fetchSite({ baseUrl: BASE_URL, apiKey: API_KEY, siteId: SITE_ID });
|
||
saveSiteSnapshot(SITE_ID, data);
|
||
return data;
|
||
}
|
||
|
||
async function updateSite(body) {
|
||
const res = await fetch(`${BASE_URL.replace(/\/$/, "")}/api/items/${SITE_ID}/updatesite`, {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json; charset=utf-8" },
|
||
body: JSON.stringify(body),
|
||
});
|
||
const data = await res.json();
|
||
if (!res.ok || data.StatusCode !== 200) {
|
||
throw new Error(`updatesite failed: ${res.status} ${JSON.stringify(data)}`);
|
||
}
|
||
return data;
|
||
}
|
||
|
||
async function main() {
|
||
const execute = process.argv.includes("--execute");
|
||
const config = { baseUrl: BASE_URL, apiKey: API_KEY, siteId: SITE_ID };
|
||
|
||
const current = await getSite();
|
||
const currentColumns = current.SiteSettings.Columns || [];
|
||
const newColumns = currentColumns.filter((c) => c.ColumnName !== "Check001");
|
||
const currentGeneral = current.SiteSettings.EditorColumnHash.General || [];
|
||
const newGeneral = currentGeneral.filter((c) => c !== "Check001");
|
||
|
||
const masterItems = await getSiteItems(config);
|
||
const targets = masterItems.filter((i) => i.Check001 === true);
|
||
|
||
console.log(`--- (1) データリセット ---`);
|
||
console.log(`Check001=trueの件数: ${targets.length} -> falseへリセット`);
|
||
|
||
console.log(`\n--- (2) サイト設定から項目除去 ---`);
|
||
console.log(`Columns: ${currentColumns.length}件 -> ${newColumns.length}件(Check001除去)`);
|
||
console.log(`EditorColumnHash.General: ${currentGeneral.length}件 -> ${newGeneral.length}件(Check001除去)`);
|
||
|
||
if (!execute) {
|
||
console.log("\n[ドライラン] --execute を付けずに実行したため送信していません。");
|
||
return;
|
||
}
|
||
|
||
let reset = 0;
|
||
for (const item of targets) {
|
||
await updateSiteItem({ baseUrl: BASE_URL, apiKey: API_KEY, itemId: item.ResultId, fields: { Check001: false } });
|
||
reset++;
|
||
}
|
||
console.log(`\n[OK] ${reset}件のCheck001をfalseにリセットしました。`);
|
||
|
||
const body = {
|
||
ApiVersion: "1.1",
|
||
ApiKey: API_KEY,
|
||
ReferenceType: current.ReferenceType,
|
||
ParentId: current.ParentId,
|
||
InheritPermission: current.InheritPermission,
|
||
Permissions: current.Permissions,
|
||
SiteSettings: {
|
||
...current.SiteSettings,
|
||
Columns: newColumns,
|
||
EditorColumnHash: { ...current.SiteSettings.EditorColumnHash, General: newGeneral },
|
||
},
|
||
};
|
||
const result = await updateSite(body);
|
||
console.log("[OK] サイト設定からCheck001を除去:", JSON.stringify(result));
|
||
|
||
await getSite();
|
||
console.log(`[OK] 反映後の状態をconfigs/site-${SITE_ID}_*/sitesettings/へ保存`);
|
||
}
|
||
|
||
main().catch((e) => {
|
||
console.error(e);
|
||
process.exit(1);
|
||
});
|