Skip to content

Commit f1f9ce7

Browse files
MC-32014: Remove google-shopping-ads module from core in 2.4.1
1 parent 735579d commit f1f9ce7

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface AdapterInterface
3636
const INSERT_ON_DUPLICATE = 1;
3737

3838
const INSERT_IGNORE = 2;
39-
39+
4040
/** Strategy for updating data in table. See https://dev.mysql.com/doc/refman/5.7/en/replace.html */
4141
const REPLACE = 4;
4242

@@ -1127,6 +1127,14 @@ public function dropTrigger($triggerName, $schemaName = null);
11271127
*/
11281128
public function getTables($likeCondition = null);
11291129

1130+
/**
1131+
* Retrieve triggers list
1132+
*
1133+
* @param null|string $likeCondition
1134+
* @return array
1135+
*/
1136+
public function getTriggers($likeCondition = null);
1137+
11301138
/**
11311139
* Generates case SQL fragment
11321140
*

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,6 +4038,19 @@ public function getTables($likeCondition = null)
40384038
return $tables;
40394039
}
40404040

4041+
/**
4042+
* Retrieve triggers list
4043+
*
4044+
* @param null|string $likeCondition
4045+
* @return array
4046+
*/
4047+
public function getTriggers($likeCondition = null)
4048+
{
4049+
$sql = ($likeCondition === null) ? 'SHOW TRIGGERS' : sprintf("SHOW TRIGGERS LIKE '%s'", $likeCondition);
4050+
$result = $this->query($sql);
4051+
return $result->fetchAll();
4052+
}
4053+
40414054
/**
40424055
* Returns auto increment field if exists
40434056
*

setup/src/Magento/Setup/Console/Command/UpgradeCommand.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
namespace Magento\Setup\Console\Command;
77

88
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
9-
use Magento\Framework\App\State as AppState;
109
use Magento\Framework\App\DeploymentConfig;
1110
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\App\State as AppState;
13+
use Magento\Framework\DB\Ddl\Trigger;
14+
use Magento\Framework\Mview\View\CollectionInterface as ViewCollection;
15+
use Magento\Framework\Mview\View\StateInterface;
1216
use Magento\Framework\Setup\ConsoleLogger;
1317
use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
1418
use Magento\Framework\Setup\Declaration\Schema\OperationsExecutor;
@@ -52,22 +56,30 @@ class UpgradeCommand extends AbstractSetupCommand
5256
*/
5357
private $searchConfigFactory;
5458

59+
/*
60+
* @var ViewCollection
61+
*/
62+
private $viewCollection;
63+
5564
/**
5665
* @param InstallerFactory $installerFactory
5766
* @param SearchConfigFactory $searchConfigFactory
5867
* @param DeploymentConfig $deploymentConfig
5968
* @param AppState|null $appState
69+
* @param ViewCollection|null $viewCollection
6070
*/
6171
public function __construct(
6272
InstallerFactory $installerFactory,
6373
SearchConfigFactory $searchConfigFactory,
6474
DeploymentConfig $deploymentConfig = null,
65-
AppState $appState = null
75+
AppState $appState = null,
76+
ViewCollection $viewCollection = null
6677
) {
6778
$this->installerFactory = $installerFactory;
6879
$this->searchConfigFactory = $searchConfigFactory;
6980
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
7081
$this->appState = $appState ?: ObjectManager::getInstance()->get(AppState::class);
82+
$this->viewCollection = $viewCollection ?: ObjectManager::getInstance()->get(ViewCollection::class);
7183
parent::__construct();
7284
}
7385

@@ -130,6 +142,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
130142
$installer->updateModulesSequence($keepGenerated);
131143
$searchConfig = $this->searchConfigFactory->create();
132144
$searchConfig->validateSearchEngine();
145+
146+
$this->removeUnusedTriggers();
147+
133148
$installer->installSchema($request);
134149
$installer->installDataFixtures($request);
135150

@@ -157,4 +172,43 @@ protected function execute(InputInterface $input, OutputInterface $output)
157172

158173
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
159174
}
175+
176+
/**
177+
* Remove unused triggers
178+
*/
179+
private function removeUnusedTriggers()
180+
{
181+
// unsubscribe mview
182+
$viewList = $this->viewCollection->getViewsByStateMode(StateInterface::MODE_ENABLED);
183+
foreach ($viewList as $view) {
184+
/** @var \Magento\Framework\Mview\ViewInterface $view */
185+
$view->unsubscribe();
186+
}
187+
188+
// remove extra triggers that have correct naming structure
189+
/* @var ResourceConnection $resource */
190+
$resource = ObjectManager::getInstance()->get(ResourceConnection::class);
191+
$connection = $resource->getConnection();
192+
$triggers = $connection->getTriggers();
193+
foreach ($triggers as $trigger) {
194+
$triggerNames = [];
195+
foreach (Trigger::getListOfEvents() as $event) {
196+
$triggerName = $resource->getTriggerName(
197+
$resource->getTableName($trigger['Table']),
198+
Trigger::TIME_AFTER,
199+
$event
200+
);
201+
$triggerNames[] = strtolower($triggerName);
202+
}
203+
if (in_array($trigger['Trigger'], $triggerNames)) {
204+
$connection->dropTrigger($trigger['Trigger']);
205+
}
206+
}
207+
208+
// subscribe mview
209+
foreach ($viewList as $view) {
210+
/** @var \Magento\Framework\Mview\ViewInterface $view */
211+
$view->subscribe();
212+
}
213+
}
160214
}

0 commit comments

Comments
 (0)