0
Fork 0
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:
Sam Lord 2023-02-17 15:47:34 +00:00
parent bb855cd462
commit c6e119ecf5
2 changed files with 24 additions and 11 deletions

View file

@ -153,7 +153,7 @@ class DataGenerator {
data: baseData.posts data: baseData.posts
}); });
await postsImporter.addNewsletters({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({ tags = await jsonImporter.import({
name: 'tags', name: 'tags',
@ -210,7 +210,7 @@ class DataGenerator {
}); });
posts = await postsImporter.import({ posts = await postsImporter.import({
amount: this.modelQuantities.posts, amount: this.modelQuantities.posts,
rows: ['newsletter_id', 'published_at', 'slug'] rows: ['newsletter_id', 'published_at', 'slug', 'status', 'visibility']
}); });
const tagsImporter = new TagsImporter(transaction, { const tagsImporter = new TagsImporter(transaction, {
@ -347,7 +347,7 @@ class DataGenerator {
await mentionsImporter.importForEach(posts, {amount: 4}); await mentionsImporter.importForEach(posts, {amount: 4});
const emailsImporter = new EmailsImporter(transaction, {newsletters, members, membersSubscribeEvents}); 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, amount: 1,
rows: ['created_at', 'email_count', 'delivered_count', 'opened_count', 'failed_count', 'newsletter_id', 'post_id'] 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 redirectsImporter = new RedirectsImporter(transaction);
const redirects = await redirectsImporter.importForEach(posts, { const redirects = await redirectsImporter.importForEach(posts.filter(post => post.status === 'published'), {
amount: 10, amount: 10,
rows: ['post_id'] rows: ['post_id']
}); });
@ -394,7 +394,7 @@ class DataGenerator {
}; };
const importMentions = async () => { 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`); this.logger.info(`Importing up to ${posts.length * 4} mentions`);
const mentionsImporter = new MentionsImporter(transaction, {baseUrl: this.baseUrl}); const mentionsImporter = new MentionsImporter(transaction, {baseUrl: this.baseUrl});

View file

@ -28,19 +28,32 @@ class PostsImporter extends TableImporter {
})).split('\n'); })).split('\n');
const twoYearsAgo = new Date(); const twoYearsAgo = new Date();
twoYearsAgo.setFullYear(twoYearsAgo.getFullYear() - 2); twoYearsAgo.setFullYear(twoYearsAgo.getFullYear() - 2);
const twoWeeksAgo = new Date(); const twoWeeksFromNow = new Date();
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14); twoWeeksFromNow.setDate(twoWeeksFromNow.getDate() + 14);
const timestamp = faker.date.between(twoYearsAgo, twoWeeksAgo); 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 { return {
id: faker.database.mongodbObjectId(), id: faker.database.mongodbObjectId(),
created_at: dateToDatabaseString(timestamp), created_at: dateToDatabaseString(timestamp),
created_by: 'unused', created_by: 'unused',
updated_at: dateToDatabaseString(timestamp), 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(), uuid: faker.datatype.uuid(),
title: title, title: title,
slug: `${slugify(title)}-${faker.random.numeric(3)}`, slug: `${slugify(title)}-${faker.random.numeric(3)}`,
status: 'published', status,
visibility,
mobiledoc: JSON.stringify({ mobiledoc: JSON.stringify({
version: '0.3.1', version: '0.3.1',
atoms: [], atoms: [],
@ -61,7 +74,7 @@ class PostsImporter extends TableImporter {
}), }),
html: content.map(paragraph => `<p>${paragraph}</p>`).join(''), html: content.map(paragraph => `<p>${paragraph}</p>`).join(''),
email_recipient_filter: 'all', 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
}; };
} }
} }