Store content config with it’s type

This commit is contained in:
Samuel Elliott 2018-03-22 16:38:09 +00:00
parent 6d46ac67de
commit a3eeee9b57
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 25 additions and 5 deletions

View File

@ -78,10 +78,9 @@ export default class Content {
*/
async saveConfiguration() {
try {
Database.insertOrUpdate({ type: 'contentconfig', $or: [{ id: this.id }, { name: this.name }] }, {
type: 'contentconfig',
Database.insertOrUpdate({ type: `${this.type}-config`, id: this.id }, {
type: `${this.type}-config`,
id: this.id,
name: this.name,
enabled: this.enabled,
config: this.settings.strip().settings,
data: this.data

View File

@ -39,6 +39,27 @@ export default class {
return this._localContent ? this._localContent : (this._localContent = []);
}
/**
* The type of content this content manager manages.
*/
static get contentType() {
return undefined;
}
/**
* The name of this content manager.
*/
static get moduleName() {
return undefined;
}
/**
* The path used to store this content manager's content.
*/
static get pathId() {
return undefined;
}
/**
* Local path for content.
* @return {String}
@ -100,7 +121,7 @@ export default class {
const directories = await FileUtils.listDirectory(this.contentPath);
for (let dir of directories) {
// If content is already loaded this should resolve.
// If content is already loaded this should resolve
if (this.getContentByDirName(dir)) continue;
try {
@ -185,7 +206,7 @@ export default class {
try {
const id = readConfig.info.id || readConfig.info.name.toLowerCase().replace(/[^a-zA-Z0-9-]/g, '-').replace(/--/g, '-');
const readUserConfig = await Database.find({ type: 'contentconfig', id });
const readUserConfig = await Database.find({ type: `${this.contentType}-config`, id });
if (readUserConfig.length) {
userConfig.enabled = readUserConfig[0].enabled || false;
userConfig.config = readUserConfig[0].config;