Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ActiveTableSwitcher.php
Go to the documentation of this file.
1 <?php
7 
12 {
18  private $additionalTableSuffix = '_replica';
19 
25  private $outdatedTableSuffix = '_outdated';
26 
34  public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $connection, array $tableNames)
35  {
36  $toRename = [];
37  foreach ($tableNames as $tableName) {
38  $outdatedTableName = $tableName . $this->outdatedTableSuffix;
39  $replicaTableName = $tableName . $this->additionalTableSuffix;
40 
41  $renameBatch = [
42  [
43  'oldName' => $tableName,
44  'newName' => $outdatedTableName
45  ],
46  [
47  'oldName' => $replicaTableName,
48  'newName' => $tableName
49  ],
50  [
51  'oldName' => $outdatedTableName,
52  'newName' => $replicaTableName
53  ]
54  ];
55  $toRename = array_merge($toRename, $renameBatch);
56  }
57 
58  if (!empty($toRename)) {
59  $connection->renameTablesBatch($toRename);
60  }
61  }
62 
68  {
69  return $tableName . $this->additionalTableSuffix;
70  }
71 }
$tableName
Definition: trigger.php:13
switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $connection, array $tableNames)
$connection
Definition: bulk.php:13