overleaf/services/web/scripts/restore_soft_deleted_docs.mjs
Jakob Ackermann a7517eefcb Merge pull request #21427 from overleaf/jpa-populate-db-on-import
[web] populate db with collections on import, ahead of waitForDb() call

GitOrigin-RevId: 7eb4cd61c2052187acd9947d7060f54d9822d314
2024-11-01 09:05:15 +00:00

32 lines
881 B
JavaScript

import ProjectEntityRestoreHandler from '../app/src/Features/Project/ProjectEntityRestoreHandler.js'
import DocstoreManager from '../app/src/Features/Docstore/DocstoreManager.js'
const ARGV = process.argv.slice(2)
const DEVELOPER_USER_ID = ARGV.shift()
const PROJECT_ID = ARGV.shift()
const FILE_NAMES_TO_RESTORE = ARGV
async function main() {
const deletedDocs =
await DocstoreManager.promises.getAllDeletedDocs(PROJECT_ID)
const docsToRestore = deletedDocs.filter(doc =>
FILE_NAMES_TO_RESTORE.includes(doc.name)
)
for (const deletedDoc of docsToRestore) {
const newDoc = await ProjectEntityRestoreHandler.promises.restoreDeletedDoc(
PROJECT_ID,
deletedDoc._id,
deletedDoc.name,
DEVELOPER_USER_ID
)
console.log(newDoc)
}
}
try {
await main()
process.exit(0)
} catch (error) {
console.error(error)
process.exit(1)
}