lib/tasks.js
function crossCorrectPass(callback) {
      return async.series([ find, correct ], callback);
      function find(callback) {
        return self.apos.docs.db.findWithProjection({ parkedId: { $exists: 1 } }).toArray(function(err, _pages) {
          if (err) {
            return callback(err);
          }
          pages = _pages;
          return callback(null);
        });
      }
      function correct(callback) {
        var parkedIdsByWorkflowGuid = {};
        _.each(pages, function(page) {
          parkedIdsByWorkflowGuid[page.workflowGuid] = page.parkedId;
        });
        return async.eachSeries(_.keys(parkedIdsByWorkflowGuid), function(workflowGuid, callback) {
          return self.apos.docs.db.update({
            workflowGuid: workflowGuid
          }, {
            $set: {
              parkedId: parkedIdsByWorkflowGuid[workflowGuid]
            }
          }, {
            multi: true
          }, callback);
        }, callback);
      }
    }
function crossCorrectPass(callback) {
      return async.series([ find, correct ], callback);
      function find(callback) {
        return self.apos.docs.db.findWithProjection({ parkedId: { $exists: 1 } }).toArray(function(err, _pages) {
          if (err) {
            return callback(err);
          }
          pages = _pages;
          return callback(null);
        });
      }
      function correct(callback) {
        var parkedIdsByWorkflowGuid = {};
        _.each(pages, function(page) {
          parkedIdsByWorkflowGuid[page.workflowGuid] = page.parkedId;
        });
        return async.eachSeries(_.keys(parkedIdsByWorkflowGuid), function(workflowGuid, callback) {
          return self.apos.docs.db.update({
            workflowGuid: workflowGuid
          }, {
            $set: {
              parkedId: parkedIdsByWorkflowGuid[workflowGuid]
            }
          }, {
            multi: true
          }, callback);
        }, callback);
      }
    }
function crossCorrectPass ( callback ) { return async . series ( [ find , correct ] , callback ) ; function find ( callback ) { return self . apos . docs . db . findWithProjection ( { parkedId : { $exists : 1 } } ) . toArray ( function ( err , _pages ) { if ( err ) { return callback ( err ) ; } pages = _pages ; return callback ( null ) ; } ) ; } function correct ( callback ) { var parkedIdsByWorkflowGuid = { } ; _ . each ( pages , function ( page ) { parkedIdsByWorkflowGuid [ page . workflowGuid ] = page . parkedId ; } ) ; return async . eachSeries ( _ . keys ( parkedIdsByWorkflowGuid ) , function ( workflowGuid , callback ) { return self . apos . docs . db . update ( { workflowGuid : workflowGuid } , { $set : { parkedId : parkedIdsByWorkflowGuid [ workflowGuid ] } } , { multi : true } , callback ) ; } , callback ) ; } }
First pass: for some workflowGuids, only some of the locales have a parkedId, due to various catch-22's. Give them all a parkedId.
First pass : for some workflowGuids only some of the locales have a parkedId due to various catch - 22 s . Give them all a parkedId .