|
8 | 8 | use Magento\Deploy\Console\Command\App\ConfigImportCommand;
|
9 | 9 | use Magento\Framework\App\DeploymentConfig;
|
10 | 10 | use Magento\Framework\App\ObjectManager;
|
11 |
| -use Magento\Framework\App\ResourceConnection; |
12 | 11 | use Magento\Framework\App\State as AppState;
|
13 | 12 | use Magento\Framework\Console\Cli;
|
14 | 13 | use Magento\Framework\Exception\RuntimeException;
|
15 |
| -use Magento\Framework\Mview\View\CollectionFactory as ViewCollectionFactory; |
16 |
| -use Magento\Framework\Mview\View\StateInterface; |
17 |
| -use Magento\Framework\Mview\View\SubscriptionFactory; |
18 |
| -use Magento\Framework\Mview\View\SubscriptionInterface; |
19 |
| -use Magento\Framework\Mview\ViewInterface; |
20 | 14 | use Magento\Framework\Setup\ConsoleLogger;
|
21 | 15 | use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
|
22 | 16 | use Magento\Framework\Setup\Declaration\Schema\OperationsExecutor;
|
@@ -60,48 +54,22 @@ class UpgradeCommand extends AbstractSetupCommand
|
60 | 54 | */
|
61 | 55 | private $searchConfigFactory;
|
62 | 56 |
|
63 |
| - /** |
64 |
| - * @var ViewCollectionFactory |
65 |
| - */ |
66 |
| - private $viewCollectionFactory; |
67 |
| - |
68 |
| - /** |
69 |
| - * @var SubscriptionFactory |
70 |
| - */ |
71 |
| - private $subscriptionFactory; |
72 |
| - |
73 |
| - /** |
74 |
| - * @var ResourceConnection |
75 |
| - */ |
76 |
| - private $resource; |
77 |
| - |
78 | 57 | /**
|
79 | 58 | * @param InstallerFactory $installerFactory
|
80 | 59 | * @param SearchConfigFactory $searchConfigFactory
|
81 | 60 | * @param DeploymentConfig $deploymentConfig
|
82 | 61 | * @param AppState|null $appState
|
83 |
| - * @param ViewCollectionFactory|null $viewCollectionFactory |
84 |
| - * @param SubscriptionFactory|null $subscriptionFactory |
85 |
| - * @param ResourceConnection|null $resource |
86 | 62 | */
|
87 | 63 | public function __construct(
|
88 | 64 | InstallerFactory $installerFactory,
|
89 | 65 | SearchConfigFactory $searchConfigFactory,
|
90 | 66 | DeploymentConfig $deploymentConfig = null,
|
91 |
| - AppState $appState = null, |
92 |
| - ViewCollectionFactory $viewCollectionFactory = null, |
93 |
| - SubscriptionFactory $subscriptionFactory = null, |
94 |
| - ResourceConnection $resource = null |
| 67 | + AppState $appState = null |
95 | 68 | ) {
|
96 | 69 | $this->installerFactory = $installerFactory;
|
97 | 70 | $this->searchConfigFactory = $searchConfigFactory;
|
98 | 71 | $this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
|
99 | 72 | $this->appState = $appState ?: ObjectManager::getInstance()->get(AppState::class);
|
100 |
| - $this->viewCollectionFactory = $viewCollectionFactory |
101 |
| - ?: ObjectManager::getInstance()->get(ViewCollectionFactory::class); |
102 |
| - $this->subscriptionFactory = $subscriptionFactory |
103 |
| - ?: ObjectManager::getInstance()->get(SubscriptionFactory::class); |
104 |
| - $this->resource = $resource ?: ObjectManager::getInstance()->get(ResourceConnection::class); |
105 | 73 | parent::__construct();
|
106 | 74 | }
|
107 | 75 |
|
@@ -164,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
|
164 | 132 | $installer->updateModulesSequence($keepGenerated);
|
165 | 133 | $searchConfig = $this->searchConfigFactory->create();
|
166 | 134 | $searchConfig->validateSearchEngine();
|
167 |
| - $this->removeUnusedTriggers(); |
| 135 | + $installer->removeUnusedTriggers(); |
168 | 136 | $installer->installSchema($request);
|
169 | 137 | $installer->installDataFixtures($request);
|
170 | 138 |
|
@@ -192,65 +160,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
|
192 | 160 |
|
193 | 161 | return Cli::RETURN_SUCCESS;
|
194 | 162 | }
|
195 |
| - |
196 |
| - /** |
197 |
| - * Remove unused triggers |
198 |
| - */ |
199 |
| - private function removeUnusedTriggers() |
200 |
| - { |
201 |
| - $viewCollection = $this->viewCollectionFactory->create(); |
202 |
| - $viewList = $viewCollection->getViewsByStateMode(StateInterface::MODE_ENABLED); |
203 |
| - |
204 |
| - // Unsubscribe mviews |
205 |
| - foreach ($viewList as $view) { |
206 |
| - /** @var ViewInterface $view */ |
207 |
| - $view->unsubscribe(); |
208 |
| - } |
209 |
| - |
210 |
| - // Remove extra triggers that have correct naming structure |
211 |
| - $triggers = $this->getTriggers(); |
212 |
| - foreach ($triggers as $trigger) { |
213 |
| - $this->initSubscriptionInstance($trigger['Table'])->remove(); |
214 |
| - } |
215 |
| - |
216 |
| - // Subscribe mviews |
217 |
| - foreach ($viewList as $view) { |
218 |
| - /** @var ViewInterface $view */ |
219 |
| - $view->subscribe(); |
220 |
| - } |
221 |
| - } |
222 |
| - |
223 |
| - /** |
224 |
| - * Retrieve triggers list |
225 |
| - * |
226 |
| - * @return array |
227 |
| - */ |
228 |
| - private function getTriggers(): array |
229 |
| - { |
230 |
| - $connection = $this->resource->getConnection(); |
231 |
| - $result = $connection->query('SHOW TRIGGERS'); |
232 |
| - return $result->fetchAll(); |
233 |
| - } |
234 |
| - |
235 |
| - /** |
236 |
| - * Initializes subscription instance |
237 |
| - * |
238 |
| - * @param string $tablename |
239 |
| - * @return SubscriptionInterface |
240 |
| - */ |
241 |
| - private function initSubscriptionInstance(string $tablename): SubscriptionInterface |
242 |
| - { |
243 |
| - /** @var ViewInterface $view */ |
244 |
| - $view = ObjectManager::getInstance()->create(ViewInterface::class); |
245 |
| - $view->setId('0'); |
246 |
| - |
247 |
| - return $this->subscriptionFactory->create( |
248 |
| - [ |
249 |
| - 'view' => $view, |
250 |
| - 'tableName' => $tablename, |
251 |
| - 'columnName' => '', |
252 |
| - 'subscriptionModel' => SubscriptionFactory::INSTANCE_NAME, |
253 |
| - ] |
254 |
| - ); |
255 |
| - } |
256 | 163 | }
|
0 commit comments