Improved files to distinguish subtypes (allows multiple different files tabs at a entity)

Attachments via the improved files
Block thumbnails at mosaico templates as a separate files tab
Some fixes

All not tested yet
This commit is contained in:
Tomas Bures 2018-08-02 15:49:27 +05:30
parent ade0fc87f2
commit 32cad03f4f
32 changed files with 683 additions and 346 deletions

View file

@ -120,5 +120,4 @@ exports.up = (knex, Promise) => (async() => {
})();
exports.down = (knex, Promise) => (async() => {
// return knex.schema.dropTable('users');
})();

View file

@ -31,5 +31,4 @@ exports.up = (knex, Promise) => (async() => {
})();
exports.down = (knex, Promise) => (async() => {
await knex.schema.dropTable('namespaces');
})();

View file

@ -32,9 +32,4 @@ exports.up = (knex, Promise) => (async() => {
})();
exports.down = (knex, Promise) => (async() => {
for (const entityType of shareableEntityTypes) {
await knex.schema
.dropTable(`shares_${entityType}`)
.dropTable(`permissions_${entityType}`);
}
})();

View file

@ -1,25 +1,39 @@
const entityTypesWithFiles = ['template', 'campaign'];
const entityTypesWithFiles = {
campaign: {
file: 'files_campaign_file',
attachment: 'files_campaign_attachment',
},
template: {
file: 'files_template_file'
},
mosaicoTemplate: {
file: 'files_mosaico_template_file',
block: 'files_mosaico_template_block'
}
};
exports.up = (knex, Promise) => (async() => {
for (const entityType of entityTypesWithFiles) {
for (const type in entityTypesWithFiles) {
const typeEntry = entityTypesWithFiles[type];
await knex.schema.createTable(`files_${entityType}`, table => {
table.increments('id').primary();
table.integer('entity').unsigned().notNullable().references(`${entityType}s.id`);
table.string('filename');
table.string('originalname');
table.string('mimetype');
table.string('encoding');
table.integer('size');
table.timestamp('created').defaultTo(knex.fn.now());
table.index(['entity', 'originalname'])
})
for (const subType in typeEntry) {
const subTypeEntry = typeEntry[subType];
await knex.schema.createTable(subTypeEntry, table => {
table.increments('id').primary();
table.integer('entity').unsigned().notNullable().references(`${type}s.id`);
table.string('filename');
table.string('originalname');
table.string('mimetype');
table.string('encoding');
table.integer('size');
table.timestamp('created').defaultTo(knex.fn.now());
table.index(['entity', 'originalname'])
});
}
}
})();
exports.down = (knex, Promise) => (async() => {
for (const entityType of entityTypesWithFiles) {
await knex.schema.dropTable(`files_${entityType}`);
}
})();

View file

@ -52,10 +52,4 @@ exports.up = (knex, Promise) => (async() => {
})();
exports.down = (knex, Promise) => (async() => {
await knex.schema
.dropTable('shares_mosaico_template')
.dropTable('permissions_mosaico_template')
.dropTable('files_mosaico_template')
.dropTable('mosaico_templates')
;
})();

View file

@ -121,9 +121,4 @@ exports.up = (knex, Promise) => (async() => {
exports.down = (knex, Promise) => (async() => {
await knex.schema
.dropTable('shares_send_configuration')
.dropTable('permissions_send_configuration')
.dropTable('send_configurations')
;
})();

View file

@ -56,6 +56,8 @@ scheduled - used only for campaign type NORMAL
const { getSystemSendConfigurationId } = require('../../../shared/send-configurations');
const { CampaignSource, CampaignType} = require('../../../shared/campaigns');
const files = require('../../../models/files');
const contextHelpers = require('../../../lib/context-helpers');
exports.up = (knex, Promise) => (async() => {
@ -77,11 +79,11 @@ exports.up = (knex, Promise) => (async() => {
let editorType = campaign.editor_name;
const editorData = JSON.parse(campaign.editor_data || '{}');
if (editorType == 'summernote') {
if (editorType === 'summernote') {
editorType = 'ckeditor';
}
if (editorType == 'mosaico') {
if (editorType === 'mosaico') {
editorType = 'mosaicoWithFsTemplate';
editorData.mosaicoFsTemplate = editorData.template;
delete editorData.template;
@ -115,6 +117,20 @@ exports.up = (knex, Promise) => (async() => {
campaign.data = JSON.stringify(data);
await knex('campaigns').where('id', campaign.id).update(campaign);
const attachments = await knex('attachments').where('campaign', campaign.id);
const attachmentFiles = [];
for (const attachment of attachments) {
attachmentFiles.push({
originalname: attachment.filename,
mimetype: attachment.content_type,
// encoding: file.encoding,
size: attachment.size,
created: attachment.created,
data: attachment.content
});
}
await files.createFiles(contextHelpers.getAdminContext(), 'campaign', 'attachment', campaign.id, attachmentFiles, files.ReplacementBehavior.NONE);
}
await knex.schema.table('campaigns', table => {
@ -138,6 +154,7 @@ exports.up = (knex, Promise) => (async() => {
await knex.schema.dropTableIfExists('campaign');
await knex.schema.dropTableIfExists('campaign_tracker');
await knex.schema.dropTableIfExists('attachments');
})();
exports.down = (knex, Promise) => (async() => {