@openinc/parse-server-opendash 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/schema/helper/migrationMode.js +2 -0
- package/dist/hooks/Service_Schedule.js +7 -0
- package/dist/hooks/Service_Schedule_Template.js +5 -0
- package/dist/scripts/migration/lib/cadence.d.ts +75 -0
- package/dist/scripts/migration/lib/cadence.js +246 -0
- package/dist/scripts/migration/lib/env.d.ts +5 -0
- package/dist/scripts/migration/lib/env.js +23 -0
- package/dist/scripts/migration/lib/schedule.d.ts +306 -0
- package/dist/scripts/migration/lib/schedule.js +613 -0
- package/dist/scripts/migration/passes/03-equipment.js +11 -4
- package/dist/scripts/migration/passes/13-schedule-templates.d.ts +15 -0
- package/dist/scripts/migration/passes/13-schedule-templates.js +163 -0
- package/dist/scripts/migration/passes/14-schedules.d.ts +30 -0
- package/dist/scripts/migration/passes/14-schedules.js +239 -0
- package/dist/scripts/migration/passes/15-executions.d.ts +34 -0
- package/dist/scripts/migration/passes/15-executions.js +244 -0
- package/dist/scripts/migration/passes/16-schedule-meta.d.ts +23 -0
- package/dist/scripts/migration/passes/16-schedule-meta.js +308 -0
- package/dist/scripts/migration/passes/17-schedule-assets.d.ts +30 -0
- package/dist/scripts/migration/passes/17-schedule-assets.js +240 -0
- package/dist/scripts/migration/passes/18-calendar-links.d.ts +25 -0
- package/dist/scripts/migration/passes/18-calendar-links.js +132 -0
- package/dist/scripts/migration/passes/19-schedule-history.d.ts +18 -0
- package/dist/scripts/migration/passes/19-schedule-history.js +186 -0
- package/dist/scripts/migration/run.js +20 -9
- package/dist/scripts/migration/verify.js +294 -11
- package/dist/scripts/seed-v1-testdata.d.ts +2 -0
- package/dist/scripts/seed-v1-testdata.js +392 -6
- package/dist/types/Service_Schedule.d.ts +3 -0
- package/dist/types/Service_Schedule.js +6 -0
- package/dist/types/Service_Schedule_Execution.d.ts +1 -1
- package/package.json +1 -1
- package/schema/Service_Schedule.json +4 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pass13 = void 0;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const acl_js_1 = require("../lib/acl.js");
|
|
10
|
+
const cadence_js_1 = require("../lib/cadence.js");
|
|
11
|
+
const latest_js_1 = require("../lib/latest.js");
|
|
12
|
+
const map_js_1 = require("../lib/map.js");
|
|
13
|
+
const pass_js_1 = require("../lib/pass.js");
|
|
14
|
+
const ptr_js_1 = require("../lib/ptr.js");
|
|
15
|
+
const schedule_js_1 = require("../lib/schedule.js");
|
|
16
|
+
const ticket_js_1 = require("../lib/ticket.js");
|
|
17
|
+
/**
|
|
18
|
+
* Pass 13 — `OD3_Maintenance_Schedule_Template` → `OD3_Service_Schedule_Template`.
|
|
19
|
+
*
|
|
20
|
+
* A v1 template is a live parent: its plans inherit its interval and, when
|
|
21
|
+
* they have no steps of their own, its steps. A v2 template is a snapshot a
|
|
22
|
+
* plan is *copied* from and then forgets. So pass 14 resolves each plan's
|
|
23
|
+
* inheritance itself, and this pass only carries the templates over as the
|
|
24
|
+
* library they are in v2 — for plans still to be created.
|
|
25
|
+
*
|
|
26
|
+
* Dropped on the way, each reported: `color` (no column on the v2 template)
|
|
27
|
+
* and `sources` (v2 templates are equipment-agnostic; the plans made from a
|
|
28
|
+
* template are the link to the machines, and those migrate in pass 14).
|
|
29
|
+
*/
|
|
30
|
+
exports.pass13 = {
|
|
31
|
+
id: "13",
|
|
32
|
+
title: "schedule-templates",
|
|
33
|
+
needs: [],
|
|
34
|
+
async run({ config, map, report, entry }) {
|
|
35
|
+
const templates = await (0, pass_js_1.all)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule_Template), config.tenantId), config.batchSize);
|
|
36
|
+
if (templates.length === 0)
|
|
37
|
+
return;
|
|
38
|
+
const roleIdByName = new Map([...(await (0, ticket_js_1.loadRoleNames)(config))].map(([id, name]) => [name, id]));
|
|
39
|
+
const steps = new schedule_js_1.StepSource(config.batchSize);
|
|
40
|
+
let manual = 0;
|
|
41
|
+
let monthEnd = 0;
|
|
42
|
+
let colors = 0;
|
|
43
|
+
let withSources = 0;
|
|
44
|
+
for (const template of templates) {
|
|
45
|
+
const sourceId = template.id;
|
|
46
|
+
if (!sourceId)
|
|
47
|
+
continue;
|
|
48
|
+
const tenantId = (0, pass_js_1.refId)(template.get("tenant"));
|
|
49
|
+
if (!tenantId) {
|
|
50
|
+
report.error(entry, `template ${sourceId} has no tenant; Schedule_Template.tenant is ` +
|
|
51
|
+
`required — skipped`);
|
|
52
|
+
entry.skipped++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const existingId = map.get(index_js_1.Maintenance_Schedule_Template.className, sourceId);
|
|
56
|
+
const target = existingId
|
|
57
|
+
? new index_js_1.Service_Schedule_Template({ objectId: existingId })
|
|
58
|
+
: new index_js_1.Service_Schedule_Template();
|
|
59
|
+
const label = `template ${sourceId} ("${template.get("title") ?? ""}")`;
|
|
60
|
+
const access = (0, schedule_js_1.readV1Access)(template, tenantId);
|
|
61
|
+
const roles = (0, schedule_js_1.resolveRoles)((0, schedule_js_1.assignedRoleNames)(access, tenantId), roleIdByName);
|
|
62
|
+
const { cadence, warnings, notes } = (0, cadence_js_1.toCadence)(template.get("cron"), {
|
|
63
|
+
timezone: config.timezone,
|
|
64
|
+
fallbackStart: template.createdAt,
|
|
65
|
+
});
|
|
66
|
+
for (const warning of warnings)
|
|
67
|
+
report.warn(entry, `${label}: ${warning}`);
|
|
68
|
+
if (cadence.kind === "manual")
|
|
69
|
+
manual += 1;
|
|
70
|
+
if (notes.includes("month-end"))
|
|
71
|
+
monthEnd += 1;
|
|
72
|
+
const rows = await steps.of(template);
|
|
73
|
+
const contactIds = await (0, latest_js_1.relationIds)(template, "contacts", config.batchSize);
|
|
74
|
+
// A v1 template only carried the *timing* of a reminder; who was told
|
|
75
|
+
// came from each plan. So its rules name nobody and notify the roles the
|
|
76
|
+
// plan is assigned to — the editor's default — because applying a
|
|
77
|
+
// template in v2 copies its rules onto every new plan.
|
|
78
|
+
const rules = (0, schedule_js_1.notificationRules)(`${index_js_1.Maintenance_Schedule_Template.className}:${sourceId}`, template.get("notifyBeforeDue"), { assignedRoles: true });
|
|
79
|
+
if (rules.deviation)
|
|
80
|
+
report.warn(entry, `${label}: ${rules.deviation}`);
|
|
81
|
+
target.set("title", String(template.get("title") ?? "").trim() || `Vorlage ${sourceId}`);
|
|
82
|
+
if (template.get("description")) {
|
|
83
|
+
target.set("description", template.get("description"));
|
|
84
|
+
}
|
|
85
|
+
target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
|
|
86
|
+
target.set("cadence", cadence);
|
|
87
|
+
target.set("steps", rows.map((row, index) => (0, schedule_js_1.toV2Step)(row, (0, schedule_js_1.templateStepId)(sourceId, row.id), index, true)));
|
|
88
|
+
target.set("serviceProviders", (0, schedule_js_1.serviceProviders)(contactIds));
|
|
89
|
+
target.set("notifications", rules.rules);
|
|
90
|
+
if (access.creatorId)
|
|
91
|
+
target.set("user", (0, ptr_js_1.userPtr)(access.creatorId));
|
|
92
|
+
// v1 lists only `enabled === true` templates; a disabled one is retired,
|
|
93
|
+
// which v2 spells as archived.
|
|
94
|
+
if (template.get("enabled") !== true) {
|
|
95
|
+
target.set("deletedAt", template.updatedAt ?? new Date());
|
|
96
|
+
}
|
|
97
|
+
if (template.get("color"))
|
|
98
|
+
colors += 1;
|
|
99
|
+
if ((await (0, latest_js_1.relationIds)(template, "sources", config.batchSize)).length) {
|
|
100
|
+
withSources += 1;
|
|
101
|
+
}
|
|
102
|
+
if (access.readerUserIds.length) {
|
|
103
|
+
report.warn(entry, `${label}: v1 also let ${access.readerUserIds.length} further ` +
|
|
104
|
+
`user(s) read it — v2 templates are shared by role only, so they lose it`);
|
|
105
|
+
}
|
|
106
|
+
if (roles.unknown.length) {
|
|
107
|
+
report.warn(entry, `${label}: ACL names role(s) ${roles.unknown.join(", ")} that no longer ` +
|
|
108
|
+
`exist — not carried over`);
|
|
109
|
+
}
|
|
110
|
+
if (!existingId) {
|
|
111
|
+
target.setACL((0, schedule_js_1.privateAcl)({
|
|
112
|
+
tenantId,
|
|
113
|
+
creatorId: access.creatorId,
|
|
114
|
+
roleNames: roles.names,
|
|
115
|
+
userIds: [],
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
if (config.dryRun) {
|
|
119
|
+
existingId ? entry.updated++ : entry.created++;
|
|
120
|
+
if (!existingId) {
|
|
121
|
+
await map.record(index_js_1.Maintenance_Schedule_Template.className, sourceId, index_js_1.Service_Schedule_Template.className, map_js_1.MigrationMap.dryId(sourceId));
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const newId = await (0, acl_js_1.saveMigrated)(config, target, {
|
|
127
|
+
className: index_js_1.Service_Schedule_Template.className,
|
|
128
|
+
isNew: !existingId,
|
|
129
|
+
createdAt: template.createdAt,
|
|
130
|
+
updatedAt: template.updatedAt,
|
|
131
|
+
});
|
|
132
|
+
await (0, schedule_js_1.addAssignments)(index_js_1.Service_Schedule_Template.className, newId, {
|
|
133
|
+
roleIds: roles.ids,
|
|
134
|
+
});
|
|
135
|
+
if (existingId) {
|
|
136
|
+
entry.updated++;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
entry.created++;
|
|
140
|
+
await map.record(index_js_1.Maintenance_Schedule_Template.className, sourceId, index_js_1.Service_Schedule_Template.className, newId);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
report.error(entry, `${label} failed: ${error.message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (manual > 0) {
|
|
148
|
+
report.info(entry, `${manual} template(s) without a usable interval → manual`);
|
|
149
|
+
}
|
|
150
|
+
if (monthEnd > 0) {
|
|
151
|
+
report.info(entry, `${monthEnd} template(s) start on a month end — their rule uses ` +
|
|
152
|
+
`BYSETPOS, which the series editor simplifies when re-edited`);
|
|
153
|
+
}
|
|
154
|
+
if (colors > 0) {
|
|
155
|
+
report.info(entry, `${colors} template colour(s) dropped — the v2 template has no colour ` +
|
|
156
|
+
`(plans keep theirs)`);
|
|
157
|
+
}
|
|
158
|
+
if (withSources > 0) {
|
|
159
|
+
report.info(entry, `${withSources} template(s) listed sources — dropped: v2 templates are ` +
|
|
160
|
+
`equipment-agnostic, the plans made from them carry the machine`);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Pass } from "../lib/pass.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pass 14 — `OD3_Maintenance_Schedule` → `OD3_Service_Schedule`.
|
|
4
|
+
*
|
|
5
|
+
* A v1 plan is only half of itself: its interval is laid over its
|
|
6
|
+
* template's, and its steps are the template's when it has none of its own.
|
|
7
|
+
* v2 has no inheritance — a template is copied, then forgotten — so each plan
|
|
8
|
+
* is written as the **effective** plan v1 actually ran:
|
|
9
|
+
*
|
|
10
|
+
* - **cadence**: the plan's `cron` merged over the template's
|
|
11
|
+
* (`mergeScheduleInterval`, as v1's frontend and scheduler did), then
|
|
12
|
+
* translated to an RRULE (`lib/cadence.ts`).
|
|
13
|
+
* - **steps**: the plan's own, else the template's, each with a step id of its
|
|
14
|
+
* own to this plan (`planStepId`).
|
|
15
|
+
* - **notifications**: the plan's `notifyBeforeDue`, else the template's.
|
|
16
|
+
*
|
|
17
|
+
* Visibility carries over exactly. v1 plans were already private — the
|
|
18
|
+
* afterSave gave the creator read+write and denied tenant users — and v2
|
|
19
|
+
* plans are private the same way. What v1 granted beyond that becomes an
|
|
20
|
+
* assignment, because v2 derives the ACL from the assignments on every save.
|
|
21
|
+
*
|
|
22
|
+
* `enabled: false` becomes `active: false`: v1 kept a disabled plan
|
|
23
|
+
* reachable (the detail page toggles it back), it just stopped scheduling —
|
|
24
|
+
* which is what an inactive v2 plan is. Not archived.
|
|
25
|
+
*
|
|
26
|
+
* `description` copies across. `lastExecution` is not carried — v1 only
|
|
27
|
+
* maintained it on one code path, and v2 derives it from the executions
|
|
28
|
+
* (pass 15).
|
|
29
|
+
*/
|
|
30
|
+
export declare const pass14: Pass;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pass14 = void 0;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const acl_js_1 = require("../lib/acl.js");
|
|
10
|
+
const cadence_js_1 = require("../lib/cadence.js");
|
|
11
|
+
const latest_js_1 = require("../lib/latest.js");
|
|
12
|
+
const map_js_1 = require("../lib/map.js");
|
|
13
|
+
const pass_js_1 = require("../lib/pass.js");
|
|
14
|
+
const ptr_js_1 = require("../lib/ptr.js");
|
|
15
|
+
const schedule_js_1 = require("../lib/schedule.js");
|
|
16
|
+
const ticket_js_1 = require("../lib/ticket.js");
|
|
17
|
+
const _08_tickets_js_1 = require("./08-tickets.js");
|
|
18
|
+
/** v2 accepts a colour override only as `#rrggbb`. */
|
|
19
|
+
const HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
20
|
+
/**
|
|
21
|
+
* Pass 14 — `OD3_Maintenance_Schedule` → `OD3_Service_Schedule`.
|
|
22
|
+
*
|
|
23
|
+
* A v1 plan is only half of itself: its interval is laid over its
|
|
24
|
+
* template's, and its steps are the template's when it has none of its own.
|
|
25
|
+
* v2 has no inheritance — a template is copied, then forgotten — so each plan
|
|
26
|
+
* is written as the **effective** plan v1 actually ran:
|
|
27
|
+
*
|
|
28
|
+
* - **cadence**: the plan's `cron` merged over the template's
|
|
29
|
+
* (`mergeScheduleInterval`, as v1's frontend and scheduler did), then
|
|
30
|
+
* translated to an RRULE (`lib/cadence.ts`).
|
|
31
|
+
* - **steps**: the plan's own, else the template's, each with a step id of its
|
|
32
|
+
* own to this plan (`planStepId`).
|
|
33
|
+
* - **notifications**: the plan's `notifyBeforeDue`, else the template's.
|
|
34
|
+
*
|
|
35
|
+
* Visibility carries over exactly. v1 plans were already private — the
|
|
36
|
+
* afterSave gave the creator read+write and denied tenant users — and v2
|
|
37
|
+
* plans are private the same way. What v1 granted beyond that becomes an
|
|
38
|
+
* assignment, because v2 derives the ACL from the assignments on every save.
|
|
39
|
+
*
|
|
40
|
+
* `enabled: false` becomes `active: false`: v1 kept a disabled plan
|
|
41
|
+
* reachable (the detail page toggles it back), it just stopped scheduling —
|
|
42
|
+
* which is what an inactive v2 plan is. Not archived.
|
|
43
|
+
*
|
|
44
|
+
* `description` copies across. `lastExecution` is not carried — v1 only
|
|
45
|
+
* maintained it on one code path, and v2 derives it from the executions
|
|
46
|
+
* (pass 15).
|
|
47
|
+
*/
|
|
48
|
+
exports.pass14 = {
|
|
49
|
+
id: "14",
|
|
50
|
+
title: "schedules",
|
|
51
|
+
needs: ["03"],
|
|
52
|
+
async run({ config, map, report, entry }) {
|
|
53
|
+
const roleIdByName = new Map([...(await (0, ticket_js_1.loadRoleNames)(config))].map(([id, name]) => [name, id]));
|
|
54
|
+
const steps = new schedule_js_1.StepSource(config.batchSize);
|
|
55
|
+
let manual = 0;
|
|
56
|
+
let oneOff = 0;
|
|
57
|
+
let monthEnd = 0;
|
|
58
|
+
let inheritedSteps = 0;
|
|
59
|
+
let inactive = 0;
|
|
60
|
+
let unrestricted = 0;
|
|
61
|
+
let withProviders = 0;
|
|
62
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule), config.tenantId)
|
|
63
|
+
.include("template")
|
|
64
|
+
.include("source"), config.batchSize)) {
|
|
65
|
+
for (const plan of page) {
|
|
66
|
+
const sourceId = plan.id;
|
|
67
|
+
if (!sourceId)
|
|
68
|
+
continue;
|
|
69
|
+
const template = plan.get("template");
|
|
70
|
+
const source = plan.get("source");
|
|
71
|
+
const label = `plan ${sourceId} ("${plan.get("title") ?? ""}")`;
|
|
72
|
+
// `tenant` is optional on the v1 plan but required on v2; the template
|
|
73
|
+
// and the machine name the same tenant when the plan does not.
|
|
74
|
+
const tenantId = (0, pass_js_1.refId)(plan.get("tenant")) ??
|
|
75
|
+
(0, pass_js_1.refId)(template?.get("tenant")) ??
|
|
76
|
+
(0, pass_js_1.refId)(source?.get("tenant"));
|
|
77
|
+
if (!tenantId) {
|
|
78
|
+
report.error(entry, `${label} has no tenant; Schedule.tenant is required — skipped`);
|
|
79
|
+
entry.skipped++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const existingId = map.get(index_js_1.Maintenance_Schedule.className, sourceId);
|
|
83
|
+
const target = existingId
|
|
84
|
+
? new index_js_1.Service_Schedule({ objectId: existingId })
|
|
85
|
+
: new index_js_1.Service_Schedule();
|
|
86
|
+
// ── timing ─────────────────────────────────────────────────────────
|
|
87
|
+
const interval = (0, cadence_js_1.mergeScheduleInterval)(template?.get("cron"), plan.get("cron"));
|
|
88
|
+
const { cadence, warnings, notes } = (0, cadence_js_1.toCadence)(interval, {
|
|
89
|
+
timezone: config.timezone,
|
|
90
|
+
fallbackStart: plan.createdAt,
|
|
91
|
+
});
|
|
92
|
+
for (const warning of warnings)
|
|
93
|
+
report.warn(entry, `${label}: ${warning}`);
|
|
94
|
+
if (cadence.kind === "manual")
|
|
95
|
+
manual += 1;
|
|
96
|
+
if (notes.includes("one-off"))
|
|
97
|
+
oneOff += 1;
|
|
98
|
+
if (notes.includes("month-end"))
|
|
99
|
+
monthEnd += 1;
|
|
100
|
+
// ── steps ──────────────────────────────────────────────────────────
|
|
101
|
+
const { rows, inherited } = await steps.ofPlan(plan);
|
|
102
|
+
if (inherited)
|
|
103
|
+
inheritedSteps += 1;
|
|
104
|
+
// ── who ────────────────────────────────────────────────────────────
|
|
105
|
+
const access = (0, schedule_js_1.readV1Access)(plan, tenantId);
|
|
106
|
+
const explicitRoles = (0, schedule_js_1.resolveRoles)(access.readerRoleNames, roleIdByName);
|
|
107
|
+
const roles = (0, schedule_js_1.resolveRoles)((0, schedule_js_1.assignedRoleNames)(access, tenantId), roleIdByName);
|
|
108
|
+
if (access.unrestricted)
|
|
109
|
+
unrestricted += 1;
|
|
110
|
+
if (roles.unknown.length) {
|
|
111
|
+
report.warn(entry, `${label}: ACL names role(s) ${roles.unknown.join(", ")} that no ` +
|
|
112
|
+
`longer exist — not carried over`);
|
|
113
|
+
}
|
|
114
|
+
if (access.demotedWriterIds.length) {
|
|
115
|
+
report.warn(entry, `${label}: ${access.demotedWriterIds.length} user(s) besides the ` +
|
|
116
|
+
`creator could edit it in v1 — they are assigned in v2, which ` +
|
|
117
|
+
`lets them read it only`);
|
|
118
|
+
}
|
|
119
|
+
const rules = (0, schedule_js_1.notificationRules)(`${index_js_1.Maintenance_Schedule.className}:${sourceId}`, (0, schedule_js_1.effectiveNotifyBeforeDue)(plan, template), (0, schedule_js_1.v1Recipients)(access, explicitRoles.ids));
|
|
120
|
+
if (rules.deviation)
|
|
121
|
+
report.warn(entry, `${label}: ${rules.deviation}`);
|
|
122
|
+
const contactIds = await (0, latest_js_1.relationIds)(plan, "contacts", config.batchSize);
|
|
123
|
+
if (contactIds.length)
|
|
124
|
+
withProviders += 1;
|
|
125
|
+
// ── machine ────────────────────────────────────────────────────────
|
|
126
|
+
const v1SourceId = (0, pass_js_1.refId)(plan.get("source"));
|
|
127
|
+
const equipmentId = v1SourceId
|
|
128
|
+
? map.get(index_js_1.Source.className, v1SourceId)
|
|
129
|
+
: undefined;
|
|
130
|
+
const equipmentPtr = (0, ptr_js_1.maybePtr)(index_js_1.Service_Equipment.className, equipmentId);
|
|
131
|
+
if (equipmentPtr)
|
|
132
|
+
target.set("equipment", equipmentPtr);
|
|
133
|
+
else if (v1SourceId) {
|
|
134
|
+
report.warn(entry, `${label}: source ${v1SourceId} has no Equipment — the plan has no ` +
|
|
135
|
+
`machine and will not appear in the machine book (run pass 03 first)`);
|
|
136
|
+
}
|
|
137
|
+
// ── the rest ───────────────────────────────────────────────────────
|
|
138
|
+
const title = String(plan.get("title") ?? "").trim() ||
|
|
139
|
+
[source?.get("name"), template?.get("title")]
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join(" - ") ||
|
|
142
|
+
`Wartungsplan ${sourceId}`;
|
|
143
|
+
target.set("title", title);
|
|
144
|
+
target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
|
|
145
|
+
target.set("active", plan.get("enabled") === true);
|
|
146
|
+
if (plan.get("enabled") !== true)
|
|
147
|
+
inactive += 1;
|
|
148
|
+
target.set("cadence", cadence);
|
|
149
|
+
target.set("steps", rows.map((row, index) => (0, schedule_js_1.toV2Step)(row, (0, schedule_js_1.planStepId)(sourceId, row.id), index, true)));
|
|
150
|
+
target.set("serviceProviders", (0, schedule_js_1.serviceProviders)(contactIds));
|
|
151
|
+
target.set("notifications", rules.rules);
|
|
152
|
+
target.set("coversTasks", []);
|
|
153
|
+
// v1's overdue rule: "due more than a day ago"
|
|
154
|
+
// (`isScheduleOverdue`). One day of grace is the same line in v2.
|
|
155
|
+
target.set("graceDays", 1);
|
|
156
|
+
target.set("origin", (0, _08_tickets_js_1.legacyOrigin)(sourceId));
|
|
157
|
+
if (access.creatorId)
|
|
158
|
+
target.set("user", (0, ptr_js_1.userPtr)(access.creatorId));
|
|
159
|
+
const color = plan.get("color");
|
|
160
|
+
if (typeof color === "string" && HEX_COLOR.test(color)) {
|
|
161
|
+
target.set("color", color);
|
|
162
|
+
}
|
|
163
|
+
else if (color) {
|
|
164
|
+
report.warn(entry, `${label}: colour "${color}" is not #rrggbb — dropped`);
|
|
165
|
+
}
|
|
166
|
+
const description = String(plan.get("description") ?? "").trim();
|
|
167
|
+
if (description)
|
|
168
|
+
target.set("description", description);
|
|
169
|
+
if (!existingId) {
|
|
170
|
+
target.setACL((0, schedule_js_1.privateAcl)({
|
|
171
|
+
tenantId,
|
|
172
|
+
creatorId: access.creatorId,
|
|
173
|
+
roleNames: roles.names,
|
|
174
|
+
userIds: access.readerUserIds,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
if (config.dryRun) {
|
|
178
|
+
existingId ? entry.updated++ : entry.created++;
|
|
179
|
+
if (!existingId) {
|
|
180
|
+
await map.record(index_js_1.Maintenance_Schedule.className, sourceId, index_js_1.Service_Schedule.className, map_js_1.MigrationMap.dryId(sourceId));
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const newId = await (0, acl_js_1.saveMigrated)(config, target, {
|
|
186
|
+
className: index_js_1.Service_Schedule.className,
|
|
187
|
+
isNew: !existingId,
|
|
188
|
+
createdAt: plan.createdAt,
|
|
189
|
+
updatedAt: plan.updatedAt,
|
|
190
|
+
});
|
|
191
|
+
await (0, schedule_js_1.addAssignments)(index_js_1.Service_Schedule.className, newId, {
|
|
192
|
+
roleIds: roles.ids,
|
|
193
|
+
userIds: access.readerUserIds,
|
|
194
|
+
});
|
|
195
|
+
if (existingId) {
|
|
196
|
+
entry.updated++;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
entry.created++;
|
|
200
|
+
await map.record(index_js_1.Maintenance_Schedule.className, sourceId, index_js_1.Service_Schedule.className, newId);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
report.error(entry, `${label} failed: ${error.message}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (manual > 0) {
|
|
209
|
+
report.info(entry, `${manual} plan(s) without a usable interval → manual (v1 never ` +
|
|
210
|
+
`scheduled them either; warnings above name the odd ones)`);
|
|
211
|
+
}
|
|
212
|
+
if (oneOff > 0) {
|
|
213
|
+
report.info(entry, `${oneOff} plan(s) with interval number 0 → a single appointment on the ` +
|
|
214
|
+
`start date, as v1's editor promised (v1's own iterator repeated them)`);
|
|
215
|
+
}
|
|
216
|
+
if (monthEnd > 0) {
|
|
217
|
+
report.info(entry, `${monthEnd} plan(s) start on a month end — their rule uses BYSETPOS to ` +
|
|
218
|
+
`keep v1's "last day of shorter months"; the series editor simplifies ` +
|
|
219
|
+
`it when re-edited`);
|
|
220
|
+
}
|
|
221
|
+
if (inheritedSteps > 0) {
|
|
222
|
+
report.info(entry, `${inheritedSteps} plan(s) had no steps of their own — they carry their ` +
|
|
223
|
+
`template's, as v1 used them`);
|
|
224
|
+
}
|
|
225
|
+
if (inactive > 0) {
|
|
226
|
+
report.info(entry, `${inactive} disabled plan(s) → active: false`);
|
|
227
|
+
}
|
|
228
|
+
if (unrestricted > 0) {
|
|
229
|
+
report.info(entry, `${unrestricted} plan(s) had no ACL (master-key writes, e.g. the v1 ` +
|
|
230
|
+
`Outlook import) or public read — assigned to the tenant's user ` +
|
|
231
|
+
`role, so its users still see them; their rules do not notify that ` +
|
|
232
|
+
`role, as v1 notified nobody`);
|
|
233
|
+
}
|
|
234
|
+
if (withProviders > 0) {
|
|
235
|
+
report.info(entry, `${withProviders} plan(s) list contacts → service providers with ` +
|
|
236
|
+
`notify: false (v1 never mailed them)`);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Pass } from "../lib/pass.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pass 15 — `OD3_Maintenance_Schedule_Execution` (+ its `_Execution_Step`
|
|
4
|
+
* rows) → `OD3_Service_Schedule_Execution`.
|
|
5
|
+
*
|
|
6
|
+
* Each v1 execution step row becomes two things on the v2 execution: an entry
|
|
7
|
+
* in `steps` — the frozen snapshot a protocol shows, which is exactly what the
|
|
8
|
+
* v1 row is, since v1 copied title and description onto it at start — and a
|
|
9
|
+
* `stepResults` entry with its `done` flag. The ids of both come from
|
|
10
|
+
* `executionStepIds`, which pass 16 uses for the captured values too.
|
|
11
|
+
*
|
|
12
|
+
* Three kinds of v1 run:
|
|
13
|
+
*
|
|
14
|
+
* - **completed** → `completedAt` = `finishedAt`, `performedBy` = the v1
|
|
15
|
+
* `user`, the only person v1 recorded. A step left undone on a completed
|
|
16
|
+
* run was skipped (v1's direct maintenance allowed it) and says so.
|
|
17
|
+
* - **open** (no `finishedAt`) → migrated open, and resumable in v2 exactly
|
|
18
|
+
* as it was in v1.
|
|
19
|
+
* - **abandoned** (`terminated`, or a plan run finished with open steps) →
|
|
20
|
+
* **not migrated**, counted and sampled. See `classifyExecution`.
|
|
21
|
+
*
|
|
22
|
+
* An execution without a plan is v1's "Direkte Wartung". v2 has the same
|
|
23
|
+
* thing since 2026-09-25: no `schedule`, the machine in `equipment`, its own
|
|
24
|
+
* title, description and steps.
|
|
25
|
+
*
|
|
26
|
+
* v1 recorded material per *execution*, v2 per *step*. It goes onto one
|
|
27
|
+
* synthetic, completed step at the end ("Verbrauchtes Material"), because
|
|
28
|
+
* attaching it to a real step would claim that step consumed it. The
|
|
29
|
+
* protocol's "Material insgesamt" adds it up either way.
|
|
30
|
+
*
|
|
31
|
+
* `occurrence` is left unset: v1 never recorded which due date a run
|
|
32
|
+
* settled, and v2 pairs such executions with the nearest occurrence itself.
|
|
33
|
+
*/
|
|
34
|
+
export declare const pass15: Pass;
|