mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	added upgrade for global keys
This commit is contained in:
		| @@ -16,7 +16,7 @@ var db = require('./database'), | |||||||
|  |  | ||||||
| Upgrade.check = function(callback) { | Upgrade.check = function(callback) { | ||||||
| 	// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema | 	// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema | ||||||
| 	var	latestSchema = new Date(2013, 10, 26).getTime(); | 	var	latestSchema = new Date(2013, 11, 2).getTime(); | ||||||
|  |  | ||||||
| 	RDB.get('schemaDate', function(err, value) { | 	RDB.get('schemaDate', function(err, value) { | ||||||
| 		if (parseInt(value, 10) >= latestSchema) { | 		if (parseInt(value, 10) >= latestSchema) { | ||||||
| @@ -184,7 +184,7 @@ Upgrade.upgrade = function(callback) { | |||||||
| 		}, | 		}, | ||||||
| 		function(next) { | 		function(next) { | ||||||
| 			thisSchemaDate = new Date(2013, 10, 26).getTime(); | 			thisSchemaDate = new Date(2013, 10, 26).getTime(); | ||||||
| 			if (schemaDate < thisSchemaDate || 1) { | 			if (schemaDate < thisSchemaDate) { | ||||||
| 				categories.getAllCategories(0, function(err, categories) { | 				categories.getAllCategories(0, function(err, categories) { | ||||||
|  |  | ||||||
| 					function updateIcon(category, next) { | 					function updateIcon(category, next) { | ||||||
| @@ -214,7 +214,57 @@ Upgrade.upgrade = function(callback) { | |||||||
| 				winston.info('[2013/11/26] Update to Category icons skipped.'); | 				winston.info('[2013/11/26] Update to Category icons skipped.'); | ||||||
| 				next(); | 				next(); | ||||||
| 			} | 			} | ||||||
| 		} | 		}, | ||||||
|  | 		function(next) { | ||||||
|  |  | ||||||
|  | 			function updateKeyToHash(key, next) { | ||||||
|  | 				RDB.get(key, function(err, value) { | ||||||
|  | 					RDB.hset('global', newKeys[key], value, next); | ||||||
|  | 				}); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			thisSchemaDate = new Date(2013, 11, 2).getTime(); | ||||||
|  | 			if (schemaDate < thisSchemaDate) { | ||||||
|  |  | ||||||
|  | 				var keys = [ | ||||||
|  | 					'global:next_user_id', | ||||||
|  | 					'next_topic_id', | ||||||
|  | 					'next_gid', | ||||||
|  | 					'notifications:next_nid', | ||||||
|  | 					'global:next_category_id', | ||||||
|  | 					'global:next_message_id', | ||||||
|  | 					'global:next_post_id', | ||||||
|  | 					'usercount', | ||||||
|  | 					'totaltopiccount', | ||||||
|  | 					'totalpostcount' | ||||||
|  | 				]; | ||||||
|  |  | ||||||
|  | 				var newKeys = { | ||||||
|  | 					'global:next_user_id':'nextUid', | ||||||
|  | 					'next_topic_id':'nextTid', | ||||||
|  | 					'next_gid':'nextGid', | ||||||
|  | 					'notifications:next_nid':'nextNid', | ||||||
|  | 					'global:next_category_id':'nextCid', | ||||||
|  | 					'global:next_message_id':'nextMid', | ||||||
|  | 					'global:next_post_id':'nextPid', | ||||||
|  | 					'usercount':'userCount', | ||||||
|  | 					'totaltopiccount':'topicCount', | ||||||
|  | 					'totalpostcount':'postCount' | ||||||
|  | 				}; | ||||||
|  |  | ||||||
|  | 				async.each(keys, updateKeyToHash, function(err) { | ||||||
|  | 					if(err) { | ||||||
|  | 						return next(err); | ||||||
|  | 					} | ||||||
|  | 					winston.info('[2013/12/2] Updated global keys to hash.'); | ||||||
|  | 					next(); | ||||||
|  | 				}); | ||||||
|  |  | ||||||
|  | 			} else { | ||||||
|  | 				winston.info('[2013/12/2] Update to global keys skipped'); | ||||||
|  | 				next(); | ||||||
|  | 			} | ||||||
|  | 		}, | ||||||
| 		// Add new schema updates here | 		// Add new schema updates here | ||||||
| 		// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!! | 		// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!! | ||||||
| 	], function(err) { | 	], function(err) { | ||||||
|   | |||||||
| @@ -107,7 +107,7 @@ var bcrypt = require('bcrypt'), | |||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				plugins.fireHook('action:user.create', {uid: uid, username: username, email: email, picture: gravatar, timestamp: timestamp}); | 				plugins.fireHook('action:user.create', {uid: uid, username: username, email: email, picture: gravatar, timestamp: timestamp}); | ||||||
| 				db.incrObjectField('global', 'usercount'); | 				db.incrObjectField('global', 'userCount'); | ||||||
|  |  | ||||||
| 				db.sortedSetAdd('users:joindate', timestamp, uid); | 				db.sortedSetAdd('users:joindate', timestamp, uid); | ||||||
| 				db.sortedSetAdd('users:postcount', 0, uid); | 				db.sortedSetAdd('users:postcount', 0, uid); | ||||||
| @@ -597,7 +597,7 @@ var bcrypt = require('bcrypt'), | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	User.count = function(socket) { | 	User.count = function(socket) { | ||||||
| 		db.getObjectField('global', 'usercount', function(err, count) { | 		db.getObjectField('global', 'userCount', function(err, count) { | ||||||
| 			if(err) { | 			if(err) { | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user