示例#1
0
 /**
  * Runs the batch update process
  */
 public function execute()
 {
     foreach ($this->reader as $rows) {
         $updates = [];
         foreach ($rows as $row) {
             $update = $this->generator->update($row);
             if ($update) {
                 $updates[] = ['primaryKey' => $this->reader->extractPrimaryKeys($row), 'changes' => $update];
             }
         }
         if ($updates) {
             $this->output("Processing " . count($updates) . " rows\n");
             $this->writer->write($updates);
         }
     }
     $this->output("Completed\n");
 }
 /**
  * Slightly hackish to use reflection, but asserting different parameters
  * to consecutive calls of DatabaseBase::select in phpunit is error prone
  *
  * @dataProvider provider_readerSelectConditions
  */
 public function testReaderSelectConditionsMultiplePrimaryKeys($message, $expectedSecondIteration, $primaryKeys, $batchSize = 3)
 {
     $results = $this->genSelectResult($batchSize, $batchSize * 3, function () {
         static $i = 0, $j = 100, $k = 1000;
         return array('id_field' => ++$i, 'foo' => ++$j, 'bar' => ++$k);
     });
     $db = $this->mockDbConsecutiveSelect($results);
     $conditions = array('bar' => 42, 'baz' => 'hai');
     $reader = new BatchRowIterator($db, 'some_table', $primaryKeys, $batchSize);
     $reader->addConditions($conditions);
     $buildConditions = new ReflectionMethod($reader, 'buildConditions');
     $buildConditions->setAccessible(true);
     // On first iteration only the passed conditions must be used
     $this->assertEquals($conditions, $buildConditions->invoke($reader), 'First iteration must return only the conditions passed in addConditions');
     $reader->rewind();
     // Second iteration must use the maximum primary key of last set
     $this->assertEquals($conditions + $expectedSecondIteration, $buildConditions->invoke($reader), $message);
 }