Skip to content

Commit

Permalink
Fixes pencilblue#1217 - corrects issue where page service executes in…
Browse files Browse the repository at this point in the history
…correct callback in wp-import
  • Loading branch information
brianhyder committed Feb 7, 2017
1 parent d46e024 commit 2c0f82b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion plugins/wp_import/controllers/import_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ module.exports = function (pb) {

self.wpXmlParse.parse(data.toString(), self.session.authentication.user_id, function(err, users) {
if(util.isError(err)) {
self.session.error = err.stack;
var errStr = err.stack;
if (err.validationErrors) {
errStr = err.validationErrors.reduce(function(str, v, i) {
return str + (i === 0 ? '' : '\n') + (v.item ? v.item + ':' : '') + v.field + ': ' + v.message;
}, '');
}
self.session.error = errStr;
return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.g('generic.ERROR_SAVING'))});
}

Expand Down
13 changes: 10 additions & 3 deletions plugins/wp_import/services/wp_xml_parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function WPXMLParseServiceModule(pb) {
* @type {SiteQueryService}
*/
this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: true});

/**
* @property service
* @type {UserService}
Expand Down Expand Up @@ -394,7 +394,7 @@ module.exports = function WPXMLParseServiceModule(pb) {
url: pageName,
headline: title,
publish_date: new Date(rawPage['wp:post_date'][0]),
page_layout: BaseObjectService.sanitize(updatedContent, BaseObjectService.getContentSanitizationRules()),
page_layout: BaseObjectService.sanitize(updatedContent, BaseObjectService.getContentSanitizationRules()) || ' ',
page_topics: pageTopics,
page_media: pageMedia,
seo_title: title,
Expand All @@ -403,7 +403,14 @@ module.exports = function WPXMLParseServiceModule(pb) {
draft: 0
};
var pageService = new pb.PageService({site: self.site, onlyThisSite: true});
pageService.save(pageDoc, cb);
pageService.save(pageDoc, function(err, result) {
if (!!err && Array.isArray(err.validationErrors)) {
err.validationErrors.forEach(function(v) {
v.item = title;
});
}
callback(err, result);
});
});
});
};
Expand Down

0 comments on commit 2c0f82b

Please sign in to comment.