2018-11-05 05:06:39 -05:00
|
|
|
const { db } = require('../app/js/infrastructure/mongojs')
|
|
|
|
const FeaturesUpdater = require('../app/js/Features/Subscription/FeaturesUpdater')
|
|
|
|
const V1SubscriptionManager = require('../app/js/Features/Subscription/V1SubscriptionManager')
|
2018-06-22 10:33:02 -04:00
|
|
|
const async = require('async')
|
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
logger.logger.level('error')
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
const areFeaturesEqual = function(featuresA, featuresB) {
|
2018-06-26 06:07:13 -04:00
|
|
|
for (const feature in featuresA) {
|
|
|
|
if (featuresA[feature] !== featuresB[feature]) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
var outOfSyncUserCount = 0
|
|
|
|
var userCount = null
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
db.users.find(
|
|
|
|
{
|
|
|
|
'overleaf.id': { $exists: true }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
overleaf: 1,
|
|
|
|
features: 1
|
|
|
|
},
|
|
|
|
function(error, users) {
|
|
|
|
if (error) throw error
|
|
|
|
console.log('USER COUNT', (userCount = users.length))
|
|
|
|
async.mapSeries(
|
|
|
|
users,
|
|
|
|
function(user, callback) {
|
|
|
|
console.log('REFRESHING IN v2', user._id)
|
|
|
|
FeaturesUpdater.refreshFeatures(user._id, false, function(error) {
|
2018-06-22 10:33:02 -04:00
|
|
|
if (error) console.error('ERROR', error)
|
2018-11-05 05:06:39 -05:00
|
|
|
console.log('REFRESHING IN v1', user._id)
|
|
|
|
V1SubscriptionManager.notifyV1OfFeaturesChange(user._id, function(
|
|
|
|
error
|
|
|
|
) {
|
|
|
|
if (error) console.error('ERROR', error)
|
|
|
|
db.users.find(
|
|
|
|
{
|
|
|
|
_id: user._id
|
|
|
|
},
|
|
|
|
{
|
|
|
|
features: 1
|
|
|
|
},
|
|
|
|
function(error, [updatedUser]) {
|
|
|
|
if (error) throw error
|
|
|
|
if (areFeaturesEqual(user.features, updatedUser.features)) {
|
|
|
|
console.log('UNCHANGED', user._id)
|
|
|
|
} else {
|
|
|
|
console.log('MODIFIED', user._id)
|
|
|
|
outOfSyncUserCount = outOfSyncUserCount + 1
|
|
|
|
}
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
)
|
2018-06-26 06:07:13 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
},
|
|
|
|
function(error) {
|
|
|
|
if (error) throw error
|
|
|
|
console.log('FINISHED!')
|
|
|
|
console.log('OUT OF SYNC USERS', outOfSyncUserCount, '/', userCount)
|
|
|
|
process.exit()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|