@@ -225,23 +225,21 @@ Sync.prototype.loadData = function () {
225225 var _loadEntries = function ( _content_types ) {
226226 for ( var i = 0 , total = _content_types . length ; i < total ; i ++ ) {
227227 _calls . push ( function ( content_type ) {
228- return utility . getEntries ( content_type , self . inputs . language , { } , [ 'publish_details' ] , self . inputs . environment . name )
228+ return utility . getEntries ( content_type , self . inputs . language , { } , [ 'publish_details' , '_version' ] , self . inputs . environment . name )
229229 . then ( function ( entries ) {
230230 var _entries = [ ] ;
231231 if ( self . inputs . datetime ) {
232232 for ( var i = 0 ; i < entries . length ; i ++ ) {
233- if ( entries [ i ] [ 'publish_details' ] instanceof Array ) {
234- var idx = _ . findIndex ( entries [ i ] [ 'publish_details' ] , function ( object ) {
235- if ( object . locale === self . inputs . language && object . environment === self . inputs . environment . uid && object . time && object . time >= self . inputs . datetime ) {
236- _entries . push ( entries [ i ] ) ;
237- return true ;
238- }
239- } ) ;
240- } else {
241- if ( entries [ i ] [ 'publish_details' ] [ 'locale' ] === self . inputs . language && entries [ i ] [ 'publish_details' ] [ 'environment' ] === self . inputs . environment . uid && entries [ i ] [ 'publish_details' ] [ 'time' ] && entries [ i ] [ 'publish_details' ] [ 'time' ] >= self . inputs . datetime ) {
233+ // this is for the API Stack 3.1 with new response
234+ if ( ! ( entries [ i ] [ 'publish_details' ] instanceof Array ) && typeof entries [ i ] [ 'publish_details' ] === "object" ) {
235+ entries [ i ] [ 'publish_details' ] [ 'version' ] = entries [ i ] [ "_version" ]
236+ entries [ i ] [ 'publish_details' ] = [ entries [ i ] [ 'publish_details' ] ]
237+ }
238+ _ . findIndex ( entries [ i ] [ 'publish_details' ] , function ( object ) {
239+ if ( object . locale === self . inputs . language && object . environment === self . inputs . environment . uid && object . time && object . time >= self . inputs . datetime ) {
242240 _entries . push ( entries [ i ] ) ;
243241 }
244- }
242+ } ) ;
245243 }
246244 } else {
247245 _entries = entries || [ ] ;
@@ -298,25 +296,16 @@ Sync.prototype.parseEntries = function (entries, content_type) {
298296 var deferred = Q . defer ( ) ;
299297 console . log ( "Restoring %d entries of %s ContentType." , entries . length , content_type ) ;
300298 for ( var i = 0 , total = entries . length ; i < total ; i ++ ) {
301- var _locale , _version ;
302299 if ( entries [ i ] && entries [ i ] [ 'publish_details' ] ) {
303- var idx ;
304- if ( entries [ i ] [ 'publish_details' ] instanceof Array ) {
305- idx = _ . findIndex ( entries [ i ] [ 'publish_details' ] , {
306- environment : self . inputs . environment . uid ,
307- locale : self . inputs . language
308- } ) ;
309- _locale = entries [ i ] [ 'publish_details' ] [ idx ] [ 'locale' ] ;
310- _version = entries [ i ] [ 'publish_details' ] [ idx ] [ 'version' ] ;
311- } else {
312- if ( entries [ i ] [ 'publish_details' ] [ 'environment' ] === self . inputs . environment . uid && entries [ i ] [ 'publish_details' ] [ 'locale' ] === self . inputs . language ) {
313- idx = 0 ;
314- _locale = entries [ i ] [ 'locale' ] ;
315- _version = entries [ i ] [ 'version' ] ;
316- } else {
317- idx = - 1 ;
318- }
319- }
300+ // this is for the API Stack 3.1 with new response
301+ if ( ! ( entries [ i ] [ 'publish_details' ] instanceof Array ) && typeof entries [ i ] [ 'publish_details' ] === "object" ) {
302+ entries [ i ] [ 'publish_details' ] [ 'version' ] = entries [ i ] [ "_version" ]
303+ entries [ i ] [ 'publish_details' ] = [ entries [ i ] [ 'publish_details' ] ]
304+ }
305+ var idx = _ . findIndex ( entries [ i ] [ 'publish_details' ] , {
306+ environment : self . inputs . environment . uid ,
307+ locale : self . inputs . language
308+ } ) ;
320309 var _lang = _ . findIndex ( languages , { 'code' : self . inputs . language } ) ;
321310 if ( ~ idx && ~ _lang ) {
322311 q . push ( {
@@ -329,8 +318,8 @@ Sync.prototype.parseEntries = function (entries, content_type) {
329318 } ,
330319 entry : {
331320 title : entries [ i ] [ 'title' ] || entries [ i ] [ 'uid' ] ,
332- locale : _locale || "en-us" ,
333- version : _version ,
321+ locale : entries [ i ] [ 'publish_details' ] [ idx ] [ 'locale' ] || "en-us" ,
322+ version : entries [ i ] [ 'publish_details' ] [ idx ] [ 'version' ] ,
334323 entry_uid : entries [ i ] [ 'uid' ]
335324 } ,
336325 locale : [ self . inputs . language ] ,
@@ -413,18 +402,15 @@ Sync.prototype.assets = function (_callback) {
413402 _assets = [ ] ;
414403 for ( var i = 0 ; i < assets . length ; i ++ ) {
415404 if ( assets [ i ] && assets [ i ] [ 'publish_details' ] ) {
416- if ( assets [ i ] [ 'publish_details' ] instanceof Array ) {
417- var idx = _ . findIndex ( assets [ i ] [ 'publish_details' ] , function ( object ) {
418- if ( object . locale === self . inputs . language && object . environment === self . inputs . environment . uid && object . time && object . time >= self . inputs . datetime ) {
419- _assets . push ( assets [ i ] ) ;
420- return true ;
421- }
422- } ) ;
423- } else {
424- if ( assets [ i ] [ 'publish_details' ] [ 'locale' ] === self . inputs . language && assets [ i ] [ 'publish_details' ] [ 'environment' ] === self . inputs . environment . uid && assets [ i ] [ 'publish_details' ] [ 'time' ] && assets [ i ] [ 'publish_details' ] [ 'time' ] >= self . inputs . datetime ) {
405+ // this is for the API Stack 3.1 with new response
406+ if ( ! ( assets [ i ] [ 'publish_details' ] instanceof Array ) && typeof assets [ i ] [ 'publish_details' ] === "object" ) {
407+ assets [ i ] [ 'publish_details' ] = [ assets [ i ] [ 'publish_details' ] ]
408+ }
409+ _ . findIndex ( assets [ i ] [ 'publish_details' ] , function ( object ) {
410+ if ( object . locale === self . inputs . language && object . environment === self . inputs . environment . uid && object . time && object . time >= self . inputs . datetime ) {
425411 _assets . push ( assets [ i ] ) ;
426412 }
427- }
413+ } ) ;
428414 }
429415 }
430416 }
0 commit comments