Skip to content

Commit

Permalink
more fixes for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Nov 20, 2023
1 parent 4a32c9b commit 8496507
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions modules/contentbox/models/content/ContentService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ component extends="cborm.models.VirtualEntityService" singleton {
};
// setup
var thisContent = arguments.contentData;

// Get content by slug, if not found then it returns a new entity so we can persist it.
var oContent = findWhere( { "slug" : thisContent.slug, "site" : arguments.site } );
if ( isNull( oContent ) ) {
Expand All @@ -848,13 +849,16 @@ component extends="cborm.models.VirtualEntityService" singleton {
);
return;
}

// Link to site
oContent.setSite( arguments.site );

// add to newContent map so we can avoid slug collisions in recursive relationships
arguments.newContent[ thisContent.slug ] = oContent;

// populate content from data and ignore relationships, we need to build those manually.
var excludedFields = [
"contentID",
"categories",
"children",
"comments",
Expand Down Expand Up @@ -916,6 +920,27 @@ component extends="cborm.models.VirtualEntityService" singleton {
}
}

// CATEGORIES
if ( arrayLen( thisContent.categories ) ) {
oContent.setCategories(
thisContent.categories.map( function( thisCategory ){
var oSiteCategory = site.getCategory( arguments.thisCategory );
return (
!isNull( oSiteCategory ) ? oSiteCategory : variables.categoryService.getOrCreateBySlug(
arguments.thisCategory,
site
)
);
} )
);
logThis(
"+ Categories (#thisContent.categories.toString()#) imported for : (#thisContent.contentType#:#thisContent.slug#)"
);
}

// We now persist it to do child relationships
entitySave( oContent );

// CUSTOM FIELDS
if ( arrayLen( thisContent.customfields ) ) {
// wipe out custom fileds if they exist
Expand All @@ -938,27 +963,6 @@ component extends="cborm.models.VirtualEntityService" singleton {
}
}

// CATEGORIES
if ( arrayLen( thisContent.categories ) ) {
oContent.setCategories(
thisContent.categories.map( function( thisCategory ){
var oSiteCategory = site.getCategory( arguments.thisCategory );
return (
!isNull( oSiteCategory ) ? oSiteCategory : variables.categoryService.getOrCreateBySlug(
arguments.thisCategory,
site
)
);
} )
);
logThis(
"+ Categories (#thisContent.categories.toString()#) imported for : (#thisContent.contentType#:#thisContent.slug#)"
);
}

// We now persist it to do child relationships
entitySave( oContent );

// STATS
if ( structCount( thisContent.stats ) && thisContent.stats.hits > 0 ) {
if ( oContent.hasStats() ) {
Expand Down

0 comments on commit 8496507

Please sign in to comment.