overleaf/services/web/scripts/backfill_deleted_project_ids.js
Simon Detheridge d7bee9a7d8 Merge pull request #2014 from overleaf/spd-deleted-project-collab-ids
Store and backfill collaborator and overleaf history IDs in deleted projects

GitOrigin-RevId: 34950e29d6910c22f1f6f153f8035a96a1ea8360
2019-07-26 14:39:18 +00:00

57 lines
1.8 KiB
JavaScript

const { DeletedProject } = require('../app/src/models/DeletedProject')
const Async = require('async')
DeletedProject.find({}, (error, deletedProjects) => {
if (error) {
throw error
}
Async.eachLimit(
deletedProjects,
10,
(deletedProject, cb) => {
if (deletedProject.project) {
const src = deletedProject.project
DeletedProject.findOneAndUpdate(
{ _id: deletedProject._id },
{
$set: {
'deleterData.deletedProjectId': src._id,
'deleterData.deletedProjectOwnerId': src.owner_ref,
'deleterData.deletedProjectCollaboratorIds':
src.collaberator_refs,
'deleterData.deletedProjectReadOnlyIds': src.readOnly_refs,
'deleterData.deletedProjectReadWriteToken': src.tokens
? src.tokens.readAndWrite
: undefined,
'deleterData.deletedProjectOverleafId': src.overleaf
? src.overleaf.id
: undefined,
'deleterData.deletedProjectOverleafHistoryId':
src.overleaf && src.overleaf.history
? src.overleaf.history.id
: undefined,
'deleterData.deletedProjectReadOnlyToken': src.tokens
? src.tokens.readOnly
: undefined,
'deleterData.deletedProjectReadWriteTokenAccessIds':
src.tokenAccessReadOnly_refs,
'deleterData.deletedProjectReadOnlyTokenAccessIds':
src.tokenAccessReadAndWrite_refs,
'deleterData.deletedProjectLastUpdatedAt': src.lastUpdated
}
},
cb
)
} else {
cb()
}
},
err => {
if (err) {
throw err
}
process.exit(0)
}
)
})