mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
Added tag to posts when importing content
refs: https://github.com/TryGhost/Toolbox/issues/431
This commit is contained in:
parent
8ed5f9784d
commit
7c6854651d
3 changed files with 35 additions and 7 deletions
|
@ -131,15 +131,15 @@ module.exports = ({result, siteUrl, postsUrl, emailRecipient}) => `
|
|||
${iff(result.errors, `
|
||||
<tr>
|
||||
<td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; padding-bottom: 16px;">
|
||||
<p style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; color: #3A464C; font-weight: normal; margin: 0; line-height: 25px; margin-bottom: 0px;">Failed to import content with the following error${iff(result.errors && result.errors.length > 1), `s`, ``}:</p>
|
||||
<p style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; color: #3A464C; font-weight: normal; margin: 0; line-height: 25px; margin-bottom: 0px;">Failed to import content with the following error${iff(result.errors.length > 1), `s`, ``}:</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; padding-bottom: 16px;">
|
||||
<ul>
|
||||
${_.each(result.errors, error => `
|
||||
${_.map(result.errors, error => `
|
||||
<li style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; color: #3A464C; font-weight: normal; margin: 0; line-height: 25px; margin-bottom: 0px;">${error.message}</li>
|
||||
`)}
|
||||
`).join('\n')}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -147,15 +147,15 @@ module.exports = ({result, siteUrl, postsUrl, emailRecipient}) => `
|
|||
${iff(result.problems && result.problems.length > 0, `
|
||||
<tr>
|
||||
<td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; padding-bottom: 16px;">
|
||||
<p style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; color: #3A464C; font-weight: normal; margin: 0; line-height: 25px; margin-bottom: 0px;">Imported content successfully, but with the following warning${iff(result.problems && result.problems.length > 1), `s`, ``}:</p>
|
||||
<p style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; color: #3A464C; font-weight: normal; margin: 0; line-height: 25px; margin-bottom: 0px;">Imported content successfully, but with the following warning${iff(result.problems.length > 1), `s`, ``}:</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; vertical-align: top; padding-bottom: 16px;">
|
||||
<ul>
|
||||
${_.each(result.problems, problem => `
|
||||
${_.map(result.problems, problem => `
|
||||
<li style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; color: #3A464C; font-weight: normal; margin: 0; line-height: 25px; margin-bottom: 0px;">${problem.message}</li>
|
||||
`)}
|
||||
`).join('\n')}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -426,13 +426,17 @@ class ImportManager {
|
|||
importResult = await this.generateReport(importResult);
|
||||
|
||||
return importResult;
|
||||
} catch (err) {
|
||||
logging.error(`Content import was unsuccessful`, {
|
||||
error: err
|
||||
});
|
||||
} finally {
|
||||
// Step 5: Cleanup any files
|
||||
await this.cleanUp();
|
||||
|
||||
if (!importOptions.forceInline) {
|
||||
// Step 6: Send email
|
||||
const email = this.generateCompletionEmail(importResult.data, {
|
||||
const email = this.generateCompletionEmail(importResult?.data, {
|
||||
emailRecipient: importOptions.user.email,
|
||||
importTag: importOptions.importTag
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const _ = require('lodash');
|
||||
const ObjectId = require('bson-objectid').default;
|
||||
const Promise = require('bluebird');
|
||||
const semver = require('semver');
|
||||
const {IncorrectUsageError} = require('@tryghost/errors');
|
||||
|
@ -15,6 +16,7 @@ const StripeProductsImporter = require('./stripe-products');
|
|||
const StripePricesImporter = require('./stripe-prices');
|
||||
const CustomThemeSettingsImporter = require('./custom-theme-settings');
|
||||
const RolesImporter = require('./roles');
|
||||
const {slugify} = require('@tryghost/string/lib');
|
||||
|
||||
let importers = {};
|
||||
let DataImporter;
|
||||
|
@ -46,6 +48,28 @@ DataImporter = {
|
|||
doImport: async function doImport(importData, importOptions) {
|
||||
importOptions = importOptions || {};
|
||||
|
||||
if (importOptions.importTag) {
|
||||
const tagId = ObjectId().toHexString();
|
||||
if (!('tags' in importData.data)) {
|
||||
importData.data.tags = [];
|
||||
}
|
||||
importData.data.tags.push({
|
||||
id: tagId,
|
||||
name: importOptions.importTag,
|
||||
slug: slugify(importOptions.importTag)
|
||||
});
|
||||
for (const post of importData.data.posts || []) {
|
||||
if (!('id' in post)) {
|
||||
// Make sure post has an id if it doesn't already
|
||||
post.id = ObjectId().toHexString();
|
||||
}
|
||||
importData.data.posts_tags.push({
|
||||
post_id: post.id,
|
||||
tag_id: tagId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const ops = [];
|
||||
let problems = [];
|
||||
let errors = [];
|
||||
|
|
Loading…
Add table
Reference in a new issue