Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexSwitcher.php
Go to the documentation of this file.
1 <?php
7 
11 
19 {
23  private $resource;
24 
28  private $resolver;
29 
33  private $state;
34 
40  public function __construct(
41  ResourceConnection $resource,
42  IndexScopeResolverInterface $indexScopeResolver,
43  State $state
44  ) {
45  $this->resource = $resource;
46  $this->resolver = $indexScopeResolver;
47  $this->state = $state;
48  }
49 
54  public function switchIndex(array $dimensions)
55  {
56  if (State::USE_TEMPORARY_INDEX === $this->state->getState()) {
58 
59  $temporalIndexTable = $this->resolver->resolve($index, $dimensions);
60  if (!$this->resource->getConnection()->isTableExists($temporalIndexTable)) {
62  __(
63  "Temporary table for index $index doesn't exist,"
64  . " which is inconsistent with state of scope resolver"
65  )
66  );
67  }
68 
69  $this->state->useRegularIndex();
70  $tableName = $this->resolver->resolve($index, $dimensions);
71  if ($this->resource->getConnection()->isTableExists($tableName)) {
72  $this->resource->getConnection()->dropTable($tableName);
73  }
74 
75  $this->resource->getConnection()->renameTable($temporalIndexTable, $tableName);
76  $this->state->useTemporaryIndex();
77  }
78  }
79 }
$tableName
Definition: trigger.php:13
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
__construct(ResourceConnection $resource, IndexScopeResolverInterface $indexScopeResolver, State $state)
$index
Definition: list.phtml:44