sync_v1_subscriptions.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const {db} = require('../app/js/infrastructure/mongojs')
  2. const FeaturesUpdater = require(
  3. '../app/js/Features/Subscription/FeaturesUpdater'
  4. )
  5. const V1SubscriptionManager = require(
  6. '../app/js/Features/Subscription/V1SubscriptionManager'
  7. )
  8. const async = require('async')
  9. const logger = require('logger-sharelatex')
  10. logger.logger.level('error')
  11. db.users.find({
  12. 'overleaf.id': { $exists: true }
  13. }, {
  14. overleaf: 1
  15. }, function (error, users) {
  16. if (error) throw error
  17. console.log('Found users:', users.length)
  18. async.mapSeries(users, function (user, callback) {
  19. console.log('refreshing in v2', user._id)
  20. FeaturesUpdater.refreshFeatures(user._id, false, function (error) {
  21. if (error) console.error('ERROR', error)
  22. console.log('refreshing in v1', user._id)
  23. V1SubscriptionManager.notifyV1OfFeaturesChange(
  24. user._id,
  25. function (error) {
  26. if (error) console.error('ERROR', error)
  27. callback()
  28. }
  29. )
  30. })
  31. }, function (error) {
  32. if (error) throw error
  33. console.log('FINISHED!')
  34. process.exit()
  35. })
  36. })