diff --git a/packages/mg-wp-api/README.md b/packages/mg-wp-api/README.md index cf525a13f..fd311fa8e 100644 --- a/packages/mg-wp-api/README.md +++ b/packages/mg-wp-api/README.md @@ -66,6 +66,9 @@ It's possible to pass more options, in order to achieve a better migration file - Provide a JSON file with users. Contents should be a JSON array of objects that match the format returned by the Wordpress API, including the following keys: "id", "slug", "name", "description", "email" and "url". +- **`--posts**`** + - boolean - default: `true` + - Import posts - **`--pages**`** - boolean - default: `true` - Import pages diff --git a/packages/mg-wp-api/lib/fetch.js b/packages/mg-wp-api/lib/fetch.js index 1f9bdc62b..2b9bf9a49 100644 --- a/packages/mg-wp-api/lib/fetch.js +++ b/packages/mg-wp-api/lib/fetch.js @@ -1,6 +1,6 @@ import WPAPI from 'wpapi'; -const discover = async (url, {apiUser, usersJSON, pages, limit, cpt}) => { +const discover = async (url, {apiUser, usersJSON, posts, pages, limit, cpt}) => { const requestOptions = {endpoint: `${url}/wp-json`}; if (apiUser && apiUser.username && apiUser.password) { @@ -29,9 +29,11 @@ const discover = async (url, {apiUser, usersJSON, pages, limit, cpt}) => { values.site = site; - const postsData = await site.posts().perPage(limit); - values.totals.posts = postsData._paging && postsData._paging.total ? postsData._paging.total : 0; - values.batches.posts = postsData._paging && postsData._paging.totalPages ? postsData._paging.totalPages : 0; + if (posts) { + const postsData = await site.posts().perPage(limit); + values.totals.posts = postsData._paging && postsData._paging.total ? postsData._paging.total : 0; + values.batches.posts = postsData._paging && postsData._paging.totalPages ? postsData._paging.totalPages : 0; + } if (pages) { const pageData = await site.pages().perPage(limit); @@ -87,7 +89,7 @@ const buildTasks = (fileCache, tasks, api, type, limit, isAuthRequest, logger) = const tasks = async (url, ctx) => { const {logger} = ctx; const {apiUser} = ctx || {}; - const {pages, limit, cpt} = ctx.options; + const {pages, posts, limit, cpt} = ctx.options; const {usersJSON} = ctx || null; let isAuthRequest = false; @@ -99,7 +101,7 @@ const tasks = async (url, ctx) => { isAuthRequest = true; } - const api = await discover(url, {apiUser, usersJSON, limit, cpt, pages}); + const api = await discover(url, {apiUser, usersJSON, posts, pages, limit, cpt}); const theTasks = []; diff --git a/packages/migrate/commands/wp-api.js b/packages/migrate/commands/wp-api.js index 3d02bfbf2..9e6cd3e13 100644 --- a/packages/migrate/commands/wp-api.js +++ b/packages/migrate/commands/wp-api.js @@ -70,6 +70,10 @@ const setup = (sywac) => { defaultValue: null, desc: 'Provide a JSON file with users' }); + sywac.boolean('--posts', { + defaultValue: true, + desc: 'Import posts' + }); sywac.boolean('--pages', { defaultValue: true, desc: 'Import pages'