Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Remove invalid settings at startup (#27653)
- Loading branch information
Showing
5 changed files
with
62 additions
and
5 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 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 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,40 @@ | ||
// Validates settings on DB are correct on structure | ||
// And deletes invalid ones | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Settings } from '@rocket.chat/models'; | ||
|
||
import { Logger } from './logger/Logger'; | ||
|
||
// Validates settings on DB are correct on structure by matching the ones missing all the required fields | ||
const logger = new Logger('SettingsRegenerator'); | ||
export async function settingsRegenerator() { | ||
const invalidSettings = await Settings.find( | ||
{ | ||
// Putting the $and explicit to ensure it's "intentional" | ||
$and: [ | ||
{ value: { $exists: false } }, | ||
{ type: { $exists: false } }, | ||
{ public: { $exists: false } }, | ||
{ packageValue: { $exists: false } }, | ||
{ blocked: { $exists: false } }, | ||
{ sorter: { $exists: false } }, | ||
{ i18nLabel: { $exists: false } }, | ||
], | ||
}, | ||
{ projection: { _id: 1 } }, | ||
).toArray(); | ||
|
||
if (invalidSettings.length > 0) { | ||
logger.warn({ | ||
msg: 'Invalid settings found on DB. Deleting them.', | ||
settings: invalidSettings.map(({ _id }) => _id), | ||
}); | ||
await Settings.deleteMany({ _id: { $in: invalidSettings.map(({ _id }) => _id) } }); | ||
} else { | ||
logger.info('No invalid settings found on DB.'); | ||
} | ||
} | ||
|
||
Meteor.startup(async () => { | ||
await settingsRegenerator(); | ||
}); |
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 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