Remove package settings if package is not loaded

pull/926/head
Marcelo Schmidt 10 years ago
parent 11ef703011
commit bc847d2228
  1. 4
      packages/rocketchat-lib/settings/lib/rocketchat.coffee
  2. 23
      packages/rocketchat-lib/settings/server/methods.coffee
  3. 4
      server/startup/settings.coffee

@ -4,6 +4,8 @@
###
RocketChat.settings = {}
RocketChat.settings.ts = new Date
RocketChat.settings.get = (_id) ->
return Meteor.settings?[_id]
@ -20,4 +22,4 @@ RocketChat.settings.batchSet = (settings, callback) ->
Meteor.call 'saveSetting', setting._id, setting.value, callback
actions = _.map settings, (setting) -> save(setting)
_(actions).reduceRight(_.wrap, (err, success) -> return callback err, success)()
_(actions).reduceRight(_.wrap, (err, success) -> return callback err, success)()

@ -16,15 +16,22 @@ RocketChat.settings.add = (_id, value, options = {}) ->
updateSettings =
i18nLabel: options.i18nLabel or _id
i18nDescription: options.i18nDescription if options.i18nDescription?
updateSettings.i18nDescription = options.i18nDescription if options.i18nDescription?
updateSettings.type = options.type if options.type
updateSettings.multiline = options.multiline if options.multiline
updateSettings.group = options.group if options.group
updateSettings.section = options.section if options.section
updateSettings.public = options.public if options.public
return RocketChat.models.Settings.upsert { _id: _id }, { $setOnInsert: { value: value }, $set: updateSettings }
upsertChanges = { $setOnInsert: { value: value }, $set: updateSettings }
if options.persistent is true
upsertChanges.$unset = { ts: true }
else
upsertChanges.$set.ts = new Date
return RocketChat.models.Settings.upsert { _id: _id }, upsertChanges
###
# Add a setting group
@ -38,12 +45,18 @@ RocketChat.settings.addGroup = (_id, options = {}) ->
# console.log '[functions] RocketChat.settings.addGroup -> '.green, 'arguments:', arguments
updateSettings =
i18nLabel: options.i18nLabel or _id
i18nDescription: options.i18nDescription if options.i18nDescription?
type: 'group'
i18nLabel: options.i18nLabel or _id
updateSettings.i18nDescription = options.i18nDescription if options.i18nDescription?
return RocketChat.models.Settings.upsert { _id: _id }, { $set: updateSettings }
upsertChanges = { $set: updateSettings }
if options.persistent is true
upsertChanges.$unset = { ts: true }
else
upsertChanges.$set.ts = new Date
return RocketChat.models.Settings.upsert { _id: _id }, upsertChanges
###
# Remove a setting by id

@ -0,0 +1,4 @@
# Remove runtime settings (non-persistent)
Meteor.startup ->
RocketChat.models.Settings.remove({ ts: { $lt: RocketChat.settings.ts } })
Loading…
Cancel
Save