-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
…hen migrating closes TryGhost#5298 - remove all harcoded instances of jQuery throughout the front-end of the blog - add migration function to add cdn link to ghost_foot code injection when migrating up from version 003 - migration version bump
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,17 @@ var Promise = require('bluebird'), | |
sequence = require('../../utils/sequence'), | ||
_ = require('lodash'), | ||
errors = require('../../errors'), | ||
config = require('../../config'), | ||
utils = require('../../utils'), | ||
models = require('../../models'), | ||
fixtures = require('./fixtures'), | ||
permissions = require('./permissions'), | ||
notifications = require('../../api/notifications'), | ||
|
||
// Private | ||
logInfo, | ||
to003, | ||
to004, | ||
convertAdminToOwner, | ||
createOwner, | ||
options = {context: {internal: true}}, | ||
|
@@ -156,13 +159,55 @@ to003 = function () { | |
}); | ||
}; | ||
|
||
/** | ||
* Update ghost_foot to include a CDN of jquery if the DB is migrating from | ||
* @return {Promise} | ||
*/ | ||
to004 = function () { | ||
var value, | ||
jquery = [ | ||
'<!-- only delete this line if you are ABSOLUTELY SURE your theme doesn\'t require jQuery -->\n', | ||
This comment has been minimized.
Sorry, something went wrong. |
||
'<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>\n\n' | ||
], | ||
privacyMessage = [ | ||
'Because jQuery is no longer included for Ghost themes by default,', | ||
'a link to the jQuery library via a CDN has been added to your code-injection setting,', | ||
'If you wish to remove it for privacy reasons, please ensure it is not required by your theme.' | ||
This comment has been minimized.
Sorry, something went wrong.
JohnONolan
|
||
]; | ||
|
||
return models.Settings.findOne('ghost_foot').then(function (setting) { | ||
if (setting) { | ||
value = setting.attributes.value; | ||
value = jquery.join('') + value; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
return models.Settings.edit({key: 'ghost_foot', value: value}, options).then(function () { | ||
if (_.isEmpty(config.privacy)) { | ||
return Promise.resolve(); | ||
} | ||
return notifications.add({notifications: [{ | ||
type: 'info', | ||
message: privacyMessage.join(' ') | ||
}]}, options); | ||
}); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
ErisDS
|
||
}); | ||
}; | ||
|
||
update = function (fromVersion, toVersion) { | ||
var ops = []; | ||
|
||
logInfo('Updating fixtures'); | ||
// Are we migrating to, or past 003? | ||
if ((fromVersion < '003' && toVersion >= '003') || | ||
fromVersion === '003' && toVersion === '003' && process.env.FORCE_MIGRATION) { | ||
return to003(); | ||
ops.push(to003); | ||
} | ||
|
||
if (fromVersion < '004' && toVersion === '004' || | ||
fromVersion === '004' && toVersion === '004' && process.env.FORCE_MIGRATION) { | ||
ops.push(to004); | ||
} | ||
|
||
return sequence(ops); | ||
}; | ||
|
||
module.exports = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*globals describe, before, beforeEach, afterEach, it */ | ||
/*jshint expr:true*/ | ||
var testUtils = require('../utils'), | ||
should = require('should'), | ||
|
||
migration = require('../../server/data/migration/index'), | ||
Models = require('../../server/models'); | ||
|
||
describe('Database Migration (special functions)', function () { | ||
before(testUtils.teardown); | ||
afterEach(testUtils.teardown); | ||
|
||
describe('004', function () { | ||
beforeEach(testUtils.setup('settings')); | ||
|
||
it('should add jQuery to ghost_foot injection setting', function (done) { | ||
Models.Settings.findOne('ghost_foot').then(function (setting) { | ||
should.exist(setting); | ||
should.exist(setting.attributes); | ||
setting.attributes.value.should.equal(''); | ||
|
||
process.env.FORCE_MIGRATION = true; // force a migration | ||
migration.init().then(function () { | ||
Models.Settings.findOne('ghost_foot').then(function (result) { | ||
var jquery = [ | ||
'<!-- only delete this line if you are ABSOLUTELY SURE your theme doesn\'t require jQuery -->\n', | ||
'<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>\n\n' | ||
]; | ||
|
||
should.exist(result); | ||
should.exist(result.attributes); | ||
result.attributes.value.should.equal(jquery.join('')); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Suggest update to:
<!-- You can safely delete this line if your theme does not require jQuery -->\n