/**
  * @param Iterator $it
  * @param integer $oldUserId
  * @param callable $callback Receives a single row, returns domain object or null
  * @param string $userTupleGetter Method to call on domain object that will return
  *  a UserTuple instance.
  */
 protected function purgeTable(Iterator $it, $oldUserId, $callback, $userTupleGetter)
 {
     foreach ($it as $batch) {
         foreach ($batch as $pkRow) {
             $obj = call_user_func($callback, $pkRow);
             if (!$obj) {
                 continue;
             }
             // This is funny looking because the loaded objects may have come from
             // the db with new user ids, or the cache with old user ids.
             // We need to tweak this object to look like the old user ids and then
             // purge caches so they get the old user id cache keys.
             $tuple = call_user_func(array($obj, $userTupleGetter));
             if (!$tuple) {
                 continue;
             }
             $tuple->id = $oldUserId;
             $om = $this->storage->getStorage(get_class($obj));
             $om->clear();
             $om->merge($obj);
             $om->cachePurge($obj);
         }
         $this->storage->clear();
     }
 }
 /**
  * Overwriting default writer because I want to use Flow storage methods so
  * the updates also affect cache, not just DB.
  *
  * @param array[] $updates
  */
 public function write(array $updates)
 {
     /*
      * from:
      * array(
      *     'primaryKey' => array( 'workflow_id' => $id ),
      *     'updates' => array( 'workflow_last_update_timestamp' => $timestamp ),
      * )
      * to:
      * array( $id => $timestamp );
      */
     $timestamps = array_combine($this->arrayColumn($this->arrayColumn($updates, 'primaryKey'), 'workflow_id'), $this->arrayColumn($this->arrayColumn($updates, 'changes'), 'workflow_last_update_timestamp'));
     /** @var UUID[] $uuids */
     $uuids = array_map(array('Flow\\Model\\UUID', 'create'), array_keys($timestamps));
     /** @var Workflow[] $workflows */
     $workflows = $this->storage->getMulti('Workflow', $uuids);
     foreach ($workflows as $workflow) {
         $timestamp = $timestamps[$workflow->getId()->getBinary()];
         $workflow->updateLastModified(UUID::getComparisonUUID($timestamp));
     }
     $this->storage->multiPut($workflows);
     // prevent memory from filling up
     $this->storage->clear();
     wfWaitForSlaves(false, false, $this->clusterName);
 }