1 |
56175
|
konstantin
|
//version compatibility: 1.1.1-SNAPSHOT
|
2 |
|
|
print("migrateCommunityIn_db script running...");
|
3 |
|
|
|
4 |
59470
|
konstantin
|
function migrate_portal(portalPid, beta_db_name, prod_db_name) {
|
5 |
56175
|
konstantin
|
beta_db = db.getSiblingDB(beta_db_name);
|
6 |
60033
|
konstantin
|
// db.auth("your_username", "your_password");
|
7 |
56175
|
konstantin
|
prod_db = db.getSiblingDB(prod_db_name);
|
8 |
60033
|
konstantin
|
// db.auth("your_username", "your_password");
|
9 |
56175
|
konstantin
|
|
10 |
59470
|
konstantin
|
print("migrate_portal: "+portalPid+" - both dbs are here");
|
11 |
56175
|
konstantin
|
|
12 |
59470
|
konstantin
|
var beta_portal = beta_db.portal.findOne({ pid: portalPid } );
|
13 |
56175
|
konstantin
|
|
14 |
59470
|
konstantin
|
if(!beta_portal) {
|
15 |
|
|
print("ERROR: Portal with pid: "+portalPid+" does not exist in (beta) database: "+ beta_db_name);
|
16 |
56175
|
konstantin
|
return;
|
17 |
|
|
}
|
18 |
|
|
|
19 |
59470
|
konstantin
|
var prod_portalOld = prod_db.portal.findOne( { pid: portalPid } );
|
20 |
|
|
var prod_portalOldId;
|
21 |
|
|
if(prod_portalOld) {
|
22 |
|
|
prod_portalOldId = prod_portalOld._id.str;
|
23 |
56175
|
konstantin
|
}
|
24 |
|
|
|
25 |
59470
|
konstantin
|
// delete portal from production db
|
26 |
|
|
prod_db.portal.remove({"pid" : portalPid});
|
27 |
|
|
print("Portal with pid: "+portalPid+" is deleted (if existed) from production db: "+prod_db_name);
|
28 |
56175
|
konstantin
|
|
29 |
59470
|
konstantin
|
// migrate portal pages
|
30 |
|
|
//beta_portal_pages = beta_db.portal.findOne({ pid: portalPid } ).map( function(portal) { return portal.pages } );
|
31 |
|
|
var beta_portal_pages = beta_portal.pages;
|
32 |
|
|
var prod_portal_pages = {}
|
33 |
|
|
for (var beta_pageId in beta_portal_pages) {
|
34 |
56175
|
konstantin
|
var beta_pageObjectId = ObjectId(beta_pageId);
|
35 |
59470
|
konstantin
|
//var prod_pageId = prod_db.portal.find( { route: beta_db.page.find( { _id: beta_pageObjectId }).map( function(page) { return page.route; } ).toString() });
|
36 |
56175
|
konstantin
|
var beta_page = beta_db.page.findOne( { _id: beta_pageObjectId } );
|
37 |
|
|
if(beta_page) {
|
38 |
59470
|
konstantin
|
var prod_page = prod_db.page.findOne( { route: beta_page.route, portalType: beta_page.portalType } );
|
39 |
56175
|
konstantin
|
if(prod_page) {
|
40 |
59470
|
konstantin
|
prod_portal_pages[prod_page._id.str] = beta_portal_pages[beta_pageId];
|
41 |
56175
|
konstantin
|
} else {
|
42 |
|
|
print("\nERROR: Page with route: "+beta_page.route+" does not exist on production db: "+prod_db_name+"\n");
|
43 |
|
|
}
|
44 |
|
|
} else {
|
45 |
|
|
print("\nERROR: Page with id: "+beta_pageId+" does not exist on beta db: "+beta_db_name+"\n");
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
59470
|
konstantin
|
print("Portal pages are ready to be migrated");
|
49 |
56175
|
konstantin
|
|
50 |
59470
|
konstantin
|
// migrate portal entities
|
51 |
|
|
var beta_portal_entities = beta_portal.entities;
|
52 |
|
|
var prod_portal_entities = {}
|
53 |
|
|
for (var beta_entityId in beta_portal_entities) {
|
54 |
56175
|
konstantin
|
var beta_entityObjectId = ObjectId(beta_entityId);
|
55 |
|
|
var beta_entity = beta_db.entity.findOne( { _id: beta_entityObjectId } );
|
56 |
|
|
if(beta_entity) {
|
57 |
|
|
var prod_entity = prod_db.entity.findOne( { pid: beta_entity.pid } );
|
58 |
|
|
if(prod_entity) {
|
59 |
59470
|
konstantin
|
prod_portal_entities[prod_entity._id.str] = beta_portal_entities[beta_entityId];
|
60 |
56175
|
konstantin
|
} else {
|
61 |
|
|
print("\nERROR: Entity with pid: "+beta_entity.pid+" does not exist on production db: "+prod_db_name+"\n");
|
62 |
|
|
}
|
63 |
|
|
} else {
|
64 |
|
|
print("\nERROR: Entity with id: "+beta_entityId+" does not exist on beta db: "+beta_db_name+"\n");
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
59470
|
konstantin
|
print("Portal entities are ready to be migrated");
|
69 |
56175
|
konstantin
|
|
70 |
59470
|
konstantin
|
prod_db.portal.save({
|
71 |
|
|
"name" : beta_portal.name, "pid" : portalPid, "type": beta_portal.type,
|
72 |
|
|
"pages" : prod_portal_pages, "entities" : prod_portal_entities
|
73 |
|
|
});
|
74 |
56175
|
konstantin
|
|
75 |
59470
|
konstantin
|
print("Portal is migrated");
|
76 |
56175
|
konstantin
|
|
77 |
59470
|
konstantin
|
// delete portal statistics from production db
|
78 |
|
|
prod_db.statistics.remove({"pid" : portalPid});
|
79 |
|
|
print("Statistics for portal with pid: "+portalPid+" are deleted (if existed) from production db: "+prod_db_name);
|
80 |
|
|
// migrate statistics for portal
|
81 |
|
|
var beta_statistics = beta_db.statistics.findOne({ pid: portalPid } );
|
82 |
56175
|
konstantin
|
prod_db.statistics.save(beta_statistics);
|
83 |
|
|
|
84 |
59470
|
konstantin
|
print("Statistics for portal were migrated");
|
85 |
56175
|
konstantin
|
|
86 |
59470
|
konstantin
|
// migrate subscribers of portal
|
87 |
|
|
var beta_portalSubscr = beta_db.portalSubscribers.findOne({ pid: portalPid } );
|
88 |
|
|
if(beta_portalSubscr) {
|
89 |
|
|
var beta_portalSubscribers = beta_portalSubscr.subscribers;
|
90 |
|
|
var prod_portalSubscribers = [];
|
91 |
|
|
var prod_portalSubscribersEmails = [];
|
92 |
|
|
var prod_portalSubscr = prod_db.portalSubscribers.findOne({ "pid" : portalPid });
|
93 |
|
|
if(prod_portalSubscr) {
|
94 |
|
|
prod_portalSubscribers = prod_portalSubscr.subscribers;
|
95 |
|
|
prod_portalSubscribersEmails = prod_portalSubscr.subscribers.map(function(subscriber){return subscriber.email});
|
96 |
56175
|
konstantin
|
}
|
97 |
|
|
|
98 |
59470
|
konstantin
|
beta_portalSubscribers.forEach(function(beta_portalSubscriber) {
|
99 |
|
|
var addInPortal = true;
|
100 |
56175
|
konstantin
|
|
101 |
59470
|
konstantin
|
// if user exists in portal subscribers already, do nothing
|
102 |
|
|
if(prod_portalSubscribersEmails.indexOf(beta_portalSubscriber.email) >= 0) {
|
103 |
|
|
addInPortal = false;
|
104 |
56175
|
konstantin
|
} else {
|
105 |
59470
|
konstantin
|
var prod_subscriber = prod_db.subscriber.findOne({email: beta_portalSubscriber.email});
|
106 |
56175
|
konstantin
|
|
107 |
|
|
// if subscriber of beta does not exist in production, add him
|
108 |
|
|
if(!prod_subscriber) {
|
109 |
59470
|
konstantin
|
prod_subscriber = {email: beta_portalSubscriber.email};
|
110 |
56175
|
konstantin
|
prod_db.subscriber.save(prod_subscriber);
|
111 |
59470
|
konstantin
|
print("subscriber "+beta_portalSubscriber.email+" added in production DB");
|
112 |
56175
|
konstantin
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
59470
|
konstantin
|
if(addInPortal) {
|
116 |
|
|
var prod_portalSubscriber = prod_db.subscriber.findOne({email: beta_portalSubscriber.email});
|
117 |
|
|
prod_portalSubscribers.push(prod_portalSubscriber);
|
118 |
56175
|
konstantin
|
}
|
119 |
|
|
})
|
120 |
59470
|
konstantin
|
if(prod_portalSubscr) {
|
121 |
|
|
prod_db.portalSubscribers.update({ "pid" : portalPid } , {$set: {subscribers : prod_portalSubscribers}});
|
122 |
56175
|
konstantin
|
} else {
|
123 |
59470
|
konstantin
|
prod_db.portalSubscribers.insert({ "pid" : portalPid, "subscribers" : prod_portalSubscribers });
|
124 |
56175
|
konstantin
|
}
|
125 |
|
|
|
126 |
59470
|
konstantin
|
print("subscribers of portal were migrated");
|
127 |
56175
|
konstantin
|
} else {
|
128 |
59470
|
konstantin
|
print("\nERROR: Subscribers not migrated. No PortalSubscribers for this portal on beta db: "+beta_db_name+"\n");
|
129 |
56175
|
konstantin
|
}
|
130 |
|
|
|
131 |
59470
|
konstantin
|
// migrate divHelpContents of portal
|
132 |
|
|
var beta_portalId = beta_portal._id.str;//beta_db.portal.findOne( { pid: portalPid } )._id.str;
|
133 |
|
|
var prod_portalId = prod_db.portal.findOne( { pid: portalPid })._id.str;
|
134 |
56175
|
konstantin
|
|
135 |
59470
|
konstantin
|
if(prod_portalOldId) {
|
136 |
|
|
prod_db.divHelpContent.remove({"portal": prod_portalOldId});
|
137 |
56175
|
konstantin
|
}
|
138 |
|
|
//var beta_divHelpContents =
|
139 |
59470
|
konstantin
|
beta_db.divHelpContent.find( { portal: beta_portalId } ).forEach(function(beta_divHelpContent){//.map( function(divHelpContent) { return divHelpContent; } );
|
140 |
56175
|
konstantin
|
//for (var beta_divHelpContent in beta_divHelpContents) {
|
141 |
|
|
var beta_beta_divHelpContent_divId_ObjectId = ObjectId(beta_divHelpContent.divId);
|
142 |
|
|
var beta_divId = beta_db.divId.findOne( { _id: beta_beta_divHelpContent_divId_ObjectId } );//.name;;
|
143 |
|
|
if(beta_divId) {
|
144 |
59470
|
konstantin
|
var prod_divId = prod_db.divId.findOne( { name: beta_divId.name, portalType: beta_divId.portalType } );//._id.str;
|
145 |
56175
|
konstantin
|
if(prod_divId) {
|
146 |
59470
|
konstantin
|
prod_db.divHelpContent.save({ "divId" : prod_divId._id.str, "portal" : prod_portalId, "content" : beta_divHelpContent.content, "isActive" : beta_divHelpContent.isActive });
|
147 |
56175
|
konstantin
|
} else {
|
148 |
|
|
print("\nERROR: DivId with name: "+beta_divId.name+" does not exist on production db: "+prod_db_name+"\n");
|
149 |
|
|
}
|
150 |
|
|
} else {
|
151 |
|
|
print("\nERROR: DivId with id: "+beta_divHelpContent.divId+" (of divHelpContent: "+beta_divHelpContent._id.str+") does not exist on beta db: "+beta_db_name+"\n");
|
152 |
|
|
}
|
153 |
|
|
//}
|
154 |
|
|
});
|
155 |
|
|
|
156 |
59470
|
konstantin
|
print("divHelpContents of portal were migrated");
|
157 |
56175
|
konstantin
|
|
158 |
59470
|
konstantin
|
// migrate pageHelpContents of portal
|
159 |
|
|
if(prod_portalOldId) {
|
160 |
|
|
prod_db.pageHelpContent.remove({"portal": prod_portalOldId});
|
161 |
56175
|
konstantin
|
}
|
162 |
59470
|
konstantin
|
beta_db.pageHelpContent.find( { portal: beta_portalId } ).forEach(function(beta_pageHelpContent){
|
163 |
56175
|
konstantin
|
var beta_beta_pageHelpContent_page_ObjectId = ObjectId(beta_pageHelpContent.page);
|
164 |
|
|
var beta_page = beta_db.page.findOne( { _id: beta_beta_pageHelpContent_page_ObjectId } );//.route;
|
165 |
|
|
if(beta_page) {
|
166 |
59470
|
konstantin
|
var prod_page = prod_db.page.findOne( { route: beta_page.route, portalType: beta_page.portalType } );//._id.str;
|
167 |
56175
|
konstantin
|
if(prod_page) {
|
168 |
59470
|
konstantin
|
prod_db.pageHelpContent.save({ "page" : prod_page._id.str, "portal" : prod_portalId, "content" : beta_pageHelpContent.content, "placement": beta_pageHelpContent.placement, "order": beta_pageHelpContent.order, "isActive": beta_pageHelpContent.isActive, "isPriorTo": beta_pageHelpContent.isPriorTo });
|
169 |
56175
|
konstantin
|
} else {
|
170 |
|
|
print("\nERROR: Page with route: "+beta_page.route+" does not exist on production db: "+prod_db_name+"\n");
|
171 |
|
|
}
|
172 |
|
|
} else {
|
173 |
|
|
print("\nERROR: Page with id: "+beta_pageHelpContent.page+" (of pageHelpContent: "+beta_pageHelpContent._id.str+") does not exist on beta db: "+beta_db_name+"\n");
|
174 |
|
|
}
|
175 |
|
|
});
|
176 |
|
|
|
177 |
59470
|
konstantin
|
print("pageHelpContents of portal were migrated");
|
178 |
56175
|
konstantin
|
|
179 |
59470
|
konstantin
|
// migrate notifications preferences of portal
|
180 |
|
|
var prod_notifications = prod_db.notifications.find({ portalPid: portalPid } );
|
181 |
56175
|
konstantin
|
var prod_notifications_emails = [];
|
182 |
|
|
if(prod_notifications) {
|
183 |
|
|
prod_notifications_emails = prod_notifications.map(function(preference){return preference.managerEmail;})
|
184 |
|
|
}
|
185 |
|
|
|
186 |
59470
|
konstantin
|
beta_db.notifications.find({ portalPid: portalPid } ).forEach(function(preference){
|
187 |
56175
|
konstantin
|
if(prod_notifications_emails.indexOf(preference.managerEmail) >= 0) {
|
188 |
59470
|
konstantin
|
prod_db.notifications.update({ managerEmail: preference.managerEmail, portalPid: portalPid }, {$set: {notifyForNewManagers: preference.notifyForNewManagers, notifyForNewSubscribers: preference.notifyForNewSubscribers}})
|
189 |
56175
|
konstantin
|
} else {
|
190 |
|
|
prod_db.notifications.insert(preference);
|
191 |
|
|
}
|
192 |
|
|
});
|
193 |
|
|
|
194 |
59470
|
konstantin
|
print("Notification preferences of portal were migrated");
|
195 |
56175
|
konstantin
|
|
196 |
|
|
}
|
197 |
|
|
|
198 |
60497
|
konstantin
|
function migrateCurators(beta_db_name, prod_db_name) {
|
199 |
|
|
beta_db = db.getSiblingDB(beta_db_name);
|
200 |
|
|
// beta_db.auth("your_username", "your_password");
|
201 |
56175
|
konstantin
|
|
202 |
60497
|
konstantin
|
prod_db = db.getSiblingDB(prod_db_name);
|
203 |
|
|
// prod_db.auth("your_username", "your_password");
|
204 |
60033
|
konstantin
|
|
205 |
60497
|
konstantin
|
print("migrateCurators: both dbs are here");
|
206 |
60033
|
konstantin
|
|
207 |
60497
|
konstantin
|
// migrate curators of portal
|
208 |
|
|
var beta_curators = beta_db.curator.find().forEach(function(beta_curator) {
|
209 |
|
|
if (beta_curator) {
|
210 |
|
|
prod_db.curator.remove({"email": beta_curator.email});
|
211 |
|
|
curator = {};
|
212 |
|
|
curator['_id'] = beta_curator._id; // this is aaiId
|
213 |
|
|
|
214 |
|
|
if(beta_curator.email) {
|
215 |
|
|
curator['email'] = beta_curator.email;
|
216 |
|
|
} else {
|
217 |
|
|
curator['email'] = "";
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
if(beta_curator.name) {
|
221 |
|
|
curator['name'] = beta_curator.name;
|
222 |
|
|
} else {
|
223 |
|
|
curator['name'] = "";
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
if(beta_curator.affiliations) {
|
227 |
|
|
curator['affiliations'] = beta_curator.affiliations;
|
228 |
|
|
} else {
|
229 |
|
|
curator['affiliations'] = [];
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
if(beta_curator.photo) {
|
233 |
|
|
curator['photo'] = beta_curator.photo;
|
234 |
|
|
} else {
|
235 |
|
|
curator['photo'] = "";
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
if(beta_curator.bio) {
|
239 |
|
|
curator['bio'] = beta_curator.bio;
|
240 |
|
|
} else {
|
241 |
|
|
curator['bio'] = "";
|
242 |
|
|
}
|
243 |
|
|
// prod_db.curator.insert({"email": beta_curator.email,"name": beta_curator.name, "affiliations": beta_curator.affiliations, "photo": beta_curator.photo, "bio": beta_curator.bio});
|
244 |
|
|
prod_db.curator.insert(curator);
|
245 |
|
|
|
246 |
|
|
print("curator "+beta_curator.name + " is migrated");
|
247 |
|
|
}
|
248 |
|
|
});
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
// migrate_portal("aginfra", 'openaireconnect_new', 'openaireconnect');
|
252 |
|
|
// migrate_portal("rural-digital-europe", 'openaireconnect_new', 'openaireconnect');
|
253 |
|
|
// migrate_portal("clarin", 'openaireconnect_new', 'openaireconnect');
|
254 |
|
|
// migrate_portal("enermaps", 'openaireconnect_new', 'openaireconnect');
|
255 |
|
|
// // migrate_portal("ifremer", 'openaireconnect_new', 'openaireconnect');
|
256 |
|
|
// migrate_portal("instruct", 'openaireconnect_new', 'openaireconnect');
|
257 |
|
|
// migrate_portal("risis", 'openaireconnect_new', 'openaireconnect');
|
258 |
|
|
// migrate_portal("rda", 'openaireconnect_new', 'openaireconnect');
|
259 |
|
|
// migrate_portal("science-innovation-policy", 'openaireconnect_new', 'openaireconnect');
|
260 |
|
|
// // migrate_portal("sobigdata", 'openaireconnect_new', 'openaireconnect');
|
261 |
|
|
// migrate_portal("sdsn-gr", 'openaireconnect_new', 'openaireconnect');
|
262 |
|
|
// migrate_portal("elixir-gr", 'openaireconnect_new', 'openaireconnect');
|
263 |
|
|
// migrate_portal("beopen", 'openaireconnect_new', 'openaireconnect');
|
264 |
|
|
// // migrate_portal("euromarine", 'openaireconnect_new', 'openaireconnect');
|
265 |
|
|
// migrate_portal("oa-pg", 'openaireconnect_new', 'openaireconnect');
|
266 |
|
|
//
|
267 |
|
|
//
|
268 |
|
|
// migrate_portal("covid-19", 'openaireconnect_new', 'openaireconnect');
|
269 |
|
|
// migrate_portal("dariah", 'openaireconnect_new', 'openaireconnect');
|
270 |
|
|
// migrate_portal("dh-ch", 'openaireconnect_new', 'openaireconnect');
|
271 |
|
|
// migrate_portal("egi", 'openaireconnect_new', 'openaireconnect');
|
272 |
|
|
// migrate_portal("mes", 'openaireconnect_new', 'openaireconnect');
|
273 |
|
|
// migrate_portal("epos", 'openaireconnect_new', 'openaireconnect');
|
274 |
|
|
// migrate_portal("fam", 'openaireconnect_new', 'openaireconnect');
|
275 |
|
|
// migrate_portal("ni", 'openaireconnect_new', 'openaireconnect');
|
276 |
|
|
//
|
277 |
|
|
|
278 |
|
|
migrateCurators("openaireconnect_new", "openaireconnect");
|