-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure BioCollect associated orgs use org name to preserve behaviour #…
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load('../../utils/audit.js'); | ||
let projects = db.project.find({status:{$ne:'deleted'}, associatedOrgs:{$exists:true}, isMERIT:false}); | ||
while (projects.hasNext()) { | ||
let changed = false; | ||
|
||
let project = projects.next(); | ||
let associatedOrgs = project.associatedOrgs; | ||
if (associatedOrgs) { | ||
for (let i = 0; i < associatedOrgs.length; i++) { | ||
if (associatedOrgs[i].organisationId) { | ||
let org = db.organisation.findOne({organisationId: associatedOrgs[i].organisationId}); | ||
if (org) { | ||
if (org.name != associatedOrgs[i].name) { | ||
print("Updating associated org for project " + project.projectId + " from " + associatedOrgs[i].name + " to " + org.name); | ||
associatedOrgs[i].name = org.name; | ||
changed = true; | ||
} | ||
} else { | ||
print("No organisation found for associated org " + associatedOrgs[i].organisationId + " in project " + project.projectId); | ||
} | ||
|
||
} | ||
} | ||
if (changed) { | ||
db.project.replaceOne({projectId: project.projectId}, project); | ||
audit(project, project.projectId, 'au.org.ala.ecodata.Project', 'system'); | ||
} | ||
|
||
} | ||
} |