From 89d5605874939d129753794e3bb1f31db01c72ea Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 22 Jun 2018 15:33:02 +0100 Subject: [PATCH] Add script that refreshes all v1 users' features in v2 --- services/web/scripts/sync_v1_subscriptions.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 services/web/scripts/sync_v1_subscriptions.js diff --git a/services/web/scripts/sync_v1_subscriptions.js b/services/web/scripts/sync_v1_subscriptions.js new file mode 100644 index 0000000000..f6ba9c9ce2 --- /dev/null +++ b/services/web/scripts/sync_v1_subscriptions.js @@ -0,0 +1,37 @@ +const {db} = require('../app/js/infrastructure/mongojs') +const FeaturesUpdater = require( + '../app/js/Features/Subscription/FeaturesUpdater' +) +const V1SubscriptionManager = require( + '../app/js/Features/Subscription/V1SubscriptionManager' +) +const async = require('async') +const logger = require('logger-sharelatex') +logger.logger.level('error') + +db.users.find({ + 'overleaf.id': { $exists: true } +}, { + overleaf: 1 +}, function (error, users) { + if (error) throw error + console.log('Found users:', users.length) + async.mapSeries(users, function (user, callback) { + console.log('refreshing in v2', user._id) + FeaturesUpdater.refreshFeatures(user._id, false, function (error) { + if (error) console.error('ERROR', error) + console.log('refreshing in v1', user._id) + V1SubscriptionManager.notifyV1OfFeaturesChange( + user._id, + function (error) { + if (error) console.error('ERROR', error) + callback() + } + ) + }) + }, function (error) { + if (error) throw error + console.log('FINISHED!') + process.exit() + }) +})