mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
0ffc5e6d47
closes #3274 - Ensure that validation errors are always handled by moving them into the importer - Ensure that db errors are handled consistently across sqlite and mysql - Change the errors to be output in a table, with a short failure notification - Add tests for 003 importing bad files
62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
var DebugController = Ember.Controller.extend(Ember.Evented, {
|
|
uploadButtonText: 'Import',
|
|
importErrors: '',
|
|
|
|
actions: {
|
|
onUpload: function (file) {
|
|
var self = this,
|
|
formData = new FormData();
|
|
|
|
this.set('uploadButtonText', 'Importing');
|
|
this.notifications.closePassive();
|
|
|
|
formData.append('importfile', file);
|
|
|
|
ic.ajax.request(this.get('ghostPaths.url').api('db'), {
|
|
type: 'POST',
|
|
data: formData,
|
|
dataType: 'json',
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false
|
|
}).then(function () {
|
|
self.notifications.showSuccess('Import successful.');
|
|
}).catch(function (response) {
|
|
if (response && response.jqXHR && response.jqXHR.responseJSON && response.jqXHR.responseJSON.errors) {
|
|
self.set('importErrors', response.jqXHR.responseJSON.errors);
|
|
}
|
|
self.notifications.showError('Import Failed');
|
|
}).finally(function () {
|
|
self.set('uploadButtonText', 'Import');
|
|
self.trigger('reset');
|
|
});
|
|
},
|
|
|
|
exportData: function () {
|
|
var iframe = $('#iframeDownload'),
|
|
downloadURL = this.get('ghostPaths.url').api('db') +
|
|
'?access_token=' + this.get('session.access_token');
|
|
|
|
if (iframe.length === 0) {
|
|
iframe = $('<iframe>', { id: 'iframeDownload' }).hide().appendTo('body');
|
|
}
|
|
|
|
iframe.attr('src', downloadURL);
|
|
},
|
|
|
|
sendTestEmail: function () {
|
|
var self = this;
|
|
|
|
ic.ajax.request(this.get('ghostPaths.url').api('mail', 'test'), {
|
|
type: 'POST'
|
|
}).then(function () {
|
|
self.notifications.showSuccess('Check your email for the test message:');
|
|
}).catch(function (response) {
|
|
self.notifications.showErrors(response);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
export default DebugController;
|