Skip to content

Commit

Permalink
Script to add service labels to new programs #3030
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Nov 27, 2023
1 parent ad784fb commit 0321e0f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/scripts/releases/3.1/adhoc/addNhtLabelsToNewPrograms.js
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);
}

0 comments on commit 0321e0f

Please sign in to comment.