Added migration for campaigns

This commit is contained in:
Tomas Bures 2018-07-22 00:01:28 +05:30
parent e85c707973
commit 189638364c
7 changed files with 177 additions and 6 deletions

View file

@ -87,6 +87,7 @@ export default class CUD extends Component {
namespace: mailtrainConfig.user.namespace,
from_email_overridable: false,
from_name_overridable: false,
reply_to_overridable: false,
subject_overridable: false,
verpEnabled: false,
verp_hostname: '',
@ -195,6 +196,8 @@ export default class CUD extends Component {
<CheckBox id="from_email_overridable" text={t('Overridable')}/>
<InputField id="from_name" label={t('Default "from" name')}/>
<CheckBox id="from_name_overridable" text={t('Overridable')}/>
<InputField id="reply_to" label={t('Default "reply-to" email')}/>
<CheckBox id="reply_to_overridable" text={t('Overridable')}/>
<InputField id="subject" label={t('Subject')}/>
<CheckBox id="subject_overridable" text={t('Overridable')}/>
</Fieldset>

View file

@ -26,7 +26,7 @@ import {
} from '../../lib/namespace';
import {DeleteModalDialog} from "../../lib/modals";
import {versafix} from "../../../../shared/mosaico-templates";
import {getVersafix} from "../../../../shared/mosaico-templates";
import {
getTemplateTypes,
getTemplateTypesOrder
@ -77,7 +77,7 @@ export default class CUD extends Component {
description: '',
namespace: mailtrainConfig.user.namespace,
type: 'html',
html: versafix
html: getVersafix()
});
} else {

View file

@ -10,7 +10,7 @@ const namespaceHelpers = require('../lib/namespace-helpers');
const {MailerType, getSystemSendConfigurationId} = require('../shared/send-configurations');
const contextHelpers = require('../lib/context-helpers');
const allowedKeys = new Set(['name', 'description', 'from_email', 'from_email_overridable', 'from_name', 'from_name_overridable', 'subject', 'subject_overridable', 'verp_hostname', 'mailer_type', 'mailer_settings', 'namespace']);
const allowedKeys = new Set(['name', 'description', 'from_email', 'from_email_overridable', 'from_name', 'from_name_overridable', 'reply_to', 'reply_to_overridable', 'subject', 'subject_overridable', 'verp_hostname', 'mailer_type', 'mailer_settings', 'namespace']);
const allowedMailerTypes = new Set(Object.values(MailerType));

View file

@ -35,7 +35,7 @@ exports.up = (knex, Promise) => (async() => {
table.string('encoding');
table.integer('size');
table.timestamp('created').defaultTo(knex.fn.now());
table.index(['entity', 'originalname'])
table.index(['entity', 'originalname']);
});
const versafix = {
@ -44,7 +44,7 @@ exports.up = (knex, Promise) => (async() => {
type: 'html',
namespace: 1,
data: JSON.stringify({
html: mosaicoTemplates.versafix
html: mosaicoTemplates.getVersafix()
})
};

View file

@ -10,6 +10,8 @@ exports.up = (knex, Promise) => (async() => {
table.boolean('from_email_overridable').defaultTo(false);
table.string('from_name');
table.boolean('from_name_overridable').defaultTo(false);
table.string('reply_to');
table.boolean('reply_to_overridable').defaultTo(false);
table.string('subject');
table.boolean('subject_overridable').defaultTo(false);
table.string('verp_hostname'); // VERP is not used if verp_hostname is null
@ -94,6 +96,8 @@ exports.up = (knex, Promise) => (async() => {
from_email_overridable: true,
from_name: settings.defaultFrom,
from_name_overridable: true,
reply_to: settings.defaultAddress,
reply_to_overridable: true,
subject: settings.defaultSubject,
subject_overridable: true,
verp_hostname: settings.verpUse ? settings.verpHostname : null,

View file

@ -0,0 +1,160 @@
/*
This is how we refactor the original campaigns table.
+-------------------------+---------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+---------------------+------+-----+-------------------+----------------+
OK | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
OK | cid | varchar(255) | NO | UNI | NULL | |
OK | type | tinyint(4) unsigned | NO | MUL | 1 | |
OK | parent | int(10) unsigned | YES | MUL | NULL | |
OK | name | varchar(255) | NO | MUL | | |
OK | description | text | YES | | NULL | |
OK | list | int(10) unsigned | NO | | NULL | |
OK | segment | int(10) unsigned | YES | | NULL | |
X | template | int(10) unsigned | NO | | NULL | |
X | source_url | varchar(255) | YES | | NULL | |
X | editor_name | varchar(50) | YES | | | |
X | editor_data | longtext | YES | | NULL | |
OK | last_check | timestamp | YES | MUL | NULL | |
X | check_status | varchar(255) | YES | | NULL | |
OK | from -> from_name_override | varchar(255) | YES | | | |
OK | address -> from_email_override | varchar(255) | YES | | | |
OK | reply_to -> reply_to_override | varchar(255) | YES | | | |
OK | subject -> subject_override | varchar(255) | YES | | | |
X | html | longtext | YES | | NULL | |
X | html_prepared | longtext | YES | | NULL | |
X | text | longtext | YES | | NULL | |
OK | status | tinyint(4) unsigned | NO | MUL | 1 | |
OK | scheduled | timestamp | YES | MUL | NULL | |
X | status_change | timestamp | YES | | NULL | |
OK | delivered | int(11) unsigned | NO | | 0 | |
OK | blacklisted | int(11) unsigned | NO | | 0 | |
OK | opened | int(11) unsigned | NO | | 0 | |
OK | clicks | int(11) unsigned | NO | | 0 | |
OK | unsubscribed | int(11) unsigned | NO | | 0 | |
OK | bounced | int(1) unsigned | NO | | 0 | |
OK | complained | int(1) unsigned | NO | | 0 | |
OK | created | timestamp | NO | | CURRENT_TIMESTAMP | |
OK | open_tracking_disabled | tinyint(4) unsigned | NO | | 0 | |
OK | click_tracking_disabled | tinyint(4) unsigned | NO | | 0 | |
OK | namespace | int(10) unsigned | NO | MUL | NULL | |
+-------------------------+---------------------+------+-----+-------------------+----------------+
New columns:
+-------------------------+---------------------+------+-----+-------------------+----------------+
| data | longtext | NO | | NULL | |
| source_type | int(10) unsigned | NO | | | |
| send_configuration | int(10) unsigned | NO | | | |
+-------------------------+---------------------+------+-----+-------------------+----------------+
list - we will probably need some strategy how to consistently treat stats when list/segment changes
parent - used only for campaign type RSS
last_check - used only for campaign type RSS
scheduled - used only for campaign type NORMAL
*/
const { getSystemSendConfigurationId } = require('../../../shared/send-configurations');
const CampaignSource = {
TEMPLATE: 1,
CUSTOM: 2,
URL: 3,
RSS: 4
};
const CampaignType = {
NORMAL: 1,
RSS: 2,
RSS_ENTRY: 3,
TRIGGERED: 4
};
const CampaignStatus = {
// For campaign types: NORMAL, RSS_ENTRY
IDLE: 1,
SCHEDULED: 2,
FINISHED: 3,
PAUSED: 4,
// For campaign types: RSS, TRIGGERED
INACTIVE: 5,
ACTIVE: 6
};
exports.up = (knex, Promise) => (async() => {
await knex.schema.table('campaigns', table => {
table.text('data', 'longtext');
table.integer('source_type').unsigned().notNullable();
// Add a default values, such that the new column has some valid non-null value
table.integer('send_configuration').unsigned().notNullable().references(`send_configurations.id`).defaultTo(getSystemSendConfigurationId());
});
const campaigns = await knex('campaigns');
for (const campaign of campaigns) {
const data = {};
if (campaign.type === CampaignType.NORMAL || campaign.type === CampaignType.RSS_ENTRY || campaign.type === CampaignType.NORMAL || campaign.type === CampaignType.TRIGGERED) {
if (campaign.template) {
let editorType = campaign.editor_name;
const editorData = JSON.parse(campaign.editor_data || '{}');
if (editorType == 'summernote') {
editorType = 'ckeditor';
}
campaign.source_type = CampaignSource.CUSTOM;
data.source = {
type: editorType,
data: JSON.stringify(editorData),
html: campaign.html,
text: campaign.text,
htmlPrepared: campaign.html_prepared
};
} else {
campaign.source_type = CampaignSource.URL;
data.source = {
url: campaign.source_url
};
}
} else if (campaign.type === CampaignType.RSS) {
campaign.source_type = CampaignSource.RSS;
data.source = {
url: campaign.source_url
};
data.checkStatus = campaign.checkStatus;
}
campaign.data = JSON.stringify(data);
await knex('campaigns').where('id', campaign.id).update(campaign);
}
await knex.schema.table('campaigns', table => {
table.dropColumn('template');
table.dropColumn('source_url');
table.dropColumn('editor_name');
table.dropColumn('editor_data');
table.dropColumn('check_status');
table.dropColumn('status_change');
table.dropColumn('html');
table.dropColumn('html_prepared');
table.dropColumn('text');
table.renameColumn('from', 'from_name_override');
table.renameColumn('address', 'from_email_override');
table.renameColumn('reply_to', 'reply_to_override');
table.renameColumn('subject', 'subject_override');
// Remove the default value
table.integer('send_configuration').unsigned().notNullable().alter();
});
})();
exports.down = (knex, Promise) => (async() => {
})();

View file

@ -1532,6 +1532,10 @@ const versafix = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
'</body>\n' +
'</html>\n';
function getVersafix() {
return versafix;
}
module.exports = {
versafix
getVersafix
};