2020-01-28 11:00:23 +00:00
|
|
|
const frappe = require('frappejs');
|
|
|
|
|
2021-11-09 10:42:39 +00:00
|
|
|
module.exports = async function runPatches(allPatches, patchOrder) {
|
2020-01-28 11:00:23 +00:00
|
|
|
let executedPatchRuns = [];
|
|
|
|
try {
|
|
|
|
executedPatchRuns = (
|
|
|
|
await frappe.db.getAll({ doctype: 'PatchRun', fields: ['name'] })
|
2021-11-09 10:42:39 +00:00
|
|
|
).map((d) => d.name);
|
2020-01-28 11:00:23 +00:00
|
|
|
} catch (error) {}
|
|
|
|
|
|
|
|
let patchRunOrder = patchOrder
|
2021-11-09 10:42:39 +00:00
|
|
|
.map((text) => {
|
2020-01-28 11:00:23 +00:00
|
|
|
let [patch] = text.split(' ');
|
|
|
|
if (text && patch) {
|
|
|
|
return {
|
|
|
|
fileName: text,
|
2021-11-09 10:42:39 +00:00
|
|
|
method: allPatches[patch],
|
2020-01-28 11:00:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter(Boolean);
|
|
|
|
|
|
|
|
for (let patch of patchRunOrder) {
|
|
|
|
if (!executedPatchRuns.includes(patch.fileName)) {
|
|
|
|
await runPatch(patch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
async function runPatch(patch) {
|
|
|
|
try {
|
|
|
|
await patch.method();
|
|
|
|
let patchRun = frappe.getNewDoc('PatchRun');
|
|
|
|
patchRun.name = patch.fileName;
|
|
|
|
await patchRun.insert();
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
console.log('Could not run patch', patch);
|
|
|
|
}
|
|
|
|
}
|