Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProductUrlRewriteDatabaseMap.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
18  const ENTITY_TYPE = 'product';
19 
23  private $createdTableAdapters = [];
24 
28  private $hashMapPool;
29 
33  private $connection;
34 
38  private $temporaryTableService;
39 
45  public function __construct(
46  ResourceConnection $connection,
47  HashMapPool $hashMapPool,
48  TemporaryTableService $temporaryTableService
49  ) {
50  $this->connection = $connection;
51  $this->hashMapPool = $hashMapPool;
52  $this->temporaryTableService = $temporaryTableService;
53  }
54 
61  private function generateTableAdapter($categoryId)
62  {
63  if (!isset($this->createdTableAdapters[$categoryId])) {
64  $this->createdTableAdapters[$categoryId] = $this->generateData($categoryId);
65  }
66  }
67 
71  public function getData($categoryId, $key)
72  {
73  $this->generateTableAdapter($categoryId);
74  $urlRewritesConnection = $this->connection->getConnection();
75  $select = $urlRewritesConnection->select()
76  ->from(['e' => $this->createdTableAdapters[$categoryId]])
77  ->where('hash_key = ?', $key);
78  return $urlRewritesConnection->fetchAll($select);
79  }
80 
88  private function generateData($categoryId)
89  {
90  $urlRewritesConnection = $this->connection->getConnection();
91  $select = $urlRewritesConnection->select()
92  ->from(
93  ['e' => $this->connection->getTableName('url_rewrite')],
94  ['e.*', 'hash_key' => new \Zend_Db_Expr(
95  "CONCAT(e.store_id,'" . MergeDataProvider::SEPARATOR . "', e.entity_id)"
96  )
97  ]
98  )
99  ->where('entity_type = ?', self::ENTITY_TYPE)
100  ->where(
101  $urlRewritesConnection->prepareSqlCondition(
102  'entity_id',
103  [
104  'in' => $this->hashMapPool->getDataMap(DataProductHashMap::class, $categoryId)
105  ->getAllData($categoryId)
106  ]
107  )
108  );
109  $mapName = $this->temporaryTableService->createFromSelect(
110  $select,
111  $this->connection->getConnection(),
112  [
113  'PRIMARY' => ['url_rewrite_id'],
114  'HASHKEY_ENTITY_STORE' => ['hash_key'],
115  'ENTITY_STORE' => ['entity_id', 'store_id']
116  ]
117  );
118  return $mapName;
119  }
120 
124  public function destroyTableAdapter($categoryId)
125  {
126  $this->hashMapPool->resetMap(DataProductHashMap::class, $categoryId);
127  if (isset($this->createdTableAdapters[$categoryId])) {
128  $this->temporaryTableService->dropTable($this->createdTableAdapters[$categoryId]);
129  unset($this->createdTableAdapters[$categoryId]);
130  }
131  }
132 }
__construct(ResourceConnection $connection, HashMapPool $hashMapPool, TemporaryTableService $temporaryTableService)
$connection
Definition: bulk.php:13