/**
  * @return void
  */
 public function testBulkUpdateBuildsAndExecutesQueries()
 {
     $touchUpdaterSet = $this->createTouchUpdaterSet();
     $idLocale = 1;
     $connection = $this->createConnectionMock();
     $touchUpdater = $this->createTouchUpdater();
     $expectedQuery = "UPDATE touchKeyTableName_value SET key = 'data_key1' WHERE touchKeyIdColumnName_value = 'new value'; \n" . "UPDATE touchKeyTableName_value SET key = 'data_key2' WHERE touchKeyIdColumnName_value = 'new value2'";
     $connection->expects($this->once())->method('exec')->with($expectedQuery);
     $this->assertEmpty($this->bulkTouchUpdateQuery->getRawSqlString());
     $touchUpdater->bulkUpdate($touchUpdaterSet, $idLocale, $connection);
 }
예제 #2
0
 /**
  * @param \Spryker\Zed\Collector\Business\Exporter\Writer\Storage\TouchUpdaterSet $touchUpdaterSet
  * @param int $idLocale
  * @param \Propel\Runtime\Connection\ConnectionInterface|null $connection
  *
  * @return void
  */
 public function bulkUpdate(TouchUpdaterSet $touchUpdaterSet, $idLocale, ConnectionInterface $connection = null)
 {
     foreach ($touchUpdaterSet->getData() as $key => $touchData) {
         $idKey = $this->getCollectorKeyFromData($touchData);
         if ($idKey !== null) {
             $this->bulkTouchUpdateQuery->addQuery($this->touchKeyTableName, $key, $this->touchKeyIdColumnName, $idKey);
         } else {
             /** @var \Orm\Zed\Touch\Persistence\SpyTouchStorage|\Orm\Zed\Touch\Persistence\SpyTouchSearch $entity */
             $entity = $this->findOrCreateTouchKeyEntity($key, $idLocale);
             $entity->setFkTouch($touchData[CollectorConfig::COLLECTOR_TOUCH_ID]);
             $entity->save();
         }
     }
     $updateSql = $this->bulkTouchUpdateQuery->getRawSqlString();
     $this->bulkTouchUpdateQuery->flushQueries();
     if (trim($updateSql) !== '' && $connection !== null) {
         $connection->exec($updateSql);
     }
 }