imports/vx/server/code/vxapp.js
/**
     * Synchronize source and target record sets making them match exactly.
     */
Synchronize source and target record sets making them match exactly.
Synchronize source and target record sets making them match exactly .
synchronizeCollection(formObject, collection, sourceRecords, targetRecords) {
        OLog.debug(`vxapp.js synchronizeCollection collectionName=${collection._name} ` +
            `source count=${sourceRecords.length} target count=${targetRecords.length}`)
        _.each(sourceRecords, sourceRecord => {
            const targetRecord = _.findWhere(targetRecords, { name : sourceRecord.name })
            if (targetRecord) {
                OLog.debug(`vxapp.js synchronizeCollection collectionName=${collection._name} updating name=${sourceRecord.name} ` +
                    ` sourceRecordId=${sourceRecord._id} targetRecordId=${targetRecord._id}`)
                const sourceRecordId = sourceRecord._id
                delete sourceRecord._id
                sourceRecord.dateModified = new Date()
                sourceRecord.userModified = Meteor.userId()
                sourceRecord.domain = formObject.targetDomain
                const result = collection.direct.update(targetRecord._id, sourceRecord, { bypassCollection2: true })
                if (result !== 1) {
                    OLog.error(`vxapp.js synchronizeCollection collectionName=${collection._name} ` +
                        `sourceRecordId=${sourceRecordId} targetRecordId=${targetRecord._id} result=${result}`)
                }
                targetRecords = _.without(targetRecords, _.findWhere(targetRecords, { _id : targetRecord._id }))
            }
            else {
                OLog.debug(`vxapp.js synchronizeCollection collectionName=${collection._name} inserting name=${sourceRecord.name} ` +
                    ` sourceRecordId=${sourceRecord._id}`)
                delete sourceRecord._id
                sourceRecord.dateModified = new Date()
                sourceRecord.userModified = Meteor.userId()
                sourceRecord.domain = formObject.targetDomain
                collection.direct.insert(sourceRecord)
            }
        })
        _.each(targetRecords, targetRecord => {
            OLog.debug(`vxapp.js synchronizeCollection collectionName=${collection._name} removing name=${targetRecord.name} ` +
                ` targetRecordId=${targetRecord._id}`)
            collection.direct.remove(targetRecord._id)
        })
    }
synchronizeCollection ( formObject , collection , sourceRecords , targetRecords ) { OLog . debug ( ` ${ collection . _name } ` + ` ${ sourceRecords . length } ${ targetRecords . length } ` ) _ . each ( sourceRecords , sourceRecord => { const targetRecord = _ . findWhere ( targetRecords , { name : sourceRecord . name } ) if ( targetRecord ) { OLog . debug ( ` ${ collection . _name } ${ sourceRecord . name } ` + ` ${ sourceRecord . _id } ${ targetRecord . _id } ` ) const sourceRecordId = sourceRecord . _id delete sourceRecord . _id sourceRecord . dateModified = new Date ( ) sourceRecord . userModified = Meteor . userId ( ) sourceRecord . domain = formObject . targetDomain const result = collection . direct . update ( targetRecord . _id , sourceRecord , { bypassCollection2 : true } ) if ( result !== 1 ) { OLog . error ( ` ${ collection . _name } ` + ` ${ sourceRecordId } ${ targetRecord . _id } ${ result } ` ) } targetRecords = _ . without ( targetRecords , _ . findWhere ( targetRecords , { _id : targetRecord . _id } ) ) } else { OLog . debug ( ` ${ collection . _name } ${ sourceRecord . name } ` + ` ${ sourceRecord . _id } ` ) delete sourceRecord . _id sourceRecord . dateModified = new Date ( ) sourceRecord . userModified = Meteor . userId ( ) sourceRecord . domain = formObject . targetDomain collection . direct . insert ( sourceRecord ) } } ) _ . each ( targetRecords , targetRecord => { OLog . debug ( ` ${ collection . _name } ${ targetRecord . name } ` + ` ${ targetRecord . _id } ` ) collection . direct . remove ( targetRecord . _id ) } ) }
Synchronize source and target record sets making them match exactly.
Synchronize source and target record sets making them match exactly .