From 63ec3b6a55a000f84179df2581b5dc20361fbcfe Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 17 Jul 2017 12:16:14 -0400 Subject: [PATCH] upgrade script to generate and set email logo+sizes in config --- src/upgrades/1.5.3/generate-email-logo.js | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/upgrades/1.5.3/generate-email-logo.js diff --git a/src/upgrades/1.5.3/generate-email-logo.js b/src/upgrades/1.5.3/generate-email-logo.js new file mode 100644 index 0000000000..9987ca11da --- /dev/null +++ b/src/upgrades/1.5.3/generate-email-logo.js @@ -0,0 +1,48 @@ +'use strict'; + +var db = require('../../database'); +var image = require('../../image'); +var meta = require('../../meta'); + +var async = require('async'); +var winston = require('winston'); +var path = require('path'); +var nconf = require('nconf'); +var url = require('url'); + +module.exports = { + name: 'Generate email logo for use in email header', + timestamp: Date.UTC(2017, 6, 17), + method: function (callback) { + var skip = false; + + async.series([ + function (next) { + // Resize existing logo (if present) to email header size + var uploadPath = path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'); + var sourcePath = meta.config['brand:logo'] ? path.join(nconf.get('upload_path'), 'system', path.basename(meta.config['brand:logo'])) : null; + + if (!sourcePath) { + skip = true; + return setImmediate(next); + } + + image.resizeImage({ + path: sourcePath, + target: uploadPath, + extension: 'png', + height: 50, + }, next); + }, + function (next) { + if (skip) { + return setImmediate(next); + } + + meta.configs.setMultiple({ + 'brand:logo': path.join(nconf.get('upload_path'), 'system', path.basename(meta.config['brand:logo'])), + }, next); + }, + ], callback); + }, +};