mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix problem copy pid
This commit is contained in:
1 parent
0aba9f8215
commit
b10c67f5cf
4 files changed
+21
-6
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.1.1",
|
"version": "3.1.2",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -292,13 +292,12 @@ export class ProblemDetailHandler extends ProblemHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@param('target', Types.String)
|
@param('target', Types.String)
|
||||||
@param('pid', Types.String, true)
|
async postCopy(domainId: string, target: string) {
|
||||||
async postCopy(domainId: string, target: string, pid: string) {
|
|
||||||
const ddoc = await domain.get(target);
|
const ddoc = await domain.get(target);
|
||||||
if (!ddoc) throw new NotFoundError(target);
|
if (!ddoc) throw new NotFoundError(target);
|
||||||
const dudoc = await user.getById(target, this.user._id);
|
const dudoc = await user.getById(target, this.user._id);
|
||||||
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
|
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
|
||||||
const docId = await problem.copy(domainId, this.user.docId, target, pid);
|
const docId = await problem.copy(domainId, this.user.docId, target, this.pdoc.pid);
|
||||||
this.response.redirect = this.url('problem_detail', { domainId: target, pid: docId });
|
this.response.redirect = this.url('problem_detail', { domainId: target, pid: docId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export class ProblemModel {
|
|||||||
static async copy(domainId: string, _id: number, target: string, pid?: string) {
|
static async copy(domainId: string, _id: number, target: string, pid?: string) {
|
||||||
const original = await ProblemModel.get(domainId, _id);
|
const original = await ProblemModel.get(domainId, _id);
|
||||||
if (!original) throw new ProblemNotFoundError(domainId, _id);
|
if (!original) throw new ProblemNotFoundError(domainId, _id);
|
||||||
if (pid && await ProblemModel.get(target, pid)) pid = '';
|
if (pid && (/^[0-9]+$/.test(pid) || await ProblemModel.get(target, pid))) pid = '';
|
||||||
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
|
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
|
||||||
const docId = await ProblemModel.add(
|
const docId = await ProblemModel.add(
|
||||||
target, pid, original.title, original.content,
|
target, pid, original.title, original.content,
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ const scripts: UpgradeScript[] = [
|
|||||||
pids.push(pdoc.docId);
|
pids.push(pdoc.docId);
|
||||||
await RecordModel.updateMulti(
|
await RecordModel.updateMulti(
|
||||||
doc.domainId,
|
doc.domainId,
|
||||||
{ contest: doc.docId },
|
{ contest: doc.docId, pid },
|
||||||
{ pid: pdoc.docId },
|
{ pid: pdoc.docId },
|
||||||
{},
|
{},
|
||||||
{ pdomain: '' },
|
{ pdomain: '' },
|
||||||
@@ -627,6 +627,22 @@ const scripts: UpgradeScript[] = [
|
|||||||
await db.collection('record').updateMany({}, { $unset: { pdomain: '' } });
|
await db.collection('record').updateMany({}, { $unset: { pdomain: '' } });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
async function _52_53() {
|
||||||
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
|
const cursor = db.collection('document').find({ docType: document.TYPE_CONTEST });
|
||||||
|
while (await cursor.hasNext()) {
|
||||||
|
const tdoc = await cursor.next();
|
||||||
|
const pdocs = await problem.getMulti(tdoc.domainId, { docId: { $in: tdoc.pids } }).toArray();
|
||||||
|
if (!pdocs.filter((i) => i.reference).length) continue;
|
||||||
|
const tsdocs = await contest.getMultiStatus(tdoc.domainId, { docId: tdoc.docId }).toArray();
|
||||||
|
for (const tsdoc of tsdocs) {
|
||||||
|
for (const tsrdoc of tsdoc.journal) {
|
||||||
|
await RecordModel.coll.updateOne({ _id: tsrdoc.rid }, { pid: tsrdoc.pid });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default scripts;
|
export default scripts;
|
||||||
Reference in new issue
Block a user