mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-10-04 16:57:12 +03:00
Added pages to data-generator
no issue Data generator will now add 3 pages by default - can add extra support here, e.g. webmentions later.
This commit is contained in:
parent
c6e119ecf5
commit
22ac685354
@ -213,6 +213,11 @@ class DataGenerator {
|
||||
rows: ['newsletter_id', 'published_at', 'slug', 'status', 'visibility']
|
||||
});
|
||||
|
||||
await postsImporter.import({
|
||||
amount: 3,
|
||||
type: 'page'
|
||||
});
|
||||
|
||||
const tagsImporter = new TagsImporter(transaction, {
|
||||
users
|
||||
});
|
||||
@ -347,7 +352,7 @@ class DataGenerator {
|
||||
await mentionsImporter.importForEach(posts, {amount: 4});
|
||||
|
||||
const emailsImporter = new EmailsImporter(transaction, {newsletters, members, membersSubscribeEvents});
|
||||
const emails = await emailsImporter.importForEach(posts.filter(post => post.status === 'published'), {
|
||||
const emails = await emailsImporter.importForEach(posts.filter(post => post.newsletter_id), {
|
||||
amount: 1,
|
||||
rows: ['created_at', 'email_count', 'delivered_count', 'opened_count', 'failed_count', 'newsletter_id', 'post_id']
|
||||
});
|
||||
@ -365,7 +370,7 @@ class DataGenerator {
|
||||
});
|
||||
|
||||
const redirectsImporter = new RedirectsImporter(transaction);
|
||||
const redirects = await redirectsImporter.importForEach(posts.filter(post => post.status === 'published'), {
|
||||
const redirects = await redirectsImporter.importForEach(posts.filter(post => post.newsletter_id), {
|
||||
amount: 10,
|
||||
rows: ['post_id']
|
||||
});
|
||||
|
@ -12,11 +12,15 @@ class PostsImporter extends TableImporter {
|
||||
this.newsletters = newsletters;
|
||||
}
|
||||
|
||||
setImportOptions({type = 'post'}) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
async addNewsletters({posts}) {
|
||||
for (const {id} of posts) {
|
||||
for (const {id, visibility} of posts) {
|
||||
await this.knex('posts').update({
|
||||
newsletter_id: luck(90) ? this.newsletters[0].id : this.newsletters[1].id
|
||||
}).where({id});
|
||||
newsletter_id: luck(90) ? (visibility === 'paid' ? this.newsletters[1].id : this.newsletters[0].id) : null
|
||||
}).where({id, type: 'post', status: 'published'});
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,17 +44,21 @@ class PostsImporter extends TableImporter {
|
||||
if (luck(5)) {
|
||||
status = 'draft';
|
||||
}
|
||||
if (this.type === 'page') {
|
||||
status = 'published';
|
||||
}
|
||||
|
||||
const visibility = luck(90) ? 'paid' : luck(10) ? 'members' : 'public';
|
||||
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
created_at: dateToDatabaseString(timestamp),
|
||||
created_by: 'unused',
|
||||
created_by: '1',
|
||||
updated_at: dateToDatabaseString(timestamp),
|
||||
published_at: status === 'published' ? dateToDatabaseString(faker.date.soon(5, timestamp)) : null,
|
||||
uuid: faker.datatype.uuid(),
|
||||
title: title,
|
||||
type: this.type,
|
||||
slug: `${slugify(title)}-${faker.random.numeric(3)}`,
|
||||
status,
|
||||
visibility,
|
||||
@ -74,7 +82,7 @@ class PostsImporter extends TableImporter {
|
||||
}),
|
||||
html: content.map(paragraph => `<p>${paragraph}</p>`).join(''),
|
||||
email_recipient_filter: 'all',
|
||||
newsletter_id: status === 'published' && luck(90) ? visibility === 'paid' ? this.newsletters[1].id : this.newsletters[0].id : null
|
||||
newsletter_id: this.type === 'post' && status === 'published' && luck(90) ? (visibility === 'paid' ? this.newsletters[1].id : this.newsletters[0].id) : null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user