Skip to content

Commit

Permalink
Work on scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rbjarnason committed Mar 2, 2021
1 parent 37434d0 commit b9d7062
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 36 deletions.
2 changes: 1 addition & 1 deletion server_api/active-citizen
2 changes: 1 addition & 1 deletion server_api/scripts/cloneFromUrlScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async.series([
if (!configLine || configLine.length<3) {
forEachCallback();u
} else {
copyCommunityWithEverything(communityId, domainId, (error, community) => {
copyCommunityWithEverything(communityId, domainId, {}, (error, community) => {
if (error) {
forEachCallback(error);
} else {
Expand Down
88 changes: 56 additions & 32 deletions server_api/scripts/cloneWBFromUrlScriptAndCreateLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ const _ = require('lodash');
const fs = require('fs');
const request = require('request');
const copyCommunityWithEverything = require('../utils/copy_utils').copyCommunityWithEverything;
const updateTranslation = require('../active-citizen/utils/translation_helpers').updateTranslation;

const domainId = process.argv[2];
const userId = process.argv[3];
const urlToConfig = process.argv[4];
const urlToAddAddFront = process.argv[5];

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

// 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/

Expand All @@ -41,15 +40,21 @@ async.series([
});
},
(seriesCallback) => {
let index = 0;
async.forEachSeries(config.split('\r\n'), (configLine, forEachCallback) => {
const splitLine = configLine.split(",");

if (!configLine || configLine.length<3 || !splitLine || splitLine.length!==2) {
if (index==0 || !configLine || configLine.length<3 || !splitLine || splitLine.length!==5 || splitLine[0].length<2) {
index+=1;
forEachCallback();
} else {
const fromCommunityId = splitLine[0];
const linkToCommunityId = splitLine[1];
copyCommunityWithEverything(fromCommunityId, domainId, (error, newCommunity) => {
const englishName = splitLine[2].trim();
const russianName = splitLine[3].trim();
const kyrgyzName = splitLine[4].trim();

copyCommunityWithEverything(fromCommunityId, domainId, {}, (error, newCommunity) => {
if (error) {
forEachCallback(error);
} else {
Expand All @@ -60,39 +65,58 @@ async.series([
attributes: ['id','name']
}).then( linkCommunity => {
newCommunity.hostname = newCommunity.hostname+"-"+newCommunity.id;
newCommunity.name = russianName;
newCommunity.language = "ru";
newCommunity.save().then(() => {
newCommunity.set('configuration.customBackURL', linkToCommunityId);
newCommunity.set('configuration.customBackName', linkCommunity.name);
newCommunity.save().then(() => {
console.log(newCommunity.id);
finalOutput+=urlToAddAddFront+"community/"+newCommunity.id+"\n";
finalTargetOutput+=urlToAddAddFront+"community/"+linkToCommunityId+"\n";

const linkModel = models.Group.build({
name: "Link for community - "+linkToCommunityId,
description: "",
access: models.Group.ACCESS_PUBLIC,
user_id: userId,
configuration: { actAsLinkToCommunityId: newCommunity.id },
community_id: linkToCommunityId
});
linkModel.save().then((model) => {
models.User.findOne({
where: {
id: userId
}
}).then(user=>{
linkModel.addGroupAdmin(user).then(function () {
forEachCallback();
}).catch((error)=>{
updateTranslation({
contentId: newCommunity.id,
textType: "communityName",
targetLocale: "en",
content: russianName,
translatedText: englishName
}, (error) => {
updateTranslation({
contentId: newCommunity.id,
textType: "communityName",
targetLocale: "ky",
content: russianName,
translatedText: kyrgyzName
}, (error) => {
console.log(newCommunity.id);
finalOutput+=urlToAddAddFront+"community/"+newCommunity.id+"\n";
finalTargetOutput+=urlToAddAddFront+"community/"+linkToCommunityId+"\n";

const linkModel = models.Group.build({
name: "Link for community - "+linkToCommunityId,
description: "",
access: models.Group.ACCESS_PUBLIC,
user_id: userId,
configuration: { actAsLinkToCommunityId: newCommunity.id },
community_id: linkToCommunityId
});
linkModel.save().then((model) => {
models.User.findOne({
where: {
id: userId
}
}).then(user=>{
linkModel.addGroupAdmin(user).then(function () {
forEachCallback();
}).catch((error)=>{
forEachCallback(error);
});
}).catch(error=>{
forEachCallback(error);
})
}).catch( error => {
forEachCallback(error);
});
}).catch(error=>{
forEachCallback(error);
})
}).catch( error => {
forEachCallback(error);
});
})
}).catch(error=>{
forEachCallback(error);
})
Expand Down
2 changes: 1 addition & 1 deletion server_api/scripts/copyCommunityToDomainWithEverything.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ip = require('ip');
const communityId = process.argv[2];
var domainId = process.argv[3];

copyCommunityWithEverything(communityId, domainId, (error) => {
copyCommunityWithEverything(communityId, domainId, {}, (error) => {
if (error) {
console.error(error);
} else {
Expand Down
2 changes: 1 addition & 1 deletion server_api/utils/copy_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ const copyCommunity = (fromCommunityId, toDomainId, options, done) => {
});
};

const copyCommunityWithEverything = (communityId, toDomainId, done) => {
const copyCommunityWithEverything = (communityId, toDomainId, options, done) => {
copyCommunity(communityId, toDomainId, {
copyGroups: true,
copyPosts: true,
Expand Down

0 comments on commit b9d7062

Please sign in to comment.