mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
Revert "Revert "clear rootDoc_id when deleting doc, reset on compiles if invalid""
This reverts commit 7acba5876581044a08d6deb4767a4a2196dcb765. GitOrigin-RevId: 034ae6fa4d8515944683395ef14d99801829cb6a
This commit is contained in:
@@ -314,8 +314,9 @@ async function moveEntity(projectId, entityId, destFolderId, entityType) {
|
||||
async function deleteEntity(projectId, entityId, entityType, callback) {
|
||||
const project = await ProjectGetter.promises.getProjectWithoutLock(
|
||||
projectId,
|
||||
{ name: true, rootFolder: true, overleaf: true }
|
||||
{ name: true, rootFolder: true, overleaf: true, rootDoc_id: true }
|
||||
)
|
||||
const deleteRootDoc = project.rootDoc_id && entityId && project.rootDoc_id.toString() === entityId.toString()
|
||||
const { element: entity, path } = await ProjectLocator.promises.findElement({
|
||||
project,
|
||||
element_id: entityId,
|
||||
@@ -325,7 +326,8 @@ async function deleteEntity(projectId, entityId, entityType, callback) {
|
||||
Project,
|
||||
projectId,
|
||||
path.mongo,
|
||||
entityId
|
||||
entityId,
|
||||
deleteRootDoc
|
||||
)
|
||||
return { entity, path, projectBeforeDeletion: project, newProject }
|
||||
}
|
||||
@@ -414,19 +416,18 @@ async function _insertDeletedFileReference(projectId, fileRef) {
|
||||
).exec()
|
||||
}
|
||||
|
||||
async function _removeElementFromMongoArray(model, modelId, path, elementId) {
|
||||
async function _removeElementFromMongoArray(model, modelId, path, elementId, deleteRootDoc=false) {
|
||||
const nonArrayPath = path.slice(0, path.lastIndexOf('.'))
|
||||
const newDoc = model
|
||||
.findOneAndUpdate(
|
||||
{ _id: modelId },
|
||||
{
|
||||
$pull: { [nonArrayPath]: { _id: elementId } },
|
||||
$inc: { version: 1 }
|
||||
},
|
||||
{ new: true }
|
||||
)
|
||||
.exec()
|
||||
return newDoc
|
||||
const options = { new: true }
|
||||
const query = { _id: modelId }
|
||||
const update = {
|
||||
$pull: { [nonArrayPath]: { _id: elementId } },
|
||||
$inc: { version: 1 }
|
||||
}
|
||||
if (deleteRootDoc) {
|
||||
update.$unset = { rootDoc_id: 1 }
|
||||
}
|
||||
return model.findOneAndUpdate(query, update, options).exec()
|
||||
}
|
||||
|
||||
function _countElements(project) {
|
||||
|
||||
Reference in New Issue
Block a user