@@ -5,19 +5,18 @@ const _ = require('lodash');
55const fs = require ( 'fs' ) ;
66const request = require ( 'request' ) ;
77const copyCommunityWithEverything = require ( '../utils/copy_utils' ) . copyCommunityWithEverything ;
8+ const updateTranslation = require ( '../active-citizen/utils/translation_helpers' ) . updateTranslation ;
89
910const domainId = process . argv [ 2 ] ;
1011const userId = process . argv [ 3 ] ;
1112const urlToConfig = process . argv [ 4 ] ;
1213const urlToAddAddFront = process . argv [ 5 ] ;
1314
14- /*
15- const domainId = "3"; //process.argv[2];
15+ /*const domainId = "3"; //process.argv[2];
1616const 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 } )
0 commit comments