mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Allow data-generator to make scheduled and draft posts
no issue Also adds visiblity options, paid, members-only and public
This commit is contained in:
parent
bb855cd462
commit
c6e119ecf5
2 changed files with 24 additions and 11 deletions
|
@ -153,7 +153,7 @@ class DataGenerator {
|
|||
data: baseData.posts
|
||||
});
|
||||
await postsImporter.addNewsletters({posts});
|
||||
posts = await transaction.select('id', 'newsletter_id', 'published_at', 'slug').from('posts');
|
||||
posts = await transaction.select('id', 'newsletter_id', 'published_at', 'slug', 'status', 'visibility').from('posts');
|
||||
|
||||
tags = await jsonImporter.import({
|
||||
name: 'tags',
|
||||
|
@ -210,7 +210,7 @@ class DataGenerator {
|
|||
});
|
||||
posts = await postsImporter.import({
|
||||
amount: this.modelQuantities.posts,
|
||||
rows: ['newsletter_id', 'published_at', 'slug']
|
||||
rows: ['newsletter_id', 'published_at', 'slug', 'status', 'visibility']
|
||||
});
|
||||
|
||||
const tagsImporter = new TagsImporter(transaction, {
|
||||
|
@ -347,7 +347,7 @@ class DataGenerator {
|
|||
await mentionsImporter.importForEach(posts, {amount: 4});
|
||||
|
||||
const emailsImporter = new EmailsImporter(transaction, {newsletters, members, membersSubscribeEvents});
|
||||
const emails = await emailsImporter.importForEach(posts, {
|
||||
const emails = await emailsImporter.importForEach(posts.filter(post => post.status === 'published'), {
|
||||
amount: 1,
|
||||
rows: ['created_at', 'email_count', 'delivered_count', 'opened_count', 'failed_count', 'newsletter_id', 'post_id']
|
||||
});
|
||||
|
@ -365,7 +365,7 @@ class DataGenerator {
|
|||
});
|
||||
|
||||
const redirectsImporter = new RedirectsImporter(transaction);
|
||||
const redirects = await redirectsImporter.importForEach(posts, {
|
||||
const redirects = await redirectsImporter.importForEach(posts.filter(post => post.status === 'published'), {
|
||||
amount: 10,
|
||||
rows: ['post_id']
|
||||
});
|
||||
|
@ -394,7 +394,7 @@ class DataGenerator {
|
|||
};
|
||||
|
||||
const importMentions = async () => {
|
||||
const posts = await transaction.select('id', 'newsletter_id', 'published_at', 'slug').from('posts');
|
||||
const posts = await transaction.select('id', 'newsletter_id', 'published_at', 'slug', 'status', 'visibility').from('posts');
|
||||
this.logger.info(`Importing up to ${posts.length * 4} mentions`);
|
||||
|
||||
const mentionsImporter = new MentionsImporter(transaction, {baseUrl: this.baseUrl});
|
||||
|
|
|
@ -28,19 +28,32 @@ class PostsImporter extends TableImporter {
|
|||
})).split('\n');
|
||||
const twoYearsAgo = new Date();
|
||||
twoYearsAgo.setFullYear(twoYearsAgo.getFullYear() - 2);
|
||||
const twoWeeksAgo = new Date();
|
||||
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14);
|
||||
const timestamp = faker.date.between(twoYearsAgo, twoWeeksAgo);
|
||||
const twoWeeksFromNow = new Date();
|
||||
twoWeeksFromNow.setDate(twoWeeksFromNow.getDate() + 14);
|
||||
const timestamp = faker.date.between(twoYearsAgo, twoWeeksFromNow);
|
||||
const currentTime = new Date();
|
||||
|
||||
let status = 'published';
|
||||
if (timestamp > currentTime) {
|
||||
status = 'scheduled';
|
||||
}
|
||||
if (luck(5)) {
|
||||
status = 'draft';
|
||||
}
|
||||
|
||||
const visibility = luck(90) ? 'paid' : luck(10) ? 'members' : 'public';
|
||||
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
created_at: dateToDatabaseString(timestamp),
|
||||
created_by: 'unused',
|
||||
updated_at: dateToDatabaseString(timestamp),
|
||||
published_at: dateToDatabaseString(faker.date.soon(5, timestamp)),
|
||||
published_at: status === 'published' ? dateToDatabaseString(faker.date.soon(5, timestamp)) : null,
|
||||
uuid: faker.datatype.uuid(),
|
||||
title: title,
|
||||
slug: `${slugify(title)}-${faker.random.numeric(3)}`,
|
||||
status: 'published',
|
||||
status,
|
||||
visibility,
|
||||
mobiledoc: JSON.stringify({
|
||||
version: '0.3.1',
|
||||
atoms: [],
|
||||
|
@ -61,7 +74,7 @@ class PostsImporter extends TableImporter {
|
|||
}),
|
||||
html: content.map(paragraph => `<p>${paragraph}</p>`).join(''),
|
||||
email_recipient_filter: 'all',
|
||||
newsletter_id: luck(10) ? this.newsletters[0].id : this.newsletters[1].id
|
||||
newsletter_id: status === 'published' && luck(90) ? visibility === 'paid' ? this.newsletters[1].id : this.newsletters[0].id : null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue