From d63d3f77ebe07110b87931e6a659302516967478 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Mon, 15 Apr 2019 11:42:44 +0200 Subject: [PATCH] Removed external app support from app service init no-issue --- core/server/services/apps/index.js | 75 ++++-------------------------- 1 file changed, 9 insertions(+), 66 deletions(-) diff --git a/core/server/services/apps/index.js b/core/server/services/apps/index.js index 4972444b0d..ebf69ef19f 100644 --- a/core/server/services/apps/index.js +++ b/core/server/services/apps/index.js @@ -1,72 +1,16 @@ -var debug = require('ghost-ignition').debug('services:apps'), - _ = require('lodash'), - Promise = require('bluebird'), - api = require('../../api'), - common = require('../../lib/common'), - config = require('../../config'), - settingsCache = require('../settings/cache'), - loader = require('./loader'), - // Internal apps are in config - internalApps = config.get('apps:internal'), - // Holds the available apps - availableApps = {}; - -function recordLoadedApp(name, loadedApp) { - // After loading the app, add it to our hash of loaded apps - availableApps[name] = loadedApp; - return loadedApp; -} - -function saveInstalledApps(installedApps) { - debug('saving begin'); - var currentInstalledApps = settingsCache.get('installed_apps'), - // Never save internal apps - updatedAppsInstalled = _.difference(_.uniq(installedApps.concat(currentInstalledApps)), internalApps); - - if (_.difference(updatedAppsInstalled, currentInstalledApps).length === 0) { - debug('saving unneeded'); - return new Promise.resolve(); - } - - debug('saving settings'); - return api.settings.edit({ - settings: [{ - key: 'installed_apps', - value: updatedAppsInstalled - }] - }, {context: {internal: true}}); -} +const debug = require('ghost-ignition').debug('services:apps'); +const Promise = require('bluebird'); +const common = require('../../lib/common'); +const config = require('../../config'); +const loader = require('./loader'); +const internalApps = config.get('apps:internal'); module.exports = { init: function () { debug('init begin'); - var activeApps = settingsCache.get('active_apps'), - installedApps = settingsCache.get('installed_apps'), - // Load means either activate, or install and activate - // We load all Active Apps, and all Internal Apps - appsToLoad = activeApps.concat(internalApps); + const appsToLoad = internalApps; - function loadApp(appName) { - // If internal or already installed, the app only needs activating - if (_.includes(internalApps, appName) || _.includes(installedApps, appName)) { - return loader.activateAppByName(appName).then(function (loadedApp) { - return recordLoadedApp(appName, loadedApp); - }); - } - - // Else first install, then activate the app - return loader.installAppByName(appName).then(function () { - return loader.activateAppByName(appName); - }).then(function (loadedApp) { - return recordLoadedApp(appName, loadedApp); - }); - } - - return Promise.map(appsToLoad, loadApp) - .then(function () { - // Save our installed apps to settings - return saveInstalledApps(_.keys(availableApps)); - }) + return Promise.map(appsToLoad, appName => loader.activateAppByName(appName)) .catch(function (err) { common.logging.error(new common.errors.GhostError({ err: err, @@ -74,6 +18,5 @@ module.exports = { help: common.i18n.t('errors.apps.appWillNotBeLoaded.help') })); }); - }, - availableApps: availableApps + } };