commit
086fc954ad
|
@ -102,6 +102,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
|
||||||
this.jsData = Object.assign(this.data, this.sitePluginsProvider.createDataForJS(this.initResult, result));
|
this.jsData = Object.assign(this.data, this.sitePluginsProvider.createDataForJS(this.initResult, result));
|
||||||
|
|
||||||
// Pass some methods as jsData so they can be called from the template too.
|
// Pass some methods as jsData so they can be called from the template too.
|
||||||
|
this.jsData.fetchContent = this.fetchContent.bind(this);
|
||||||
this.jsData.openContent = this.openContent.bind(this);
|
this.jsData.openContent = this.openContent.bind(this);
|
||||||
this.jsData.refreshContent = this.refreshContent.bind(this);
|
this.jsData.refreshContent = this.refreshContent.bind(this);
|
||||||
this.jsData.updateContent = this.updateContent.bind(this);
|
this.jsData.updateContent = this.updateContent.bind(this);
|
||||||
|
|
|
@ -164,7 +164,7 @@ export class CoreSitePluginsProvider {
|
||||||
|
|
||||||
if (initResult) {
|
if (initResult) {
|
||||||
// First of all, add the data returned by the init JS (if any).
|
// First of all, add the data returned by the init JS (if any).
|
||||||
data = this.utils.clone(initResult.jsResult || {});
|
data = Object.assign({}, initResult.jsResult || {});
|
||||||
if (typeof data == 'boolean') {
|
if (typeof data == 'boolean') {
|
||||||
data = {};
|
data = {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1628,8 +1628,17 @@ export class CoreSitesProvider {
|
||||||
* Register a site schema.
|
* Register a site schema.
|
||||||
*/
|
*/
|
||||||
registerSiteSchema(schema: CoreSiteSchema): void {
|
registerSiteSchema(schema: CoreSiteSchema): void {
|
||||||
|
|
||||||
|
if (this.currentSite) {
|
||||||
|
// Site has already been created, it's a schema probably added by site plugins. Add it only to current site.
|
||||||
|
const schemas: {[name: string]: CoreSiteSchema} = {};
|
||||||
|
schemas[schema.name] = schema;
|
||||||
|
|
||||||
|
this.applySiteSchemas(this.currentSite, schemas);
|
||||||
|
} else {
|
||||||
this.siteSchemas[schema.name] = schema;
|
this.siteSchemas[schema.name] = schema;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install and upgrade all the registered schemas and tables.
|
* Install and upgrade all the registered schemas and tables.
|
||||||
|
@ -1638,7 +1647,6 @@ export class CoreSitesProvider {
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
migrateSiteSchemas(site: CoreSite): Promise<any> {
|
migrateSiteSchemas(site: CoreSite): Promise<any> {
|
||||||
const db = site.getDb();
|
|
||||||
|
|
||||||
if (this.siteSchemasMigration[site.id]) {
|
if (this.siteSchemasMigration[site.id]) {
|
||||||
return this.siteSchemasMigration[site.id];
|
return this.siteSchemasMigration[site.id];
|
||||||
|
@ -1647,7 +1655,27 @@ export class CoreSitesProvider {
|
||||||
this.logger.debug(`Migrating all schemas of ${site.id}`);
|
this.logger.debug(`Migrating all schemas of ${site.id}`);
|
||||||
|
|
||||||
// First create tables not registerd with name/version.
|
// First create tables not registerd with name/version.
|
||||||
const promise = db.createTablesFromSchema(this.siteTablesSchemas).then(() => {
|
const promise = site.getDb().createTablesFromSchema(this.siteTablesSchemas).then(() => {
|
||||||
|
return this.applySiteSchemas(site, this.siteSchemas);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.siteSchemasMigration[site.id] = promise;
|
||||||
|
|
||||||
|
return promise.finally(() => {
|
||||||
|
delete this.siteSchemasMigration[site.id];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install and upgrade the supplied schemas for a certain site.
|
||||||
|
*
|
||||||
|
* @param site Site.
|
||||||
|
* @param schemas Schemas to migrate.
|
||||||
|
* @return Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected applySiteSchemas(site: CoreSite, schemas: {[name: string]: CoreSiteSchema}): Promise<any> {
|
||||||
|
const db = site.getDb();
|
||||||
|
|
||||||
// Fetch installed versions of the schema.
|
// Fetch installed versions of the schema.
|
||||||
return db.getAllRecords(this.SCHEMA_VERSIONS_TABLE).then((records) => {
|
return db.getAllRecords(this.SCHEMA_VERSIONS_TABLE).then((records) => {
|
||||||
const versions = {};
|
const versions = {};
|
||||||
|
@ -1656,8 +1684,8 @@ export class CoreSitesProvider {
|
||||||
});
|
});
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (const name in this.siteSchemas) {
|
for (const name in schemas) {
|
||||||
const schema = this.siteSchemas[name];
|
const schema = schemas[name];
|
||||||
const oldVersion = versions[name] || 0;
|
const oldVersion = versions[name] || 0;
|
||||||
if (oldVersion >= schema.version) {
|
if (oldVersion >= schema.version) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1681,13 +1709,6 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.siteSchemasMigration[site.id] = promise;
|
|
||||||
|
|
||||||
return promise.finally(() => {
|
|
||||||
delete this.siteSchemasMigration[site.id];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue