@yrpri/api 9.0.101 → 9.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +11 -1
- package/active-citizen/llms/baseChatBot.js +8 -75
- package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
- package/agents/assistants/agentAssistant.js +3 -2
- package/agents/assistants/baseAssistant.js +7 -30
- package/agents/assistants/baseAssistantWithVoice.js +3 -3
- package/agents/assistants/voiceAssistant.js +2 -2
- package/agents/controllers/agentProductController.js +2 -1
- package/agents/controllers/agentSubscriptionController.js +20 -11
- package/agents/controllers/assistantsController.js +171 -127
- package/agents/controllers/policySynthAgents.js +33 -12
- package/agents/managers/newAiModelSetup.js +96 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +12 -12
- package/authorization.cjs +4 -0
- package/controllers/allOurIdeas.js +2 -1
- package/controllers/communities.cjs +47 -1
- package/controllers/groups.cjs +67 -4
- package/controllers/index.cjs +7 -7
- package/controllers/nonSpa.cjs +1 -1
- package/dist/active-citizen/controllers/activities.cjs +174 -0
- package/dist/active-citizen/controllers/news_feeds.cjs +96 -0
- package/dist/active-citizen/controllers/notifications.cjs +243 -0
- package/dist/active-citizen/controllers/recommendations.cjs +280 -0
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +204 -0
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +66 -0
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +38 -0
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +334 -0
- package/dist/active-citizen/engine/analytics/importer.js +308 -0
- package/dist/active-citizen/engine/analytics/manager.cjs +377 -0
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +500 -0
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +194 -0
- package/dist/active-citizen/engine/analytics/utils.cjs +369 -0
- package/dist/active-citizen/engine/marketing/campaign.cjs +90 -0
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +313 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +239 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +211 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +120 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +114 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +101 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +84 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +15 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +133 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +185 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +184 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +170 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +109 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +140 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +279 -0
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +386 -0
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +49 -0
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +68 -0
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +288 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +33 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +56 -0
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +106 -0
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +344 -0
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +810 -0
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +15 -0
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +362 -0
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +268 -0
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +439 -0
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +569 -0
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +233 -0
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +118 -0
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +41 -0
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +148 -0
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +54 -0
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +31 -0
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +471 -0
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +212 -0
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +153 -0
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +80 -0
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +157 -0
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +139 -0
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +212 -0
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +83 -0
- package/dist/active-citizen/engine/reports/commonUtils.js +75 -0
- package/dist/active-citizen/engine/reports/common_utils.cjs +740 -0
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +596 -0
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +232 -0
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +277 -0
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +718 -0
- package/dist/active-citizen/llms/baseChatBot.js +183 -0
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +109 -0
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +84 -0
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +110 -0
- package/dist/active-citizen/llms/llmTranslation.js +472 -0
- package/dist/active-citizen/models/ac_activity.cjs +216 -0
- package/dist/active-citizen/models/ac_background_job.cjs +109 -0
- package/dist/active-citizen/models/ac_campaign.cjs +97 -0
- package/dist/active-citizen/models/ac_client_activity.cjs +23 -0
- package/dist/active-citizen/models/ac_delayed_notification.cjs +43 -0
- package/dist/active-citizen/models/ac_following.cjs +43 -0
- package/dist/active-citizen/models/ac_list.cjs +68 -0
- package/dist/active-citizen/models/ac_list_users.cjs +19 -0
- package/dist/active-citizen/models/ac_mute.cjs +27 -0
- package/dist/active-citizen/models/ac_news_feed_item.cjs +57 -0
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +59 -0
- package/dist/active-citizen/models/ac_notification.cjs +292 -0
- package/dist/active-citizen/models/ac_translation_cache.cjs +750 -0
- package/dist/active-citizen/models/ac_watching.cjs +31 -0
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +13 -0
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +63 -0
- package/dist/active-citizen/scripts/kue_status.js +31 -0
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +24 -0
- package/dist/active-citizen/scripts/translation_clear_language.js +117 -0
- package/dist/active-citizen/scripts/translation_delete.js +27 -0
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +180 -0
- package/dist/active-citizen/scripts/translation_update.js +28 -0
- package/dist/active-citizen/scripts/translations_list.js +27 -0
- package/{active-citizen/utils/airbrake.js → dist/active-citizen/utils/airbrake.cjs} +1 -1
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +21 -0
- package/dist/active-citizen/utils/i18n.cjs +3 -0
- package/dist/active-citizen/utils/logger.cjs +25 -0
- package/dist/active-citizen/utils/redisConnection.cjs +29 -0
- package/dist/active-citizen/utils/to_json.cjs +9 -0
- package/dist/active-citizen/utils/translation_cloning.cjs +171 -0
- package/dist/active-citizen/utils/translation_helpers.cjs +534 -0
- package/dist/active-citizen/utils/truncate_text.cjs +21 -0
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +253 -0
- package/dist/active-citizen/utils/updateLocaleFolders.js +34 -0
- package/dist/active-citizen/workers/activity.cjs +189 -0
- package/dist/active-citizen/workers/anonymizations.cjs +734 -0
- package/dist/active-citizen/workers/bulk_status_update.cjs +458 -0
- package/dist/active-citizen/workers/delayed_jobs.cjs +244 -0
- package/dist/active-citizen/workers/deletions.cjs +1911 -0
- package/dist/active-citizen/workers/email.cjs +9 -0
- package/dist/active-citizen/workers/fraud_management.cjs +109 -0
- package/dist/active-citizen/workers/generativeAi.js +56 -0
- package/dist/active-citizen/workers/main.cjs +89 -0
- package/dist/active-citizen/workers/marketing.cjs +25 -0
- package/dist/active-citizen/workers/moderation.cjs +73 -0
- package/dist/active-citizen/workers/notification_delivery.cjs +368 -0
- package/dist/active-citizen/workers/notification_news_feed.cjs +142 -0
- package/dist/active-citizen/workers/queue.cjs +99 -0
- package/dist/active-citizen/workers/recount.cjs +74 -0
- package/dist/active-citizen/workers/reports.cjs +42 -0
- package/dist/active-citizen/workers/similarities.cjs +21 -0
- package/dist/active-citizen/workers/speech_to_text.cjs +482 -0
- package/dist/agents/assistants/agentAssistant.js +88 -0
- package/dist/agents/assistants/baseAssistant.js +888 -0
- package/dist/agents/assistants/baseAssistantWithVoice.js +150 -0
- package/dist/agents/assistants/modes/agentDirectConnection.js +84 -0
- package/dist/agents/assistants/modes/agentSelectionMode.js +44 -0
- package/dist/agents/assistants/modes/baseAssistantMode.js +54 -0
- package/dist/agents/assistants/modes/tools/agentTools.js +447 -0
- package/dist/agents/assistants/modes/tools/baseTools.js +58 -0
- package/dist/agents/assistants/modes/tools/loginTools.js +156 -0
- package/dist/agents/assistants/modes/tools/models/agents.js +146 -0
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +332 -0
- package/dist/agents/assistants/modes/tools/models/users.js +11 -0
- package/dist/agents/assistants/modes/tools/navigationTools.js +166 -0
- package/{agents/assistants/modes/tools/workflowConversationTools.js → dist/agents/assistants/modes/tools/subscriptionTools.js} +1 -4
- package/{agents/assistants/modes/tools/workflowTools.js → dist/agents/assistants/modes/tools/workflowConverstationTools.js} +1 -1
- package/dist/agents/assistants/voiceAssistant.js +619 -0
- package/dist/agents/controllers/agentProductController.js +103 -0
- package/dist/agents/controllers/agentSubscriptionController.js +261 -0
- package/dist/agents/controllers/assistantsController.js +511 -0
- package/dist/agents/controllers/policySynthAgents.js +395 -0
- package/{agents → dist/agents/managers}/agentProductManager.js +2 -2
- package/dist/agents/managers/emailInvitesManager.js +55 -0
- package/dist/agents/managers/emailTemplateRenderer.js +362 -0
- package/dist/agents/managers/newAiModelSetup.js +650 -0
- package/dist/agents/managers/notificationAgentQueueManager.js +510 -0
- package/dist/agents/managers/subscriptionManager.js +535 -0
- package/dist/agents/managers/workflowConversationManager.js +79 -0
- package/dist/agents/models/agentProduct.js +116 -0
- package/dist/agents/models/agentProductBoosterPurchase.js +58 -0
- package/dist/agents/models/agentProductBundle.js +68 -0
- package/dist/agents/models/agentProductRun.js +52 -0
- package/dist/agents/models/discount.js +88 -0
- package/dist/agents/models/subscription.js +79 -0
- package/dist/agents/models/subscriptionPlan.js +46 -0
- package/dist/agents/models/subscriptionUser.js +27 -0
- package/dist/agents/models/testData/createEvolyAgentProduct.js +477 -0
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +230 -0
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +233 -0
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +230 -0
- package/{agents/models/workflowConverstation.js → dist/agents/models/workflowConversation.js} +1 -1
- package/{agents/tools/updateTemplateWorkflow.js → dist/agents/tools/setTemplateWorkflowCommunityId.js} +1 -0
- package/dist/app.js +943 -0
- package/dist/authorization.cjs +1860 -0
- package/dist/bot_control.js +1930 -0
- package/dist/config/config.cjs +14 -0
- package/dist/config/config.js +14 -0
- package/dist/controllers/allOurIdeas.js +696 -0
- package/dist/controllers/audios.cjs +100 -0
- package/dist/controllers/bulkStatusUpdates.cjs +202 -0
- package/dist/controllers/categories.cjs +199 -0
- package/dist/controllers/communities.cjs +2996 -0
- package/dist/controllers/domains.cjs +1341 -0
- package/dist/controllers/externalIds.cjs +223 -0
- package/dist/controllers/groups.cjs +4309 -0
- package/dist/controllers/images.cjs +499 -0
- package/dist/controllers/index.cjs +449 -0
- package/dist/controllers/legacyPages.cjs +35 -0
- package/dist/controllers/legacyPosts.cjs +56 -0
- package/dist/controllers/legacyUsers.cjs +36 -0
- package/dist/controllers/nonSpa.cjs +574 -0
- package/dist/controllers/organizations.cjs +250 -0
- package/dist/controllers/points.cjs +1137 -0
- package/dist/controllers/posts.cjs +2036 -0
- package/dist/controllers/ratings.cjs +234 -0
- package/dist/controllers/users.cjs +2255 -0
- package/dist/controllers/videos.cjs +226 -0
- package/dist/deleteUnwantedDeclerations.cjs +55 -0
- package/dist/migrations/agentAuditLogs.cjs +46 -0
- package/dist/migrations/agentClasses.cjs +60 -0
- package/dist/migrations/agentConnectorClasses.cjs +61 -0
- package/dist/migrations/agentConnectors.cjs +50 -0
- package/dist/migrations/agentEvals.cjs +45 -0
- package/dist/migrations/agentRegistries.cjs +40 -0
- package/dist/migrations/agents.cjs +54 -0
- package/dist/migrations/aiModels.cjs +49 -0
- package/dist/migrations/apiUsage.cjs +47 -0
- package/dist/migrations/apis.cjs +49 -0
- package/dist/migrations/groupPrivateData.cjs +30 -0
- package/dist/migrations/modelUsage.cjs +60 -0
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +23 -0
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +360 -0
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +29 -0
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +24 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +29 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +22 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +23 -0
- package/{migrations/200824_create_embeddings_and_org_update.cjs → dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js} +6 -3
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +36 -0
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +41 -0
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +88 -0
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +33 -0
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +38 -0
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +127 -0
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +68 -0
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +63 -0
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +14 -0
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +71 -0
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +12 -0
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +46 -0
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +46 -0
- package/dist/migrations/privateAccessStore.cjs +55 -0
- package/dist/migrations/zzz_associations.cjs +154 -0
- package/dist/migrations/zzzzz_create_agent_runs.cjs +606 -0
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +11 -0
- package/dist/migrations/zzzzzzz_create_trees.cjs +81 -0
- package/dist/models/audio.cjs +430 -0
- package/dist/models/bulk_status_update.cjs +58 -0
- package/dist/models/campaign.cjs +78 -0
- package/dist/models/category.cjs +94 -0
- package/dist/models/community.cjs +337 -0
- package/dist/models/domain.cjs +486 -0
- package/dist/models/endorsement.cjs +39 -0
- package/dist/models/general_data_store.cjs +20 -0
- package/dist/models/group.cjs +728 -0
- package/dist/models/image.cjs +579 -0
- package/dist/models/index.cjs +186 -0
- package/dist/models/invite.cjs +48 -0
- package/dist/models/iso_country.cjs +16 -0
- package/dist/models/organization.cjs +122 -0
- package/dist/models/page.cjs +273 -0
- package/dist/models/point.cjs +622 -0
- package/dist/models/point_quality.cjs +39 -0
- package/dist/models/point_revision.cjs +47 -0
- package/dist/models/post.cjs +680 -0
- package/dist/models/post_revision.cjs +38 -0
- package/dist/models/post_status_change.cjs +35 -0
- package/dist/models/promotion.cjs +34 -0
- package/dist/models/rating.cjs +51 -0
- package/dist/models/relationship.cjs +19 -0
- package/dist/models/request_to_join.cjs +20 -0
- package/dist/models/user.cjs +604 -0
- package/dist/models/user_legacy_password.cjs +13 -0
- package/dist/models/video.cjs +1137 -0
- package/dist/publish.js +40 -0
- package/dist/repack.js +53 -0
- package/dist/scripts/addRatingUsersToGroup.js +51 -0
- package/dist/scripts/addUserToOrganization.js +71 -0
- package/dist/scripts/analyseRatingsForCommunity.js +150 -0
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +28 -0
- package/dist/scripts/analyzeEndorsementsByCountry.js +70 -0
- package/dist/scripts/analyzePostsForCommunity.js +185 -0
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +14 -0
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +110 -0
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +116 -0
- package/{scripts/bulkStatusUpdates/performUpdateForGroup.js → dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs} +1 -2
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +141 -0
- package/dist/scripts/change/changeVideoAspectTo.js +34 -0
- package/dist/scripts/change/setUseNewVersion.cjs +22 -0
- package/dist/scripts/changeCommunityGroupcount.js +30 -0
- package/dist/scripts/changeCommunityPostCount.js +30 -0
- package/dist/scripts/changeGroupPostCount.js +30 -0
- package/dist/scripts/changeLanguage.js +50 -0
- package/dist/scripts/changeOfficalStatus.js +30 -0
- package/{scripts/cleanups/deleteAnonNotifications.js → dist/scripts/cleanups/deleteAnonNotifications.cjs} +1 -1
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +62 -0
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +72 -0
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +43 -0
- package/dist/scripts/clearAllEndorsementInGroup.js +50 -0
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +129 -0
- package/dist/scripts/cloning/cloneFromUrlScript.js +65 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +140 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +140 -0
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +173 -0
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +18 -0
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +26 -0
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +205 -0
- package/dist/scripts/cloning/copyPostToGroupOld.js +397 -0
- package/dist/scripts/cloning/copyPostVideosFromURL.js +236 -0
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +17 -0
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +139 -0
- package/dist/scripts/cloning/setAdminsFromURL.js +161 -0
- package/dist/scripts/cloning/setExternalIdsFromURL.js +129 -0
- package/dist/scripts/countCommunity.js +291 -0
- package/dist/scripts/countCommunityUsers.js +152 -0
- package/dist/scripts/countDelayedNotifications.js +18 -0
- package/dist/scripts/countGroup.js +246 -0
- package/dist/scripts/countStuff.js +67 -0
- package/dist/scripts/countUniqueVotersInAGroup.js +48 -0
- package/dist/scripts/createInvitesAndShow.js +75 -0
- package/dist/scripts/database/sync_database.js +14 -0
- package/dist/scripts/database/sync_dev_database.js +17 -0
- package/dist/scripts/debugNotifications.js +58 -0
- package/dist/scripts/deleteAllNewsFeeds.js +10 -0
- package/dist/scripts/deleteCategory.js +13 -0
- package/dist/scripts/deleteOldAppActivities.js +40 -0
- package/dist/scripts/deletePostContactDataForCommunity.js +53 -0
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +1026 -0
- package/dist/scripts/displayAuthorForPost.js +16 -0
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +183 -0
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +208 -0
- package/dist/scripts/exportAllStatusChanges.js +36 -0
- package/dist/scripts/exportClientAcitivity.js +36 -0
- package/dist/scripts/exportEndorsementsForCommunity.js +79 -0
- package/dist/scripts/exportPointQualitiesForCommunity.js +84 -0
- package/dist/scripts/exportPostsAndPointsForCommunity.js +147 -0
- package/dist/scripts/exportPostsDataSetForDomain.js +244 -0
- package/dist/scripts/exportPostsForGroup.js +173 -0
- package/dist/scripts/exportRatingsForPost.js +15 -0
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +123 -0
- package/dist/scripts/exportUsersForCommunity.js +24 -0
- package/dist/scripts/exportUsersForDomain.js +24 -0
- package/dist/scripts/exportUsersForGroup.js +24 -0
- package/dist/scripts/exports/ratingDistribution.js +71 -0
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +56 -0
- package/dist/scripts/findUnusedClientImports.js +56 -0
- package/dist/scripts/fixAllPostPointCounts.js +22 -0
- package/dist/scripts/fixAnonNotificationsSettings.js +48 -0
- package/dist/scripts/fixCountKopavogur.js +9 -0
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +190 -0
- package/dist/scripts/fixExternalUserId.js +24 -0
- package/dist/scripts/fixGroupAccess.js +16 -0
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +49 -0
- package/dist/scripts/fixNotificationSettings.js +39 -0
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +64 -0
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +49 -0
- package/dist/scripts/gallery/exportGalleryData.js +40 -0
- package/dist/scripts/gallery/importGalleryForCommunity.js +168 -0
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +55 -0
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +58 -0
- package/dist/scripts/genderAnalysis.js +63 -0
- package/dist/scripts/genderAnalysisByStatus.js +62 -0
- package/dist/scripts/importAllLocalesFromLocalFolders.js +55 -0
- package/dist/scripts/importDomain.js +1652 -0
- package/dist/scripts/keys/addOidcToDomain.cjs +61 -0
- package/dist/scripts/landUseGame/export3Ddata.js +162 -0
- package/dist/scripts/listLanguagesForGroup.js +54 -0
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +27 -0
- package/dist/scripts/makeRecursiveMapData.js +103 -0
- package/dist/scripts/mapping/community_map_csv.js +145 -0
- package/dist/scripts/moveCommunityToDomain.js +22 -0
- package/dist/scripts/moveGroupToCommunity.js +23 -0
- package/dist/scripts/movePostToGroup.js +101 -0
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +297 -0
- package/dist/scripts/oldMovePostToGroup.js +153 -0
- package/dist/scripts/processCsvForPdfUrls.js +37 -0
- package/dist/scripts/processCsvForTranslationAndToxicity.js +125 -0
- package/dist/scripts/recount/recount_recursive_communities.js +125 -0
- package/dist/scripts/recountALLCommunityGroupCounts.js +37 -0
- package/dist/scripts/recountAll.js +97 -0
- package/dist/scripts/recountCommunitesFromUrl.js +58 -0
- package/dist/scripts/recountCommunity.js +19 -0
- package/dist/scripts/recountGroup.js +218 -0
- package/dist/scripts/recountGroupNoUserChange.js +219 -0
- package/dist/scripts/resetAllEndorsementsForGroup.js +57 -0
- package/dist/scripts/resetEnTranslationForGroup.js +45 -0
- package/dist/scripts/setAdminOnAll.cjs +107 -0
- package/{scripts/change → dist/scripts}/setDomainAdmin.cjs +0 -2
- package/dist/scripts/setDomainLocales.js +33 -0
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +29 -0
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +86 -0
- package/dist/scripts/setMemberOfAll.js +101 -0
- package/dist/scripts/setNewUserForContentOfCommunity.js +189 -0
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +35 -0
- package/dist/scripts/setUserOnAll.js +101 -0
- package/dist/scripts/showCategoryForGroup.js +18 -0
- package/dist/scripts/showOldActivityTypes.js +14 -0
- package/dist/scripts/showPostsMissingCategoryForGroup.js +17 -0
- package/dist/scripts/showStatuses.js +17 -0
- package/dist/scripts/showUniqueVotersInCommunity.js +61 -0
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +66 -0
- package/dist/scripts/simpleExportForGroupsForCommunity.js +46 -0
- package/dist/scripts/simpleExportForPointsForCommunity.js +82 -0
- package/dist/scripts/simpleExportForPostsForCommunity.js +61 -0
- package/dist/scripts/testForEndorsments.js +21 -0
- package/dist/scripts/undeleteGroupAndAllContent.js +151 -0
- package/dist/scripts/undeletePost.js +135 -0
- package/dist/scripts/unlinkSsn.js +23 -0
- package/dist/scripts/updateFromAlthingi.js +303 -0
- package/dist/server.js +3 -0
- package/dist/utils/airbrake.cjs +17 -0
- package/dist/utils/cjsCodeReview.js +99 -0
- package/dist/utils/community_mapping_tools.cjs +124 -0
- package/dist/utils/copy_utils.cjs +1399 -0
- package/dist/utils/docx_utils.cjs +464 -0
- package/dist/utils/export_utils.cjs +491 -0
- package/dist/utils/i18n.cjs +17 -0
- package/dist/utils/is_valid_db_id.cjs +28 -0
- package/dist/utils/logger.cjs +25 -0
- package/dist/utils/loggerTs.js +26 -0
- package/dist/utils/manifest_generator.cjs +104 -0
- package/dist/utils/parse_domain.cjs +16 -0
- package/dist/utils/recount_utils.cjs +415 -0
- package/dist/utils/sharing_parameters.cjs +111 -0
- package/dist/utils/sitemap_generator.cjs +286 -0
- package/dist/utils/to_json.cjs +14 -0
- package/dist/utils/ypLanguages.js +747 -0
- package/dist/webSockets.js +77 -0
- package/package.json +46 -44
- package/server.d.ts +104 -2
- package/utils/copy_utils.cjs +7 -1
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
- package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
- package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
- package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
- package/active-citizen/llms/baseChatBot.d.ts +0 -51
- package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
- package/active-citizen/llms/collectionImageGenerator.js +0 -357
- package/active-citizen/llms/llmTranslation.d.ts +0 -24
- package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
- package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
- package/active-citizen/scripts/kue_status.d.ts.map +0 -1
- package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
- package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
- package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
- package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
- package/active-citizen/scripts/translation_update.d.ts.map +0 -1
- package/active-citizen/scripts/translations_list.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.d.ts.map +0 -1
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
- package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
- package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
- package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
- package/active-citizen/workers/generativeAi.d.ts.map +0 -1
- package/agents/assistants/agentAssistantOld.js +0 -863
- package/agents/assistants/modes/agentConfigurationMode.js +0 -63
- package/agents/assistants/modes/agentOperationsMode.js +0 -195
- package/agents/assistants/modes/commonTools.js +0 -58
- package/agents/assistants/modes/directConversationMode.js +0 -14
- package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
- package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
- package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
- package/agents/assistants/modes/tools/commonHandlers.js +0 -57
- package/agents/assistants/modes/tools/loginHandlers.js +0 -46
- package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
- package/agents/controllers/assistantController.js +0 -243
- package/agents/managers/workflowManager.js +0 -76
- package/agents/models/testData/setupConfig.js +0 -140
- package/agents/models/workflow.js +0 -53
- package/agents/subscriptionManager.js +0 -218
- package/app.d.ts +0 -40
- package/app.d.ts.map +0 -1
- package/bot_control.d.ts.map +0 -1
- package/publish.d.ts.map +0 -1
- package/repack.d.ts.map +0 -1
- package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
- package/scripts/addUserToOrganization.d.ts.map +0 -1
- package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
- package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
- package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
- package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
- package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
- package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
- package/scripts/changeCommunityPostCount.d.ts.map +0 -1
- package/scripts/changeGroupPostCount.d.ts.map +0 -1
- package/scripts/changeLanguage.d.ts.map +0 -1
- package/scripts/changeOfficalStatus.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
- package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
- package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
- package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
- package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
- package/scripts/countCommunity.d.ts.map +0 -1
- package/scripts/countCommunityUsers.d.ts.map +0 -1
- package/scripts/countDelayedNotifications.d.ts.map +0 -1
- package/scripts/countGroup.d.ts.map +0 -1
- package/scripts/countStuff.d.ts.map +0 -1
- package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
- package/scripts/createInvitesAndShow.d.ts.map +0 -1
- package/scripts/database/seedTestAiModels.js +0 -64
- package/scripts/database/sync_database.d.ts.map +0 -1
- package/scripts/database/sync_dev_database.d.ts.map +0 -1
- package/scripts/debugNotifications.d.ts.map +0 -1
- package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
- package/scripts/deleteCategory.d.ts.map +0 -1
- package/scripts/deleteOldAppActivities.d.ts.map +0 -1
- package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
- package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
- package/scripts/displayAuthorForPost.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
- package/scripts/exportAllStatusChanges.d.ts.map +0 -1
- package/scripts/exportClientAcitivity.d.ts.map +0 -1
- package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
- package/scripts/exportPostsForGroup.d.ts.map +0 -1
- package/scripts/exportRatingsForPost.d.ts.map +0 -1
- package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
- package/scripts/exportUsersForCommunity.d.ts.map +0 -1
- package/scripts/exportUsersForDomain.d.ts.map +0 -1
- package/scripts/exportUsersForGroup.d.ts.map +0 -1
- package/scripts/exports/ratingDistribution.d.ts.map +0 -1
- package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
- package/scripts/findUnusedClientImports.d.ts.map +0 -1
- package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
- package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
- package/scripts/fixCountKopavogur.d.ts.map +0 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
- package/scripts/fixExternalUserId.d.ts.map +0 -1
- package/scripts/fixGroupAccess.d.ts.map +0 -1
- package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
- package/scripts/fixNotificationSettings.d.ts.map +0 -1
- package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
- package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
- package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
- package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
- package/scripts/genderAnalysis.d.ts.map +0 -1
- package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
- package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
- package/scripts/importDomain.d.ts.map +0 -1
- package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
- package/scripts/listLanguagesForGroup.d.ts.map +0 -1
- package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
- package/scripts/makeRecursiveMapData.d.ts.map +0 -1
- package/scripts/mapping/community_map_csv.d.ts.map +0 -1
- package/scripts/moveCommunityToDomain.d.ts.map +0 -1
- package/scripts/moveGroupToCommunity.d.ts.map +0 -1
- package/scripts/movePostToGroup.d.ts.map +0 -1
- package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
- package/scripts/oldMovePostToGroup.d.ts.map +0 -1
- package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
- package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
- package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
- package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
- package/scripts/recountAll.d.ts.map +0 -1
- package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/recountCommunity.d.ts.map +0 -1
- package/scripts/recountGroup.d.ts.map +0 -1
- package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
- package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
- package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
- package/scripts/setDomainLocales.d.ts.map +0 -1
- package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/setMemberOfAll.d.ts.map +0 -1
- package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
- package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
- package/scripts/setUserOnAll.d.ts.map +0 -1
- package/scripts/showCategoryForGroup.d.ts.map +0 -1
- package/scripts/showOldActivityTypes.d.ts.map +0 -1
- package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
- package/scripts/showStatuses.d.ts.map +0 -1
- package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
- package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
- package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
- package/scripts/testForEndorsments.d.ts.map +0 -1
- package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
- package/scripts/undeletePost.d.ts.map +0 -1
- package/scripts/unlinkSsn.d.ts.map +0 -1
- package/scripts/updateFromAlthingi.d.ts.map +0 -1
- package/server.d.ts.map +0 -1
- package/utils/copyGroup.js +0 -246
- package/utils/loggerTs.d.ts +0 -4
- package/utils/loggerTs.d.ts.map +0 -1
- package/utils/ypLanguages.d.ts +0 -18
- package/utils/ypLanguages.d.ts.map +0 -1
- /package/{agents/tools/updateCommunityWorkflow.js → dist/active-citizen/llms/imageGeneration/iImageGenerator.js} +0 -0
- /package/{migrations/270724_createUsersAndAdminsForClasses.cjs → dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs} +0 -0
|
@@ -0,0 +1,1399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var models = require("../models/index.cjs");
|
|
3
|
+
var async = require("async");
|
|
4
|
+
const { cloneTranslationForGroup, } = require("../active-citizen/utils/translation_cloning.cjs");
|
|
5
|
+
const { cloneTranslationForCommunity, } = require("../active-citizen/utils/translation_cloning.cjs");
|
|
6
|
+
const { cloneTranslationForPoint, } = require("../active-citizen/utils/translation_cloning.cjs");
|
|
7
|
+
const { cloneTranslationForPost, } = require("../active-citizen/utils/translation_cloning.cjs");
|
|
8
|
+
const { recountCommunity } = require("./recount_utils.cjs");
|
|
9
|
+
const clonePagesForCollection = (model, modelRelField, inCollection, outCollection, done) => {
|
|
10
|
+
const oldToNewHash = {};
|
|
11
|
+
models.Page.findAll({
|
|
12
|
+
include: [
|
|
13
|
+
{
|
|
14
|
+
model: model,
|
|
15
|
+
where: {
|
|
16
|
+
id: inCollection.id,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
})
|
|
21
|
+
.then((pages) => {
|
|
22
|
+
async.forEach(pages, (oldPage, forEachCallback) => {
|
|
23
|
+
const pageJson = JSON.parse(JSON.stringify(oldPage.toJSON()));
|
|
24
|
+
delete pageJson["id"];
|
|
25
|
+
pageJson[modelRelField] = outCollection.id;
|
|
26
|
+
const newPage = models.Page.build(pageJson);
|
|
27
|
+
newPage
|
|
28
|
+
.save()
|
|
29
|
+
.then(() => {
|
|
30
|
+
oldToNewHash[oldPage.id] = newPage.id;
|
|
31
|
+
forEachCallback();
|
|
32
|
+
})
|
|
33
|
+
.catch((error) => {
|
|
34
|
+
forEachCallback(error);
|
|
35
|
+
});
|
|
36
|
+
}, (error) => {
|
|
37
|
+
if (inCollection.configuration &&
|
|
38
|
+
inCollection.configuration.welcomePageId &&
|
|
39
|
+
inCollection.configuration.welcomePageId !== "") {
|
|
40
|
+
outCollection.set("configuration.welcomePageId", oldToNewHash[parseInt(inCollection.configuration.welcomePageId)]);
|
|
41
|
+
outCollection
|
|
42
|
+
.save()
|
|
43
|
+
.then(() => {
|
|
44
|
+
done();
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
done(error);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
done(error);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
done(error);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const clonePagesForGroup = (inGroup, outGroup, done) => {
|
|
60
|
+
clonePagesForCollection(models.Group, "group_id", inGroup, outGroup, done);
|
|
61
|
+
};
|
|
62
|
+
const clonePagesForCommunity = (inCommunity, outCommunity, done) => {
|
|
63
|
+
clonePagesForCollection(models.Community, "community_id", inCommunity, outCommunity, done);
|
|
64
|
+
};
|
|
65
|
+
const copyPost = (fromPostId, toGroupId, options, done) => {
|
|
66
|
+
var toGroup, toDomainId, toCommunityId;
|
|
67
|
+
var toDomain;
|
|
68
|
+
var newPost;
|
|
69
|
+
var oldPost;
|
|
70
|
+
var skipPointActivitiesIdsForPostCopy = [];
|
|
71
|
+
async.series([
|
|
72
|
+
function (callback) {
|
|
73
|
+
models.Group.findOne({
|
|
74
|
+
where: {
|
|
75
|
+
id: toGroupId,
|
|
76
|
+
},
|
|
77
|
+
include: [
|
|
78
|
+
{
|
|
79
|
+
model: models.Community,
|
|
80
|
+
required: true,
|
|
81
|
+
include: [
|
|
82
|
+
{
|
|
83
|
+
model: models.Domain,
|
|
84
|
+
required: true,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
})
|
|
90
|
+
.then(function (groupIn) {
|
|
91
|
+
toGroup = groupIn;
|
|
92
|
+
toCommunityId = toGroup.Community.id;
|
|
93
|
+
toDomainId = toGroup.Community.Domain.id;
|
|
94
|
+
toDomain = toGroup.Community.Domain;
|
|
95
|
+
callback();
|
|
96
|
+
})
|
|
97
|
+
.catch(function (error) {
|
|
98
|
+
callback(error);
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
function (callback) {
|
|
102
|
+
models.Post.findOne({
|
|
103
|
+
where: {
|
|
104
|
+
id: fromPostId,
|
|
105
|
+
},
|
|
106
|
+
include: [
|
|
107
|
+
{
|
|
108
|
+
model: models.Image,
|
|
109
|
+
as: "PostHeaderImages",
|
|
110
|
+
attributes: ["id"],
|
|
111
|
+
required: false,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
model: models.Video,
|
|
115
|
+
as: "PostVideos",
|
|
116
|
+
attributes: ["id"],
|
|
117
|
+
required: false,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
model: models.Audio,
|
|
121
|
+
as: "PostAudios",
|
|
122
|
+
attributes: ["id"],
|
|
123
|
+
required: false,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
model: models.Image,
|
|
127
|
+
as: "PostUserImages",
|
|
128
|
+
attributes: ["id"],
|
|
129
|
+
required: false,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
}).then(function (postIn) {
|
|
133
|
+
oldPost = postIn;
|
|
134
|
+
if (!postIn) {
|
|
135
|
+
console.error("No post in");
|
|
136
|
+
callback("no post");
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
var postJson = JSON.parse(JSON.stringify(postIn.toJSON()));
|
|
140
|
+
delete postJson["id"];
|
|
141
|
+
newPost = models.Post.build(postJson);
|
|
142
|
+
newPost.set("group_id", toGroup.id);
|
|
143
|
+
if (options && !options.copyPoints) {
|
|
144
|
+
newPost.set("counter_points", 0);
|
|
145
|
+
}
|
|
146
|
+
if (options && options.toCategoryId) {
|
|
147
|
+
newPost.set("category_id", options.toCategoryId);
|
|
148
|
+
}
|
|
149
|
+
if (options && options.skipUsers) {
|
|
150
|
+
newPost.set("counter_users", 0);
|
|
151
|
+
}
|
|
152
|
+
if (options && options.resetEndorsementCounters) {
|
|
153
|
+
newPost.set("counter_endorsements_up", 0);
|
|
154
|
+
newPost.set("counter_endorsements_down", 0);
|
|
155
|
+
}
|
|
156
|
+
newPost
|
|
157
|
+
.save()
|
|
158
|
+
.then(function () {
|
|
159
|
+
async.series([
|
|
160
|
+
(postSeriesCallback) => {
|
|
161
|
+
cloneTranslationForPost(oldPost, newPost, postSeriesCallback);
|
|
162
|
+
},
|
|
163
|
+
(postSeriesCallback) => {
|
|
164
|
+
if (options && options.createCopyActivities) {
|
|
165
|
+
models.AcActivity.createActivity({
|
|
166
|
+
type: "activity.post.copied",
|
|
167
|
+
userId: newPost.user_id,
|
|
168
|
+
domainId: toDomain.id,
|
|
169
|
+
groupId: newPost.group_id,
|
|
170
|
+
postId: newPost.id,
|
|
171
|
+
access: models.AcActivity.ACCESS_PRIVATE,
|
|
172
|
+
}, function (error) {
|
|
173
|
+
postSeriesCallback(error);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
postSeriesCallback();
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
(postSeriesCallback) => {
|
|
181
|
+
if (oldPost.PostVideos && oldPost.PostVideos.length > 0) {
|
|
182
|
+
async.eachSeries(oldPost.PostVideos, function (media, mediaCallback) {
|
|
183
|
+
newPost
|
|
184
|
+
.addPostVideo(media)
|
|
185
|
+
.then(function () {
|
|
186
|
+
mediaCallback();
|
|
187
|
+
})
|
|
188
|
+
.catch((error) => {
|
|
189
|
+
mediaCallback(error);
|
|
190
|
+
});
|
|
191
|
+
}, function (error) {
|
|
192
|
+
postSeriesCallback(error);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
postSeriesCallback();
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
(postSeriesCallback) => {
|
|
200
|
+
if (oldPost.PostAudios && oldPost.PostAudios.length > 0) {
|
|
201
|
+
async.eachSeries(oldPost.PostAudios, function (media, mediaCallback) {
|
|
202
|
+
newPost
|
|
203
|
+
.addPostAudio(media)
|
|
204
|
+
.then(function () {
|
|
205
|
+
mediaCallback();
|
|
206
|
+
})
|
|
207
|
+
.catch((error) => {
|
|
208
|
+
mediaCallback(error);
|
|
209
|
+
});
|
|
210
|
+
}, function (error) {
|
|
211
|
+
postSeriesCallback(error);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
postSeriesCallback();
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
(postSeriesCallback) => {
|
|
219
|
+
if (!options.skipEndorsementQualitiesAndRatings) {
|
|
220
|
+
models.Endorsement.findAll({
|
|
221
|
+
where: {
|
|
222
|
+
post_id: oldPost.id,
|
|
223
|
+
},
|
|
224
|
+
}).then(function (endorsements) {
|
|
225
|
+
async.eachSeries(endorsements, function (endorsement, endorsementCallback) {
|
|
226
|
+
var endorsementJson = JSON.parse(JSON.stringify(endorsement.toJSON()));
|
|
227
|
+
delete endorsementJson.id;
|
|
228
|
+
var endorsementModel = models.Endorsement.build(endorsementJson);
|
|
229
|
+
endorsementModel.set("post_id", newPost.id);
|
|
230
|
+
endorsementModel.set("PostId", newPost.id);
|
|
231
|
+
endorsementModel
|
|
232
|
+
.save()
|
|
233
|
+
.then(function () {
|
|
234
|
+
if (options && options.createCopyActivities) {
|
|
235
|
+
models.AcActivity.createActivity({
|
|
236
|
+
type: endorsementModel.value > 0
|
|
237
|
+
? "activity.post.endorsement.copied"
|
|
238
|
+
: "activity.post.opposition.copied",
|
|
239
|
+
userId: endorsementModel.user_id,
|
|
240
|
+
domainId: toDomain.id,
|
|
241
|
+
groupId: newPost.group_id,
|
|
242
|
+
postId: newPost.id,
|
|
243
|
+
access: models.AcActivity.ACCESS_PRIVATE,
|
|
244
|
+
}, function (error) {
|
|
245
|
+
endorsementCallback(error);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
endorsementCallback();
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
.catch((error) => {
|
|
253
|
+
endorsementCallback(error);
|
|
254
|
+
});
|
|
255
|
+
}, function (error) {
|
|
256
|
+
postSeriesCallback(error);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
postSeriesCallback();
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
(postSeriesCallback) => {
|
|
265
|
+
if (!options.skipEndorsementQualitiesAndRatings) {
|
|
266
|
+
models.Rating.findAll({
|
|
267
|
+
where: {
|
|
268
|
+
post_id: oldPost.id,
|
|
269
|
+
},
|
|
270
|
+
}).then(function (ratings) {
|
|
271
|
+
async.eachSeries(ratings, function (rating, ratingCallback) {
|
|
272
|
+
var ratingJson = JSON.parse(JSON.stringify(rating.toJSON()));
|
|
273
|
+
delete rating.id;
|
|
274
|
+
var ratingModel = models.Endorsement.build(ratingJson);
|
|
275
|
+
ratingModel.set("post_id", newPost.id);
|
|
276
|
+
ratingModel.set("PostId", newPost.id);
|
|
277
|
+
ratingModel
|
|
278
|
+
.save()
|
|
279
|
+
.then(function () {
|
|
280
|
+
if (options && options.createCopyActivities) {
|
|
281
|
+
models.AcActivity.createActivity({
|
|
282
|
+
type: "activity.post.rating.copied",
|
|
283
|
+
userId: ratingModel.user_id,
|
|
284
|
+
domainId: toDomain.id,
|
|
285
|
+
groupId: newPost.group_id,
|
|
286
|
+
postId: newPost.id,
|
|
287
|
+
access: models.AcActivity.ACCESS_PRIVATE,
|
|
288
|
+
}, function (error) {
|
|
289
|
+
ratingCallback(error);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
ratingCallback();
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
.catch((error) => {
|
|
297
|
+
ratingCallback(error);
|
|
298
|
+
});
|
|
299
|
+
}, function (error) {
|
|
300
|
+
postSeriesCallback(error);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
postSeriesCallback();
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
function (postSeriesCallback) {
|
|
309
|
+
models.PostRevision.findAll({
|
|
310
|
+
where: {
|
|
311
|
+
post_id: oldPost.id,
|
|
312
|
+
},
|
|
313
|
+
}).then(function (postRevisions) {
|
|
314
|
+
async.eachSeries(postRevisions, function (postRevision, postRevisionCallback) {
|
|
315
|
+
var postRevisionJson = JSON.parse(JSON.stringify(postRevision.toJSON()));
|
|
316
|
+
delete postRevisionJson.id;
|
|
317
|
+
var newPostRevision = models.PostRevision.build(postRevisionJson);
|
|
318
|
+
newPostRevision.set("post_id", newPost.id);
|
|
319
|
+
newPostRevision.set("PostId", newPost.id);
|
|
320
|
+
newPostRevision
|
|
321
|
+
.save()
|
|
322
|
+
.then(function () {
|
|
323
|
+
postRevisionCallback();
|
|
324
|
+
})
|
|
325
|
+
.catch((error) => {
|
|
326
|
+
postRevisionCallback(error);
|
|
327
|
+
});
|
|
328
|
+
}, function (error) {
|
|
329
|
+
postSeriesCallback(error);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
function (postSeriesCallback) {
|
|
334
|
+
if (oldPost.PostUserImages &&
|
|
335
|
+
oldPost.PostUserImages.length > 0) {
|
|
336
|
+
async.eachSeries(oldPost.PostUserImages, function (userImage, userImageCallback) {
|
|
337
|
+
newPost
|
|
338
|
+
.addPostUserImage(userImage)
|
|
339
|
+
.then(function () {
|
|
340
|
+
userImageCallback();
|
|
341
|
+
})
|
|
342
|
+
.catch((error) => {
|
|
343
|
+
userImageCallback(error);
|
|
344
|
+
});
|
|
345
|
+
}, function (error) {
|
|
346
|
+
postSeriesCallback(error);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
postSeriesCallback();
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
function (postSeriesCallback) {
|
|
354
|
+
if (oldPost.PostHeaderImages &&
|
|
355
|
+
oldPost.PostHeaderImages.length > 0) {
|
|
356
|
+
async.eachSeries(oldPost.PostHeaderImages, function (userImage, imageCallback) {
|
|
357
|
+
newPost
|
|
358
|
+
.addPostHeaderImage(userImage)
|
|
359
|
+
.then(function () {
|
|
360
|
+
imageCallback();
|
|
361
|
+
})
|
|
362
|
+
.catch((error) => {
|
|
363
|
+
imageCallback(error);
|
|
364
|
+
});
|
|
365
|
+
}, function (error) {
|
|
366
|
+
postSeriesCallback(error);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
postSeriesCallback();
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
], function (error) {
|
|
374
|
+
console.log("Have copied post to group id");
|
|
375
|
+
callback(error);
|
|
376
|
+
});
|
|
377
|
+
})
|
|
378
|
+
.catch((error) => {
|
|
379
|
+
callback(error);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
},
|
|
384
|
+
function (callback) {
|
|
385
|
+
if (options && options.copyPoints) {
|
|
386
|
+
models.Point.findAll({
|
|
387
|
+
where: {
|
|
388
|
+
post_id: fromPostId,
|
|
389
|
+
},
|
|
390
|
+
include: [
|
|
391
|
+
{
|
|
392
|
+
model: models.Video,
|
|
393
|
+
as: "PointVideos",
|
|
394
|
+
attributes: ["id"],
|
|
395
|
+
required: false,
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
model: models.Audio,
|
|
399
|
+
as: "PointAudios",
|
|
400
|
+
attributes: ["id"],
|
|
401
|
+
required: false,
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
}).then(function (pointsIn) {
|
|
405
|
+
async.eachSeries(pointsIn, function (point, innerSeriesCallback) {
|
|
406
|
+
var pointJson = JSON.parse(JSON.stringify(point.toJSON()));
|
|
407
|
+
var currentOldPoint = point;
|
|
408
|
+
delete pointJson["id"];
|
|
409
|
+
var newPoint = models.Point.build(pointJson);
|
|
410
|
+
newPoint.set("group_id", toGroup.id);
|
|
411
|
+
newPoint.set("community_id", toCommunityId);
|
|
412
|
+
newPoint.set("domain_id", toDomainId);
|
|
413
|
+
newPoint.set("post_id", newPost.id);
|
|
414
|
+
newPoint.set("PostId", newPost.id);
|
|
415
|
+
newPoint.save().then(function () {
|
|
416
|
+
async.series([
|
|
417
|
+
(pointSeriesCallback) => {
|
|
418
|
+
//cloneTranslationForPoint(point, newPoint, pointSeriesCallback);
|
|
419
|
+
pointSeriesCallback();
|
|
420
|
+
},
|
|
421
|
+
(pointSeriesCallback) => {
|
|
422
|
+
if (options && options.createCopyActivities) {
|
|
423
|
+
models.AcActivity.createActivity({
|
|
424
|
+
type: "activity.point.copied",
|
|
425
|
+
userId: newPost.user_id,
|
|
426
|
+
domainId: toDomain.id,
|
|
427
|
+
groupId: newPost.group_id,
|
|
428
|
+
postId: newPost.id,
|
|
429
|
+
pointId: newPoint.id,
|
|
430
|
+
access: models.AcActivity.ACCESS_PRIVATE,
|
|
431
|
+
}, function (error) {
|
|
432
|
+
pointSeriesCallback(error);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
pointSeriesCallback();
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
function (pointSeriesCallback) {
|
|
440
|
+
if (!options.skipEndorsementQualitiesAndRatings) {
|
|
441
|
+
models.PointQuality.findAll({
|
|
442
|
+
where: {
|
|
443
|
+
point_id: currentOldPoint.id,
|
|
444
|
+
},
|
|
445
|
+
}).then(function (pointQualities) {
|
|
446
|
+
async.eachSeries(pointQualities, function (pointQuality, pointQualityCallback) {
|
|
447
|
+
var pointQualityJson = JSON.parse(JSON.stringify(pointQuality.toJSON()));
|
|
448
|
+
delete pointQualityJson.id;
|
|
449
|
+
var newPointQuality = models.PointQuality.build(pointQualityJson);
|
|
450
|
+
newPointQuality.set("point_id", newPoint.id);
|
|
451
|
+
newPointQuality
|
|
452
|
+
.save()
|
|
453
|
+
.then(function () {
|
|
454
|
+
if (options &&
|
|
455
|
+
options.createCopyActivities) {
|
|
456
|
+
models.AcActivity.createActivity({
|
|
457
|
+
type: newPointQuality.value > 0
|
|
458
|
+
? "activity.point.helpful.copied"
|
|
459
|
+
: "activity.point.unhelpful.copied",
|
|
460
|
+
userId: newPointQuality.user_id,
|
|
461
|
+
domainId: toDomain.id,
|
|
462
|
+
groupId: newPost.group_id,
|
|
463
|
+
postId: newPost.id,
|
|
464
|
+
pointId: newPoint.id,
|
|
465
|
+
access: models.AcActivity.ACCESS_PRIVATE,
|
|
466
|
+
}, function (error) {
|
|
467
|
+
pointQualityCallback(error);
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
pointQualityCallback();
|
|
472
|
+
}
|
|
473
|
+
})
|
|
474
|
+
.catch((error) => {
|
|
475
|
+
pointQualityCallback(error);
|
|
476
|
+
});
|
|
477
|
+
}, function (error) {
|
|
478
|
+
pointSeriesCallback(error);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
pointSeriesCallback();
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
function (pointSeriesCallback) {
|
|
487
|
+
models.PointRevision.findAll({
|
|
488
|
+
where: {
|
|
489
|
+
point_id: currentOldPoint.id,
|
|
490
|
+
},
|
|
491
|
+
}).then(function (pointRevisions) {
|
|
492
|
+
async.eachSeries(pointRevisions, function (pointRevision, pointRevisionCallback) {
|
|
493
|
+
var pointRevisionJson = JSON.parse(JSON.stringify(pointRevision.toJSON()));
|
|
494
|
+
delete pointRevisionJson.id;
|
|
495
|
+
var newPointRevision = models.PointRevision.build(pointRevisionJson);
|
|
496
|
+
newPointRevision.set("point_id", newPoint.id);
|
|
497
|
+
newPointRevision
|
|
498
|
+
.save()
|
|
499
|
+
.then(function () {
|
|
500
|
+
pointRevisionCallback();
|
|
501
|
+
})
|
|
502
|
+
.catch((error) => {
|
|
503
|
+
pointRevisionCallback(error);
|
|
504
|
+
});
|
|
505
|
+
}, function (error) {
|
|
506
|
+
pointSeriesCallback(error);
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
function (pointSeriesCallback) {
|
|
511
|
+
if (!options.skipActivities) {
|
|
512
|
+
models.AcActivity.findAll({
|
|
513
|
+
where: {
|
|
514
|
+
point_id: currentOldPoint.id,
|
|
515
|
+
post_id: { $not: null },
|
|
516
|
+
},
|
|
517
|
+
}).then(function (activities) {
|
|
518
|
+
async.eachSeries(activities, function (activity, activitesSeriesCallback) {
|
|
519
|
+
skipPointActivitiesIdsForPostCopy.push(activity.id);
|
|
520
|
+
var activityJson = JSON.parse(JSON.stringify(activity.toJSON()));
|
|
521
|
+
delete activityJson.id;
|
|
522
|
+
var newActivity = models.AcActivity.build(activityJson);
|
|
523
|
+
newActivity.set("group_id", toGroup.id);
|
|
524
|
+
newActivity.set("community_id", toCommunityId);
|
|
525
|
+
newActivity.set("domain_id", toDomainId);
|
|
526
|
+
newActivity.set("point_id", newPoint.id);
|
|
527
|
+
newActivity
|
|
528
|
+
.save()
|
|
529
|
+
.then(function (results) {
|
|
530
|
+
console.log("Have changed group and all activity: " +
|
|
531
|
+
newActivity.id);
|
|
532
|
+
activitesSeriesCallback();
|
|
533
|
+
})
|
|
534
|
+
.catch((error) => {
|
|
535
|
+
activitesSeriesCallback(error);
|
|
536
|
+
});
|
|
537
|
+
}, function (error) {
|
|
538
|
+
pointSeriesCallback(error);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
pointSeriesCallback();
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
], function (error) {
|
|
547
|
+
innerSeriesCallback(error);
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
}, function (error) {
|
|
551
|
+
console.log("Have changed group and all for point");
|
|
552
|
+
callback();
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
callback();
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
function (callback) {
|
|
561
|
+
if (!options.skipActivities) {
|
|
562
|
+
models.AcActivity.findAll({
|
|
563
|
+
where: {
|
|
564
|
+
post_id: oldPost.id,
|
|
565
|
+
point_id: { $is: null },
|
|
566
|
+
},
|
|
567
|
+
})
|
|
568
|
+
.then(function (activities) {
|
|
569
|
+
async.eachSeries(activities, function (activity, innerSeriesCallback) {
|
|
570
|
+
var activityJson = JSON.parse(JSON.stringify(activity.toJSON()));
|
|
571
|
+
delete activityJson.id;
|
|
572
|
+
var newActivity = models.AcActivity.build(activityJson);
|
|
573
|
+
newActivity.set("group_id", toGroup.id);
|
|
574
|
+
newActivity.set("community_id", toCommunityId);
|
|
575
|
+
newActivity.set("domain_id", toDomainId);
|
|
576
|
+
newActivity.set("post_id", newPost.id);
|
|
577
|
+
newActivity.set("PostId", newPost.id);
|
|
578
|
+
newActivity
|
|
579
|
+
.save()
|
|
580
|
+
.then(function (results) {
|
|
581
|
+
console.log("Have changed group and all activity: " + newActivity.id);
|
|
582
|
+
innerSeriesCallback();
|
|
583
|
+
})
|
|
584
|
+
.catch((error) => {
|
|
585
|
+
innerSeriesCallback(error);
|
|
586
|
+
});
|
|
587
|
+
}, function (error) {
|
|
588
|
+
callback(error);
|
|
589
|
+
});
|
|
590
|
+
})
|
|
591
|
+
.catch((error) => {
|
|
592
|
+
callback(error);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
callback();
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
], function (error) {
|
|
600
|
+
console.log("Done copying post id " + fromPostId);
|
|
601
|
+
if (error)
|
|
602
|
+
console.error(error);
|
|
603
|
+
done(error, newPost);
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
const copyGroup = (fromGroupId, toCommunityIn, toDomainId, options, done) => {
|
|
607
|
+
let toCommunity;
|
|
608
|
+
let toDomain;
|
|
609
|
+
let newGroup;
|
|
610
|
+
let oldGroup;
|
|
611
|
+
async.series([
|
|
612
|
+
(callback) => {
|
|
613
|
+
models.Community.findOne({
|
|
614
|
+
where: {
|
|
615
|
+
id: toCommunityIn.id,
|
|
616
|
+
},
|
|
617
|
+
attributes: ["id"],
|
|
618
|
+
include: [
|
|
619
|
+
{
|
|
620
|
+
model: models.Domain,
|
|
621
|
+
attributes: ["id", "theme_id", "name"],
|
|
622
|
+
},
|
|
623
|
+
],
|
|
624
|
+
}).then((communityIn) => {
|
|
625
|
+
toCommunity = communityIn;
|
|
626
|
+
toDomain = communityIn.Domain.id;
|
|
627
|
+
toDomain = communityIn.Domain;
|
|
628
|
+
callback();
|
|
629
|
+
});
|
|
630
|
+
},
|
|
631
|
+
(callback) => {
|
|
632
|
+
var groupIncludes = [
|
|
633
|
+
{
|
|
634
|
+
model: models.Community,
|
|
635
|
+
attributes: [
|
|
636
|
+
"id",
|
|
637
|
+
"theme_id",
|
|
638
|
+
"name",
|
|
639
|
+
"access",
|
|
640
|
+
"google_analytics_code",
|
|
641
|
+
"configuration",
|
|
642
|
+
],
|
|
643
|
+
include: [
|
|
644
|
+
{
|
|
645
|
+
model: models.Domain,
|
|
646
|
+
attributes: ["id", "theme_id", "name"],
|
|
647
|
+
},
|
|
648
|
+
],
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
model: models.Category,
|
|
652
|
+
required: false,
|
|
653
|
+
include: [
|
|
654
|
+
{
|
|
655
|
+
model: models.Image,
|
|
656
|
+
required: false,
|
|
657
|
+
as: "CategoryIconImages",
|
|
658
|
+
attributes: ["id"],
|
|
659
|
+
},
|
|
660
|
+
],
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
model: models.User,
|
|
664
|
+
attributes: ["id"],
|
|
665
|
+
as: "GroupAdmins",
|
|
666
|
+
required: false,
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
model: models.Image,
|
|
670
|
+
as: "GroupLogoImages",
|
|
671
|
+
attributes: models.Image.defaultAttributesPublic,
|
|
672
|
+
required: false,
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
model: models.Video,
|
|
676
|
+
as: "GroupLogoVideos",
|
|
677
|
+
attributes: ["id", "formats", "viewable", "public_meta"],
|
|
678
|
+
required: false,
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
model: models.Image,
|
|
682
|
+
as: "GroupHeaderImages",
|
|
683
|
+
attributes: models.Image.defaultAttributesPublic,
|
|
684
|
+
required: false,
|
|
685
|
+
},
|
|
686
|
+
];
|
|
687
|
+
if (!options.skipUsers) {
|
|
688
|
+
groupIncludes.push({
|
|
689
|
+
model: models.User,
|
|
690
|
+
attributes: ["id"],
|
|
691
|
+
as: "GroupUsers",
|
|
692
|
+
required: false,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
models.Group.findOne({
|
|
696
|
+
where: {
|
|
697
|
+
id: fromGroupId,
|
|
698
|
+
},
|
|
699
|
+
include: groupIncludes,
|
|
700
|
+
})
|
|
701
|
+
.then(function (groupIn) {
|
|
702
|
+
oldGroup = groupIn;
|
|
703
|
+
var groupJson = JSON.parse(JSON.stringify(oldGroup.toJSON()));
|
|
704
|
+
delete groupJson["id"];
|
|
705
|
+
newGroup = models.Group.build(groupJson);
|
|
706
|
+
newGroup.set("community_id", toCommunity.id);
|
|
707
|
+
if (options.setInGroupFolderId) {
|
|
708
|
+
newGroup.set("in_group_folder_id", options.setInGroupFolderId);
|
|
709
|
+
}
|
|
710
|
+
if (options.skipUsers) {
|
|
711
|
+
newGroup.set("counter_users", 0);
|
|
712
|
+
}
|
|
713
|
+
if (!options.copyPoints) {
|
|
714
|
+
newGroup.set("counter_points", 0);
|
|
715
|
+
}
|
|
716
|
+
if (!options.copyPosts) {
|
|
717
|
+
newGroup.set("counter_posts", 0);
|
|
718
|
+
}
|
|
719
|
+
newGroup.save().then(function () {
|
|
720
|
+
async.series([
|
|
721
|
+
(groupSeriesCallback) => {
|
|
722
|
+
clonePagesForGroup(oldGroup, newGroup, groupSeriesCallback);
|
|
723
|
+
},
|
|
724
|
+
(groupSeriesCallback) => {
|
|
725
|
+
cloneTranslationForGroup(oldGroup, newGroup, groupSeriesCallback);
|
|
726
|
+
},
|
|
727
|
+
(groupSeriesCallback) => {
|
|
728
|
+
if (oldGroup.is_group_folder) {
|
|
729
|
+
models.Group.findAll({
|
|
730
|
+
where: {
|
|
731
|
+
in_group_folder_id: oldGroup.id,
|
|
732
|
+
},
|
|
733
|
+
attributes: ["id", "in_group_folder_id"],
|
|
734
|
+
})
|
|
735
|
+
.then((groupsInFolder) => {
|
|
736
|
+
async.eachSeries(groupsInFolder, function (groupInFolder, groupInFolderCallback) {
|
|
737
|
+
copyGroup(groupInFolder.id, toCommunity, toDomainId, {
|
|
738
|
+
...JSON.parse(JSON.stringify(options)),
|
|
739
|
+
setInGroupFolderId: newGroup.id,
|
|
740
|
+
}, (recursiveError, nestedNewGroup) => {
|
|
741
|
+
if (recursiveError) {
|
|
742
|
+
return groupInFolderCallback(recursiveError);
|
|
743
|
+
}
|
|
744
|
+
groupInFolderCallback();
|
|
745
|
+
});
|
|
746
|
+
}, (error) => {
|
|
747
|
+
groupSeriesCallback(error);
|
|
748
|
+
});
|
|
749
|
+
})
|
|
750
|
+
.catch((error) => {
|
|
751
|
+
groupSeriesCallback(error);
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
groupSeriesCallback();
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
(groupSeriesCallback) => {
|
|
759
|
+
if (options.deepCopyLinks &&
|
|
760
|
+
oldGroup.configuration &&
|
|
761
|
+
oldGroup.configuration.actAsLinkToCommunityId) {
|
|
762
|
+
copyCommunity(oldGroup.configuration.actAsLinkToCommunityId, toDomainId, options, { id: toCommunityIn.id, name: toCommunityIn.name }, (error, newCommunity) => {
|
|
763
|
+
if (error) {
|
|
764
|
+
groupSeriesCallback(error);
|
|
765
|
+
}
|
|
766
|
+
else {
|
|
767
|
+
newGroup.set("configuration.actAsLinkToCommunityId", newCommunity.id);
|
|
768
|
+
newGroup.save().then(function () {
|
|
769
|
+
groupSeriesCallback();
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
groupSeriesCallback();
|
|
776
|
+
}
|
|
777
|
+
},
|
|
778
|
+
(groupSeriesCallback) => {
|
|
779
|
+
if (oldGroup.GroupLogoImages &&
|
|
780
|
+
oldGroup.GroupLogoImages.length > 0) {
|
|
781
|
+
async.eachSeries(oldGroup.GroupLogoImages, function (image, mediaCallback) {
|
|
782
|
+
newGroup
|
|
783
|
+
.addGroupLogoImage(image)
|
|
784
|
+
.then(function () {
|
|
785
|
+
mediaCallback();
|
|
786
|
+
})
|
|
787
|
+
.catch((error) => {
|
|
788
|
+
mediaCallback(error);
|
|
789
|
+
});
|
|
790
|
+
}, function (error) {
|
|
791
|
+
groupSeriesCallback(error);
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
else {
|
|
795
|
+
groupSeriesCallback();
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
(groupSeriesCallback) => {
|
|
799
|
+
if (oldGroup.GroupHeaderImages &&
|
|
800
|
+
oldGroup.GroupHeaderImages.length > 0) {
|
|
801
|
+
async.eachSeries(oldGroup.GroupHeaderImages, function (image, mediaCallback) {
|
|
802
|
+
newGroup
|
|
803
|
+
.addGroupHeaderImage(image)
|
|
804
|
+
.then(function () {
|
|
805
|
+
mediaCallback();
|
|
806
|
+
})
|
|
807
|
+
.catch((error) => {
|
|
808
|
+
mediaCallback(error);
|
|
809
|
+
});
|
|
810
|
+
}, function (error) {
|
|
811
|
+
groupSeriesCallback(error);
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
groupSeriesCallback();
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
(groupSeriesCallback) => {
|
|
819
|
+
if (oldGroup.GroupLogoVideos &&
|
|
820
|
+
oldGroup.GroupLogoVideos.length > 0) {
|
|
821
|
+
async.eachSeries(oldGroup.GroupLogoVideos, function (image, mediaCallback) {
|
|
822
|
+
newGroup
|
|
823
|
+
.addGroupLogoVideo(image)
|
|
824
|
+
.then(function () {
|
|
825
|
+
mediaCallback();
|
|
826
|
+
})
|
|
827
|
+
.catch((error) => {
|
|
828
|
+
mediaCallback(error);
|
|
829
|
+
});
|
|
830
|
+
}, function (error) {
|
|
831
|
+
groupSeriesCallback(error);
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
groupSeriesCallback();
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
(groupSeriesCallback) => {
|
|
839
|
+
if (oldGroup.GroupAdmins &&
|
|
840
|
+
oldGroup.GroupAdmins.length > 0) {
|
|
841
|
+
async.eachSeries(oldGroup.GroupAdmins, function (admin, adminCallback) {
|
|
842
|
+
newGroup
|
|
843
|
+
.addGroupAdmin(admin)
|
|
844
|
+
.then(function () {
|
|
845
|
+
adminCallback();
|
|
846
|
+
})
|
|
847
|
+
.catch((error) => {
|
|
848
|
+
adminCallback(error);
|
|
849
|
+
});
|
|
850
|
+
}, function (error) {
|
|
851
|
+
groupSeriesCallback(error);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
groupSeriesCallback();
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
(groupSeriesCallback) => {
|
|
859
|
+
if (oldGroup.GroupUsers && oldGroup.GroupUsers.length > 0) {
|
|
860
|
+
async.eachSeries(oldGroup.GroupUsers, function (user, userCallback) {
|
|
861
|
+
newGroup
|
|
862
|
+
.addGroupUser(user)
|
|
863
|
+
.then(function () {
|
|
864
|
+
userCallback();
|
|
865
|
+
})
|
|
866
|
+
.catch((error) => {
|
|
867
|
+
userCallback(error);
|
|
868
|
+
});
|
|
869
|
+
}, function (error) {
|
|
870
|
+
groupSeriesCallback(error);
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
groupSeriesCallback();
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
(groupSeriesCallback) => {
|
|
878
|
+
if (oldGroup.Categories && oldGroup.Categories.length > 0) {
|
|
879
|
+
async.eachSeries(oldGroup.Categories, function (category, categoryCallback) {
|
|
880
|
+
const newCategoryJson = JSON.parse(JSON.stringify(category.toJSON()));
|
|
881
|
+
delete newCategoryJson.id;
|
|
882
|
+
const newCategoryModel = models.Category.build(newCategoryJson);
|
|
883
|
+
newCategoryModel.set("group_id", newGroup.id);
|
|
884
|
+
newCategoryModel
|
|
885
|
+
.save()
|
|
886
|
+
.then(() => {
|
|
887
|
+
if (category.CategoryIconImages &&
|
|
888
|
+
category.CategoryIconImages.length > 0) {
|
|
889
|
+
async.eachSeries(category.CategoryIconImages, (image, categoryImageCallBack) => {
|
|
890
|
+
newCategoryModel
|
|
891
|
+
.addCategoryIconImage(image)
|
|
892
|
+
.then(() => {
|
|
893
|
+
categoryImageCallBack();
|
|
894
|
+
})
|
|
895
|
+
.catch((error) => {
|
|
896
|
+
categoryImageCallBack(error);
|
|
897
|
+
});
|
|
898
|
+
}, (error) => {
|
|
899
|
+
categoryCallback(error);
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
categoryCallback();
|
|
904
|
+
}
|
|
905
|
+
})
|
|
906
|
+
.catch((error) => {
|
|
907
|
+
categoryCallback(error);
|
|
908
|
+
});
|
|
909
|
+
}, (error) => {
|
|
910
|
+
groupSeriesCallback(error);
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
groupSeriesCallback();
|
|
915
|
+
}
|
|
916
|
+
},
|
|
917
|
+
(groupSeriesCallback) => {
|
|
918
|
+
if (options && options.copyPosts === true) {
|
|
919
|
+
models.Post.findAll({
|
|
920
|
+
where: {
|
|
921
|
+
group_id: oldGroup.id,
|
|
922
|
+
},
|
|
923
|
+
attributes: ["id"],
|
|
924
|
+
})
|
|
925
|
+
.then((posts) => {
|
|
926
|
+
async.eachSeries(posts, function (post, postCallback) {
|
|
927
|
+
copyPost(post.id, newGroup.id, options, postCallback);
|
|
928
|
+
}, function (error) {
|
|
929
|
+
groupSeriesCallback(error);
|
|
930
|
+
});
|
|
931
|
+
})
|
|
932
|
+
.catch((error) => {
|
|
933
|
+
groupSeriesCallback(error);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
groupSeriesCallback();
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
(groupSeriesCallback) => {
|
|
941
|
+
if (options.recountGroupPosts) {
|
|
942
|
+
models.Post.count({
|
|
943
|
+
where: {
|
|
944
|
+
group_id: newGroup.id,
|
|
945
|
+
},
|
|
946
|
+
})
|
|
947
|
+
.then((count) => {
|
|
948
|
+
newGroup.set("counter_posts", count);
|
|
949
|
+
newGroup.save().then(function () {
|
|
950
|
+
groupSeriesCallback();
|
|
951
|
+
});
|
|
952
|
+
})
|
|
953
|
+
.catch((error) => {
|
|
954
|
+
groupSeriesCallback(error);
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
groupSeriesCallback();
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
], function (error) {
|
|
962
|
+
console.log("Have copied post to group id");
|
|
963
|
+
callback(error);
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
})
|
|
967
|
+
.catch(function (error) {
|
|
968
|
+
callback(error);
|
|
969
|
+
});
|
|
970
|
+
},
|
|
971
|
+
], function (error) {
|
|
972
|
+
console.log("Done copying group");
|
|
973
|
+
if (error)
|
|
974
|
+
console.error(error);
|
|
975
|
+
done(error, newGroup);
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
const copyCommunity = (fromCommunityId, toDomainId, options, linkFromOptions, done) => {
|
|
979
|
+
let toDomain;
|
|
980
|
+
let newCommunity = null;
|
|
981
|
+
let oldCommunity;
|
|
982
|
+
const groupMapping = new Map();
|
|
983
|
+
async.series([
|
|
984
|
+
(callback) => {
|
|
985
|
+
models.Domain.findOne({
|
|
986
|
+
where: {
|
|
987
|
+
id: toDomainId,
|
|
988
|
+
},
|
|
989
|
+
attributes: ["id"],
|
|
990
|
+
})
|
|
991
|
+
.then((domainIn) => {
|
|
992
|
+
toDomain = domainIn;
|
|
993
|
+
callback();
|
|
994
|
+
})
|
|
995
|
+
.catch((error) => {
|
|
996
|
+
callback(error);
|
|
997
|
+
});
|
|
998
|
+
},
|
|
999
|
+
(callback) => {
|
|
1000
|
+
var communityIncludes = [
|
|
1001
|
+
{
|
|
1002
|
+
model: models.Domain,
|
|
1003
|
+
attributes: ["id", "theme_id", "name"],
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
model: models.User,
|
|
1007
|
+
attributes: ["id"],
|
|
1008
|
+
as: "CommunityAdmins",
|
|
1009
|
+
required: false,
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
model: models.Image,
|
|
1013
|
+
as: "CommunityLogoImages",
|
|
1014
|
+
attributes: models.Image.defaultAttributesPublic,
|
|
1015
|
+
required: false,
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
model: models.Video,
|
|
1019
|
+
as: "CommunityLogoVideos",
|
|
1020
|
+
attributes: ["id", "formats", "viewable", "public_meta"],
|
|
1021
|
+
required: false,
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
model: models.Image,
|
|
1025
|
+
as: "CommunityHeaderImages",
|
|
1026
|
+
attributes: models.Image.defaultAttributesPublic,
|
|
1027
|
+
required: false,
|
|
1028
|
+
},
|
|
1029
|
+
];
|
|
1030
|
+
if (!options.skipUsers) {
|
|
1031
|
+
communityIncludes.push({
|
|
1032
|
+
model: models.User,
|
|
1033
|
+
attributes: ["id"],
|
|
1034
|
+
as: "CommunityUsers",
|
|
1035
|
+
required: false,
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
models.Community.findOne({
|
|
1039
|
+
where: {
|
|
1040
|
+
id: fromCommunityId,
|
|
1041
|
+
},
|
|
1042
|
+
include: communityIncludes,
|
|
1043
|
+
})
|
|
1044
|
+
.then(function (communityIn) {
|
|
1045
|
+
oldCommunity = communityIn;
|
|
1046
|
+
var communityJson = JSON.parse(JSON.stringify(oldCommunity.toJSON()));
|
|
1047
|
+
delete communityJson["id"];
|
|
1048
|
+
newCommunity = models.Community.build(communityJson);
|
|
1049
|
+
newCommunity.set("domain_id", toDomain.id);
|
|
1050
|
+
if (options.skipUsers) {
|
|
1051
|
+
newCommunity.set("counter_users", 0);
|
|
1052
|
+
}
|
|
1053
|
+
if (linkFromOptions) {
|
|
1054
|
+
newCommunity.set("configuration.customBackURL", `/community/${linkFromOptions.id}`);
|
|
1055
|
+
newCommunity.set("configuration.customBackName", linkFromOptions.name);
|
|
1056
|
+
}
|
|
1057
|
+
if (newCommunity.hostname) {
|
|
1058
|
+
newCommunity.set("hostname", newCommunity.hostname + "-copy");
|
|
1059
|
+
}
|
|
1060
|
+
newCommunity.set("configuration.useAsTemplate", false);
|
|
1061
|
+
newCommunity.save().then(function () {
|
|
1062
|
+
async.series([
|
|
1063
|
+
(communitySeriesCallback) => {
|
|
1064
|
+
clonePagesForCommunity(oldCommunity, newCommunity, communitySeriesCallback);
|
|
1065
|
+
},
|
|
1066
|
+
(communitySeriesCallback) => {
|
|
1067
|
+
cloneTranslationForCommunity(oldCommunity, newCommunity, communitySeriesCallback);
|
|
1068
|
+
},
|
|
1069
|
+
(communitySeriesCallback) => {
|
|
1070
|
+
if (oldCommunity.CommunityLogoImages &&
|
|
1071
|
+
oldCommunity.CommunityLogoImages.length > 0) {
|
|
1072
|
+
async.eachSeries(oldCommunity.CommunityLogoImages, function (image, mediaCallback) {
|
|
1073
|
+
newCommunity
|
|
1074
|
+
.addCommunityLogoImage(image)
|
|
1075
|
+
.then(function () {
|
|
1076
|
+
mediaCallback();
|
|
1077
|
+
})
|
|
1078
|
+
.catch((error) => {
|
|
1079
|
+
mediaCallback(error);
|
|
1080
|
+
});
|
|
1081
|
+
}, function (error) {
|
|
1082
|
+
communitySeriesCallback(error);
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
else {
|
|
1086
|
+
communitySeriesCallback();
|
|
1087
|
+
}
|
|
1088
|
+
},
|
|
1089
|
+
(communitySeriesCallback) => {
|
|
1090
|
+
if (oldCommunity.CommunityHeaderImages &&
|
|
1091
|
+
oldCommunity.CommunityHeaderImages.length > 0) {
|
|
1092
|
+
async.eachSeries(oldCommunity.CommunityHeaderImages, function (image, mediaCallback) {
|
|
1093
|
+
newCommunity
|
|
1094
|
+
.addCommunityHeaderImage(image)
|
|
1095
|
+
.then(function () {
|
|
1096
|
+
mediaCallback();
|
|
1097
|
+
})
|
|
1098
|
+
.catch((error) => {
|
|
1099
|
+
mediaCallback(error);
|
|
1100
|
+
});
|
|
1101
|
+
}, function (error) {
|
|
1102
|
+
communitySeriesCallback(error);
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
communitySeriesCallback();
|
|
1107
|
+
}
|
|
1108
|
+
},
|
|
1109
|
+
(communitySeriesCallback) => {
|
|
1110
|
+
if (oldCommunity.CommunityLogoVideos &&
|
|
1111
|
+
oldCommunity.CommunityLogoVideos.length > 0) {
|
|
1112
|
+
async.eachSeries(oldCommunity.CommunityLogoVideos, function (image, mediaCallback) {
|
|
1113
|
+
newCommunity
|
|
1114
|
+
.addCommunityLogoVideo(image)
|
|
1115
|
+
.then(function () {
|
|
1116
|
+
mediaCallback();
|
|
1117
|
+
})
|
|
1118
|
+
.catch((error) => {
|
|
1119
|
+
mediaCallback(error);
|
|
1120
|
+
});
|
|
1121
|
+
}, function (error) {
|
|
1122
|
+
communitySeriesCallback(error);
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
communitySeriesCallback();
|
|
1127
|
+
}
|
|
1128
|
+
},
|
|
1129
|
+
(communitySeriesCallback) => {
|
|
1130
|
+
if (oldCommunity.CommunityAdmins &&
|
|
1131
|
+
oldCommunity.CommunityAdmins.length > 0) {
|
|
1132
|
+
async.eachSeries(oldCommunity.CommunityAdmins, function (admin, adminCallback) {
|
|
1133
|
+
newCommunity
|
|
1134
|
+
.addCommunityAdmin(admin)
|
|
1135
|
+
.then(function () {
|
|
1136
|
+
adminCallback();
|
|
1137
|
+
})
|
|
1138
|
+
.catch((error) => {
|
|
1139
|
+
adminCallback(error);
|
|
1140
|
+
});
|
|
1141
|
+
}, function (error) {
|
|
1142
|
+
communitySeriesCallback(error);
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
communitySeriesCallback();
|
|
1147
|
+
}
|
|
1148
|
+
},
|
|
1149
|
+
(communitySeriesCallback) => {
|
|
1150
|
+
if (oldCommunity.CommunityUsers &&
|
|
1151
|
+
oldCommunity.CommunityUsers.length > 0) {
|
|
1152
|
+
async.eachSeries(oldCommunity.CommunityUsers, function (user, userCallback) {
|
|
1153
|
+
newCommunity
|
|
1154
|
+
.addCommunityUser(user)
|
|
1155
|
+
.then(function () {
|
|
1156
|
+
userCallback();
|
|
1157
|
+
})
|
|
1158
|
+
.catch((error) => {
|
|
1159
|
+
userCallback(error);
|
|
1160
|
+
});
|
|
1161
|
+
}, function (error) {
|
|
1162
|
+
communitySeriesCallback(error);
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
else {
|
|
1166
|
+
communitySeriesCallback();
|
|
1167
|
+
}
|
|
1168
|
+
},
|
|
1169
|
+
(communitySeriesCallback) => {
|
|
1170
|
+
if (options &&
|
|
1171
|
+
(options.copyGroups === true || options.copyOneGroupId)) {
|
|
1172
|
+
let whereOptions = {
|
|
1173
|
+
community_id: oldCommunity.id,
|
|
1174
|
+
in_group_folder_id: {
|
|
1175
|
+
$eq: null,
|
|
1176
|
+
},
|
|
1177
|
+
};
|
|
1178
|
+
if (options.copyOneGroupId) {
|
|
1179
|
+
whereOptions = {
|
|
1180
|
+
...whereOptions,
|
|
1181
|
+
id: options.copyOneGroupId,
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
models.Group.findAll({
|
|
1185
|
+
where: whereOptions,
|
|
1186
|
+
attributes: ["id"],
|
|
1187
|
+
})
|
|
1188
|
+
.then((groups) => {
|
|
1189
|
+
async.eachSeries(groups, function (group, groupCallback) {
|
|
1190
|
+
copyGroup(group.id, newCommunity, toDomainId, options, (error, newGroup) => {
|
|
1191
|
+
if (!error && newGroup) {
|
|
1192
|
+
groupMapping.set(group.id, newGroup.id);
|
|
1193
|
+
}
|
|
1194
|
+
groupCallback(error);
|
|
1195
|
+
});
|
|
1196
|
+
}, function (error) {
|
|
1197
|
+
communitySeriesCallback(error);
|
|
1198
|
+
});
|
|
1199
|
+
})
|
|
1200
|
+
.catch((error) => {
|
|
1201
|
+
communitySeriesCallback(error);
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
else {
|
|
1205
|
+
communitySeriesCallback();
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
], function (error) {
|
|
1209
|
+
console.log("Have copied community");
|
|
1210
|
+
callback(error);
|
|
1211
|
+
});
|
|
1212
|
+
});
|
|
1213
|
+
})
|
|
1214
|
+
.catch(function (error) {
|
|
1215
|
+
callback(error);
|
|
1216
|
+
});
|
|
1217
|
+
},
|
|
1218
|
+
], function (error) {
|
|
1219
|
+
console.log("Done copying community", newCommunity);
|
|
1220
|
+
if (error) {
|
|
1221
|
+
console.error(error);
|
|
1222
|
+
done(error);
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
models.Group.count({
|
|
1226
|
+
where: {
|
|
1227
|
+
community_id: newCommunity.id,
|
|
1228
|
+
},
|
|
1229
|
+
})
|
|
1230
|
+
.then((count) => {
|
|
1231
|
+
newCommunity
|
|
1232
|
+
.update({
|
|
1233
|
+
counter_groups: count,
|
|
1234
|
+
})
|
|
1235
|
+
.then(() => {
|
|
1236
|
+
newCommunity.groupMapping = groupMapping;
|
|
1237
|
+
done(error, typeof newCommunity != "undefined" ? newCommunity : null);
|
|
1238
|
+
})
|
|
1239
|
+
.catch((error) => {
|
|
1240
|
+
done(error);
|
|
1241
|
+
});
|
|
1242
|
+
})
|
|
1243
|
+
.catch((error) => {
|
|
1244
|
+
done(error);
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
};
|
|
1249
|
+
const copyCommunityWithEverything = (communityId, toDomainId, options, done) => {
|
|
1250
|
+
copyCommunity(communityId, toDomainId, {
|
|
1251
|
+
copyGroups: true,
|
|
1252
|
+
copyPosts: true,
|
|
1253
|
+
copyPoints: true,
|
|
1254
|
+
}, null, (error, newCommunity) => {
|
|
1255
|
+
if (newCommunity)
|
|
1256
|
+
console.log(newCommunity.id);
|
|
1257
|
+
if (error) {
|
|
1258
|
+
console.error(error);
|
|
1259
|
+
done(error, newCommunity);
|
|
1260
|
+
}
|
|
1261
|
+
else {
|
|
1262
|
+
//console.log("Done for new community "+ńewCommunity.id);
|
|
1263
|
+
done(null, newCommunity);
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
};
|
|
1267
|
+
const deepCopyCommunityOnlyStructureWithAdminsAndPosts = (communityId, toDomainId, done) => {
|
|
1268
|
+
copyCommunity(communityId, toDomainId, {
|
|
1269
|
+
copyGroups: true,
|
|
1270
|
+
copyPosts: true,
|
|
1271
|
+
copyPoints: false,
|
|
1272
|
+
recountGroupPosts: true,
|
|
1273
|
+
deepCopyLinks: true,
|
|
1274
|
+
skipUsers: true,
|
|
1275
|
+
skipEndorsementQualitiesAndRatings: true,
|
|
1276
|
+
resetEndorsementCounters: true,
|
|
1277
|
+
skipActivities: true,
|
|
1278
|
+
}, null, (error, newCommunity) => {
|
|
1279
|
+
if (newCommunity)
|
|
1280
|
+
console.log(newCommunity.id);
|
|
1281
|
+
if (error) {
|
|
1282
|
+
console.error(error);
|
|
1283
|
+
done(error, newCommunity);
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
//console.log("Done for new community "+ńewCommunity.id);
|
|
1287
|
+
done(null, newCommunity);
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
};
|
|
1291
|
+
const copyCommunityNoUsersNoEndorsementsNoPoints = (communityId, toDomainId, done) => {
|
|
1292
|
+
copyCommunity(communityId, toDomainId, {
|
|
1293
|
+
copyGroups: true,
|
|
1294
|
+
copyPosts: true,
|
|
1295
|
+
copyPoints: false,
|
|
1296
|
+
skipUsers: true,
|
|
1297
|
+
skipEndorsementQualitiesAndRatings: true,
|
|
1298
|
+
resetEndorsementCounters: true,
|
|
1299
|
+
skipActivities: true,
|
|
1300
|
+
}, null, (error, newCommunity) => {
|
|
1301
|
+
if (newCommunity)
|
|
1302
|
+
console.log(newCommunity.id);
|
|
1303
|
+
if (error) {
|
|
1304
|
+
console.error(error);
|
|
1305
|
+
done(error, newCommunity);
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
recountCommunity(newCommunity.id, (recountError) => {
|
|
1309
|
+
if (recountError) {
|
|
1310
|
+
console.error(error);
|
|
1311
|
+
done(recountError, newCommunity);
|
|
1312
|
+
}
|
|
1313
|
+
else {
|
|
1314
|
+
done(null, newCommunity);
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
};
|
|
1320
|
+
const copyCommunityNoUsersNoEndorsements = (communityId, toDomainId, done) => {
|
|
1321
|
+
copyCommunity(communityId, toDomainId, {
|
|
1322
|
+
copyGroups: true,
|
|
1323
|
+
copyPosts: true,
|
|
1324
|
+
copyPoints: true,
|
|
1325
|
+
skipUsers: true,
|
|
1326
|
+
skipEndorsementQualitiesAndRatings: true,
|
|
1327
|
+
resetEndorsementCounters: true,
|
|
1328
|
+
skipActivities: true,
|
|
1329
|
+
}, null, (error, newCommunity) => {
|
|
1330
|
+
if (newCommunity)
|
|
1331
|
+
console.log(newCommunity.id);
|
|
1332
|
+
if (error) {
|
|
1333
|
+
console.error(error);
|
|
1334
|
+
done(error, newCommunity);
|
|
1335
|
+
}
|
|
1336
|
+
else {
|
|
1337
|
+
//console.log("Done for new community "+ńewCommunity.id);
|
|
1338
|
+
done(null, newCommunity);
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
};
|
|
1342
|
+
const copyCommunityNoUsersNoEndorsementsOneGroup = (communityId, groupId, toDomainId, done) => {
|
|
1343
|
+
copyCommunity(communityId, toDomainId, {
|
|
1344
|
+
copyOneGroupId: groupId,
|
|
1345
|
+
copyPosts: true,
|
|
1346
|
+
copyPoints: true,
|
|
1347
|
+
skipUsers: true,
|
|
1348
|
+
skipEndorsementQualitiesAndRatings: true,
|
|
1349
|
+
resetEndorsementCounters: true,
|
|
1350
|
+
skipActivities: true,
|
|
1351
|
+
}, null, (error, newCommunity) => {
|
|
1352
|
+
if (newCommunity)
|
|
1353
|
+
console.log(newCommunity.id);
|
|
1354
|
+
if (error) {
|
|
1355
|
+
console.error(error);
|
|
1356
|
+
done(error, newCommunity);
|
|
1357
|
+
}
|
|
1358
|
+
else {
|
|
1359
|
+
//console.log("Done for new community "+ńewCommunity.id);
|
|
1360
|
+
done(null, newCommunity);
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
};
|
|
1364
|
+
const copyCommunityOnlyGroups = (communityId, toDomainId, done) => {
|
|
1365
|
+
copyCommunity(communityId, toDomainId, {
|
|
1366
|
+
copyGroups: true,
|
|
1367
|
+
copyPosts: false,
|
|
1368
|
+
copyPoints: false,
|
|
1369
|
+
skipUsers: true,
|
|
1370
|
+
recountGroupPosts: true,
|
|
1371
|
+
skipEndorsementQualitiesAndRatings: true,
|
|
1372
|
+
resetEndorsementCounters: true,
|
|
1373
|
+
skipActivities: true,
|
|
1374
|
+
}, null, (error, newCommunity) => {
|
|
1375
|
+
if (newCommunity)
|
|
1376
|
+
console.log(newCommunity.id);
|
|
1377
|
+
if (error) {
|
|
1378
|
+
console.error(error);
|
|
1379
|
+
done(error, newCommunity);
|
|
1380
|
+
}
|
|
1381
|
+
else {
|
|
1382
|
+
//console.log("Done for new community "+ńewCommunity.id);
|
|
1383
|
+
done(null, newCommunity);
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
};
|
|
1387
|
+
module.exports = {
|
|
1388
|
+
copyCommunityNoUsersNoEndorsementsOneGroup,
|
|
1389
|
+
copyCommunityNoUsersNoEndorsements,
|
|
1390
|
+
copyCommunityNoUsersNoEndorsementsNoPoints,
|
|
1391
|
+
copyCommunityWithEverything,
|
|
1392
|
+
clonePagesForGroup,
|
|
1393
|
+
deepCopyCommunityOnlyStructureWithAdminsAndPosts,
|
|
1394
|
+
clonePagesForCommunity,
|
|
1395
|
+
copyCommunity,
|
|
1396
|
+
copyCommunityOnlyGroups,
|
|
1397
|
+
copyGroup,
|
|
1398
|
+
copyPost,
|
|
1399
|
+
};
|