Skip to content

Commit b9d7062

Browse files
committed
Work on scripts
1 parent 37434d0 commit b9d7062

File tree

5 files changed

+60
-36
lines changed

5 files changed

+60
-36
lines changed

server_api/active-citizen

server_api/scripts/cloneFromUrlScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async.series([
3333
if (!configLine || configLine.length<3) {
3434
forEachCallback();u
3535
} else {
36-
copyCommunityWithEverything(communityId, domainId, (error, community) => {
36+
copyCommunityWithEverything(communityId, domainId, {}, (error, community) => {
3737
if (error) {
3838
forEachCallback(error);
3939
} else {

server_api/scripts/cloneWBFromUrlScriptAndCreateLinks.js

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ const _ = require('lodash');
55
const fs = require('fs');
66
const request = require('request');
77
const copyCommunityWithEverything = require('../utils/copy_utils').copyCommunityWithEverything;
8+
const updateTranslation = require('../active-citizen/utils/translation_helpers').updateTranslation;
89

910
const domainId = process.argv[2];
1011
const userId = process.argv[3];
1112
const urlToConfig = process.argv[4];
1213
const urlToAddAddFront = process.argv[5];
1314

14-
/*
15-
const domainId = "3"; //process.argv[2];
15+
/*const domainId = "3"; //process.argv[2];
1616
const userId = "850" //process.argv[3];
17-
const urlToConfig = "https://yrpri-eu-direct-assets.s3-eu-west-1.amazonaws.com/CF_clone_WB_140221.csv";// process.argv[4];
17+
const urlToConfig = "https://yrpri-eu-direct-assets.s3-eu-west-1.amazonaws.com/ClonesARIS01.03-CFEdit.xlsx+-+OSH.csv";// process.argv[4];
1818
//const urlToAddAddFront = "https://kyrgyz-aris.yrpri.org/";
19-
const urlToAddAddFront = "http://localhost:4242/"; //process.argv[5];
20-
*/
19+
const urlToAddAddFront = "http://localhost:4242/"; //process.argv[5];*/
2120

2221
// node server_api/scripts/cloneWBFromUrlScriptAndCreateLinks.js 3 84397 https://yrpri-eu-direct-assets.s3-eu-west-1.amazonaws.com/CF_clone_WB_140221.csv https://kyrgyz-aris.yrpri.org/
2322

@@ -41,15 +40,21 @@ async.series([
4140
});
4241
},
4342
(seriesCallback) => {
43+
let index = 0;
4444
async.forEachSeries(config.split('\r\n'), (configLine, forEachCallback) => {
4545
const splitLine = configLine.split(",");
4646

47-
if (!configLine || configLine.length<3 || !splitLine || splitLine.length!==2) {
47+
if (index==0 || !configLine || configLine.length<3 || !splitLine || splitLine.length!==5 || splitLine[0].length<2) {
48+
index+=1;
4849
forEachCallback();
4950
} else {
5051
const fromCommunityId = splitLine[0];
5152
const linkToCommunityId = splitLine[1];
52-
copyCommunityWithEverything(fromCommunityId, domainId, (error, newCommunity) => {
53+
const englishName = splitLine[2].trim();
54+
const russianName = splitLine[3].trim();
55+
const kyrgyzName = splitLine[4].trim();
56+
57+
copyCommunityWithEverything(fromCommunityId, domainId, {}, (error, newCommunity) => {
5358
if (error) {
5459
forEachCallback(error);
5560
} else {
@@ -60,39 +65,58 @@ async.series([
6065
attributes: ['id','name']
6166
}).then( linkCommunity => {
6267
newCommunity.hostname = newCommunity.hostname+"-"+newCommunity.id;
68+
newCommunity.name = russianName;
69+
newCommunity.language = "ru";
6370
newCommunity.save().then(() => {
6471
newCommunity.set('configuration.customBackURL', linkToCommunityId);
6572
newCommunity.set('configuration.customBackName', linkCommunity.name);
6673
newCommunity.save().then(() => {
67-
console.log(newCommunity.id);
68-
finalOutput+=urlToAddAddFront+"community/"+newCommunity.id+"\n";
69-
finalTargetOutput+=urlToAddAddFront+"community/"+linkToCommunityId+"\n";
7074

71-
const linkModel = models.Group.build({
72-
name: "Link for community - "+linkToCommunityId,
73-
description: "",
74-
access: models.Group.ACCESS_PUBLIC,
75-
user_id: userId,
76-
configuration: { actAsLinkToCommunityId: newCommunity.id },
77-
community_id: linkToCommunityId
78-
});
79-
linkModel.save().then((model) => {
80-
models.User.findOne({
81-
where: {
82-
id: userId
83-
}
84-
}).then(user=>{
85-
linkModel.addGroupAdmin(user).then(function () {
86-
forEachCallback();
87-
}).catch((error)=>{
75+
updateTranslation({
76+
contentId: newCommunity.id,
77+
textType: "communityName",
78+
targetLocale: "en",
79+
content: russianName,
80+
translatedText: englishName
81+
}, (error) => {
82+
updateTranslation({
83+
contentId: newCommunity.id,
84+
textType: "communityName",
85+
targetLocale: "ky",
86+
content: russianName,
87+
translatedText: kyrgyzName
88+
}, (error) => {
89+
console.log(newCommunity.id);
90+
finalOutput+=urlToAddAddFront+"community/"+newCommunity.id+"\n";
91+
finalTargetOutput+=urlToAddAddFront+"community/"+linkToCommunityId+"\n";
92+
93+
const linkModel = models.Group.build({
94+
name: "Link for community - "+linkToCommunityId,
95+
description: "",
96+
access: models.Group.ACCESS_PUBLIC,
97+
user_id: userId,
98+
configuration: { actAsLinkToCommunityId: newCommunity.id },
99+
community_id: linkToCommunityId
100+
});
101+
linkModel.save().then((model) => {
102+
models.User.findOne({
103+
where: {
104+
id: userId
105+
}
106+
}).then(user=>{
107+
linkModel.addGroupAdmin(user).then(function () {
108+
forEachCallback();
109+
}).catch((error)=>{
110+
forEachCallback(error);
111+
});
112+
}).catch(error=>{
113+
forEachCallback(error);
114+
})
115+
}).catch( error => {
88116
forEachCallback(error);
89117
});
90-
}).catch(error=>{
91-
forEachCallback(error);
92118
})
93-
}).catch( error => {
94-
forEachCallback(error);
95-
});
119+
})
96120
}).catch(error=>{
97121
forEachCallback(error);
98122
})

server_api/scripts/copyCommunityToDomainWithEverything.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ip = require('ip');
99
const communityId = process.argv[2];
1010
var domainId = process.argv[3];
1111

12-
copyCommunityWithEverything(communityId, domainId, (error) => {
12+
copyCommunityWithEverything(communityId, domainId, {}, (error) => {
1313
if (error) {
1414
console.error(error);
1515
} else {

server_api/utils/copy_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ const copyCommunity = (fromCommunityId, toDomainId, options, done) => {
957957
});
958958
};
959959

960-
const copyCommunityWithEverything = (communityId, toDomainId, done) => {
960+
const copyCommunityWithEverything = (communityId, toDomainId, options, done) => {
961961
copyCommunity(communityId, toDomainId, {
962962
copyGroups: true,
963963
copyPosts: true,

0 commit comments

Comments
 (0)