47 private $resourceConnection;
52 private $statementFactory;
57 private $dbSchemaWriter;
62 private $statementAggregatorFactory;
67 private $dataSaviorsCollection;
72 private $dryRunLogger;
88 array $dataSaviorsCollection,
97 $this->sharding = $sharding;
99 $this->statementFactory = $statementFactory;
100 $this->dbSchemaWriter = $dbSchemaWriter;
101 $this->statementAggregatorFactory = $statementAggregatorFactory;
102 $this->dataSaviorsCollection = $dataSaviorsCollection;
103 $this->dryRunLogger = $dryRunLogger;
117 foreach ($this->operations as $operation) {
118 if ($operation->isOperationDestructive()) {
119 $operations[$operation->getOperationName()] = $operation->getOperationName();
132 private function startSetupForAllConnections()
134 foreach ($this->sharding->getResources() as
$resource) {
135 $this->resourceConnection->getConnection(
$resource)
137 $this->resourceConnection->getConnection(
$resource)
138 ->query(
'SET UNIQUE_CHECKS=0');
148 private function endSetupForAllConnections()
150 foreach ($this->sharding->getResources() as
$resource) {
151 $this->resourceConnection->getConnection(
$resource)
162 private function operationIsOppositeToDestructive(OperationInterface $operation)
164 return $operation instanceof AddColumn ||
165 $operation instanceof CreateTable ||
166 $operation instanceof ReCreateTable;
180 public function execute(DiffInterface $diff, array
$requestData)
182 $this->startSetupForAllConnections();
183 $tableHistories = $diff->getAll();
188 $this->dryRunLogger->prepareToDryRun();
191 if (is_array($tableHistories)) {
192 foreach ($tableHistories as $tableHistory) {
193 $destructiveElements = [];
194 $oppositeToDestructiveElements = [];
195 $statementAggregator = $this->statementAggregatorFactory->create();
197 foreach ($this->operations as $operation) {
198 if (isset($tableHistory[$operation->getOperationName()])) {
200 foreach ($tableHistory[$operation->getOperationName()] as $elementHistory) {
201 $statementAggregator->addStatements($operation->doOperation($elementHistory));
203 if ($operation->isOperationDestructive()) {
204 $destructiveElements[] = $elementHistory->getOld();
205 }
elseif ($this->operationIsOppositeToDestructive($operation)) {
206 $oppositeToDestructiveElements[] = $elementHistory->getNew();
213 $this->dbSchemaWriter->compile($statementAggregator, $dryRun);
214 $this->doRestore($oppositeToDestructiveElements,
$requestData);
218 $this->endSetupForAllConnections();
227 private function doRestore(array $elements, array
$requestData)
236 foreach ($this->dataSaviorsCollection as $dataSavior) {
237 if ($dataSavior->isAcceptable(
$element)) {
252 private function doDump(array $elements, array
$requestData)
261 foreach ($this->dataSaviorsCollection as $dataSavior) {
262 if ($dataSavior->isAcceptable(
$element)) {
elseif(isset( $params[ 'redirect_parent']))
__construct(array $operations, array $dataSaviorsCollection, Sharding $sharding, ResourceConnection $resourceConnection, StatementFactory $statementFactory, DbSchemaWriterInterface $dbSchemaWriter, StatementAggregatorFactory $statementAggregatorFactory, DryRunLogger $dryRunLogger)
const INPUT_KEY_DRY_RUN_MODE
getDestructiveOperations()