-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7145 from RocketChat/unsubscribe2js
Convert file unsubscribe.coffee to js
- Loading branch information
Showing
3 changed files
with
45 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import lineReader from 'line-reader'; | ||
import program from 'commander'; | ||
import wait from 'wait.for'; | ||
import {MongoClient} from 'mongodb'; | ||
|
||
program.usage('[options]').option('-v, --verbose', 'Verbose', (function(v, total) { | ||
return total + 1; | ||
}), 0).option('-M, --mongo-db [mongo db]', 'Mongo DB', 'localhost:27017').option('-N, --db-name [db name]', 'DB Name', 'meteor').on('--help', function() { | ||
console.log(' Example:'); | ||
console.log(''); | ||
console.log(' $ coffee unsubscribe.coffee'); | ||
return console.log(''); | ||
}).parse(process.argv); | ||
|
||
wait.launchFiber(function() { | ||
const db = wait.forMethod(MongoClient, 'connect', `mongodb://${ program.mongoDb }/${ program.dbName }`, { | ||
replSet: { | ||
socketOptions: { | ||
connectTimeoutMS: 300000 | ||
} | ||
} | ||
}); | ||
|
||
const User = db.collection('users'); | ||
return lineReader.eachLine('./unsubscribe.csv', function(line, last) { | ||
const row = line.split(','); | ||
if (program.verbose) { | ||
console.log(row[0]); | ||
} | ||
return wait.launchFiber(function() { | ||
wait.forMethod(User, 'update', { | ||
'emails.address': row[0] | ||
}, { | ||
$set: { | ||
'mailer.unsubscribed': true | ||
} | ||
}); | ||
|
||
if (last) { | ||
return process.exit(); | ||
} | ||
}); | ||
}); | ||
}); |