Skip to content

Commit b26a48c

Browse files
MC-32014: Remove google-shopping-ads module from core in 2.4.1
1 parent 4b0f7ed commit b26a48c

File tree

3 files changed

+72
-52
lines changed

3 files changed

+72
-52
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,14 +1127,6 @@ 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-
11381130
/**
11391131
* Generates case SQL fragment
11401132
*

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,19 +4038,6 @@ 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-
40544041
/**
40554042
* Returns auto increment field if exists
40564043
*

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

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\App\State as AppState;
13-
use Magento\Framework\DB\Ddl\Trigger;
13+
use Magento\Framework\Console\Cli;
14+
use Magento\Framework\Exception\RuntimeException;
1415
use Magento\Framework\Mview\View\CollectionFactory as ViewCollectionFactory;
1516
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;
1620
use Magento\Framework\Setup\ConsoleLogger;
1721
use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
1822
use Magento\Framework\Setup\Declaration\Schema\OperationsExecutor;
@@ -56,30 +60,48 @@ class UpgradeCommand extends AbstractSetupCommand
5660
*/
5761
private $searchConfigFactory;
5862

59-
/*
63+
/**
6064
* @var ViewCollectionFactory
6165
*/
6266
private $viewCollectionFactory;
6367

68+
/**
69+
* @var SubscriptionFactory
70+
*/
71+
private $subscriptionFactory;
72+
73+
/**
74+
* @var ResourceConnection
75+
*/
76+
private $resource;
77+
6478
/**
6579
* @param InstallerFactory $installerFactory
6680
* @param SearchConfigFactory $searchConfigFactory
6781
* @param DeploymentConfig $deploymentConfig
6882
* @param AppState|null $appState
6983
* @param ViewCollectionFactory|null $viewCollectionFactory
84+
* @param SubscriptionFactory|null $subscriptionFactory
85+
* @param ResourceConnection|null $resource
7086
*/
7187
public function __construct(
7288
InstallerFactory $installerFactory,
7389
SearchConfigFactory $searchConfigFactory,
7490
DeploymentConfig $deploymentConfig = null,
7591
AppState $appState = null,
76-
ViewCollectionFactory $viewCollectionFactory = null
92+
ViewCollectionFactory $viewCollectionFactory = null,
93+
SubscriptionFactory $subscriptionFactory = null,
94+
ResourceConnection $resource = null
7795
) {
7896
$this->installerFactory = $installerFactory;
7997
$this->searchConfigFactory = $searchConfigFactory;
8098
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
8199
$this->appState = $appState ?: ObjectManager::getInstance()->get(AppState::class);
82-
$this->viewCollectionFactory = $viewCollectionFactory ?: ObjectManager::getInstance()->get(ViewCollectionFactory::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);
83105
parent::__construct();
84106
}
85107

@@ -142,9 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
142164
$installer->updateModulesSequence($keepGenerated);
143165
$searchConfig = $this->searchConfigFactory->create();
144166
$searchConfig->validateSearchEngine();
145-
146167
$this->removeUnusedTriggers();
147-
148168
$installer->installSchema($request);
149169
$installer->installDataFixtures($request);
150170

@@ -153,8 +173,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
153173
$arrayInput = new ArrayInput([]);
154174
$arrayInput->setInteractive($input->isInteractive());
155175
$result = $importConfigCommand->run($arrayInput, $output);
156-
if ($result === \Magento\Framework\Console\Cli::RETURN_FAILURE) {
157-
throw new \Magento\Framework\Exception\RuntimeException(
176+
if ($result === Cli::RETURN_FAILURE) {
177+
throw new RuntimeException(
158178
__('%1 failed. See previous output.', ConfigImportCommand::COMMAND_NAME)
159179
);
160180
}
@@ -167,49 +187,70 @@ protected function execute(InputInterface $input, OutputInterface $output)
167187
}
168188
} catch (\Exception $e) {
169189
$output->writeln('<error>' . $e->getMessage() . '</error>');
170-
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
190+
return Cli::RETURN_FAILURE;
171191
}
172192

173-
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
193+
return Cli::RETURN_SUCCESS;
174194
}
175195

176196
/**
177197
* Remove unused triggers
178198
*/
179199
private function removeUnusedTriggers()
180200
{
181-
// unsubscribe mview
182201
$viewCollection = $this->viewCollectionFactory->create();
183202
$viewList = $viewCollection->getViewsByStateMode(StateInterface::MODE_ENABLED);
203+
204+
// Unsubscribe mviews
184205
foreach ($viewList as $view) {
185-
/** @var \Magento\Framework\Mview\ViewInterface $view */
206+
/** @var ViewInterface $view */
186207
$view->unsubscribe();
187208
}
188209

189-
// remove extra triggers that have correct naming structure
190-
/** @var ResourceConnection $resource */
191-
$resource = ObjectManager::getInstance()->get(ResourceConnection::class);
192-
$connection = $resource->getConnection();
193-
$triggers = $connection->getTriggers();
210+
// Remove extra triggers that have correct naming structure
211+
$triggers = $this->getTriggers();
194212
foreach ($triggers as $trigger) {
195-
$triggerNames = [];
196-
foreach (Trigger::getListOfEvents() as $event) {
197-
$triggerName = $resource->getTriggerName(
198-
$resource->getTableName($trigger['Table']),
199-
Trigger::TIME_AFTER,
200-
$event
201-
);
202-
$triggerNames[] = strtolower($triggerName);
203-
}
204-
if (in_array($trigger['Trigger'], $triggerNames)) {
205-
$connection->dropTrigger($trigger['Trigger']);
206-
}
213+
$this->initSubscriptionInstance($trigger['Table'])->remove();
207214
}
208215

209-
// subscribe mview
216+
// Subscribe mviews
210217
foreach ($viewList as $view) {
211-
/** @var \Magento\Framework\Mview\ViewInterface $view */
218+
/** @var ViewInterface $view */
212219
$view->subscribe();
213220
}
214221
}
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+
}
215256
}

0 commit comments

Comments
 (0)