2020-05-22 21:22:20 +03:00
|
|
|
const {events, logging, i18n} = require('../../../server/lib/common');
|
|
|
|
const errors = require('@tryghost/errors');
|
2019-07-01 17:56:23 +03:00
|
|
|
const active = require('./active');
|
|
|
|
|
|
|
|
function activate(loadedTheme, checkedTheme, error) {
|
|
|
|
// no need to check the score, activation should be used in combination with validate.check
|
|
|
|
// Use the two theme objects to set the current active theme
|
|
|
|
try {
|
|
|
|
let previousGhostAPI;
|
|
|
|
|
|
|
|
if (active.get()) {
|
|
|
|
previousGhostAPI = active.get().engine('ghost-api');
|
|
|
|
}
|
|
|
|
|
|
|
|
active.set(loadedTheme, checkedTheme, error);
|
|
|
|
const currentGhostAPI = active.get().engine('ghost-api');
|
|
|
|
|
2020-05-22 21:22:20 +03:00
|
|
|
events.emit('services.themes.activated');
|
2019-07-01 17:56:23 +03:00
|
|
|
|
|
|
|
if (previousGhostAPI !== undefined && (previousGhostAPI !== currentGhostAPI)) {
|
2020-05-22 21:22:20 +03:00
|
|
|
events.emit('services.themes.api.changed');
|
2019-07-01 17:56:23 +03:00
|
|
|
const siteApp = require('../../../server/web/site/app');
|
|
|
|
siteApp.reload();
|
|
|
|
}
|
|
|
|
} catch (err) {
|
2020-05-22 21:22:20 +03:00
|
|
|
logging.error(new errors.InternalServerError({
|
|
|
|
message: i18n.t('errors.middleware.themehandler.activateFailed', {theme: loadedTheme.name}),
|
2019-07-01 17:56:23 +03:00
|
|
|
err: err
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = activate;
|