-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to add service labels to new programs #3030
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/scripts/releases/3.1/adhoc/addNhtLabelsToNewPrograms.js
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,28 @@ | ||
const programs = [ | ||
'Priority Species - Procurements', | ||
'World Heritage Protection', | ||
'Ramsar Wetland Protection', | ||
'Priority Places', | ||
'Priority Species', | ||
'Saving Native Species' | ||
]; | ||
var programToCopyLabels = db.program.findOne({name:'Recovery Actions for Species and Landscapes'}); | ||
|
||
let services = db.service.find({programLabels:{$ne:null}}); | ||
while(services.hasNext()) { | ||
let service = services.next(); | ||
let label = service.programLabels[programToCopyLabels.programId]; | ||
|
||
if (!label) { | ||
print("No label found for service " + service.name); | ||
printjson(service); | ||
throw "Help!"; | ||
} | ||
|
||
for (let i=0; i<programs.length; i++) { | ||
let program = db.program.findOne({name:programs[i]}); | ||
service.programLabels[program.programId] = {label:label.label}; | ||
print("Updating label for service " + service.name + " to " + label.label); | ||
} | ||
db.service.replaceOne({_id:service._id}, service); | ||
} |