Skip to content

Commit cf09bcc

Browse files
authored
Merge pull request #75 from webfactory/109924_disable-keys
Disable keys before inserting data (Case 109924)
2 parents 06abeb1 + 4b35298 commit cf09bcc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Webfactory/Slimdump/Database/Dumper.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ public function dumpData($table, Table $tableConfig, Connection $db, bool $noPro
160160
$s .= $tableConfig->getCondition();
161161

162162
$this->output->writeln("-- BEGIN DATA $table", OutputInterface::OUTPUT_RAW);
163-
$this->output->writeln("LOCK TABLES `$table` WRITE;", OutputInterface::OUTPUT_RAW);
163+
$this->writeDataDumpBegin($table);
164164

165165
$bufferSize = 0;
166166
$max = $this->bufferSize;
167167
$numRows = (int)$db->fetchColumn("SELECT COUNT(*) FROM `$table`".$tableConfig->getCondition());
168168

169169
if (0 === $numRows) {
170170
// Fail fast: No data to dump.
171-
$this->writeDataDumpEnd();
171+
$this->writeDataDumpEnd($table);
172172
return;
173173
}
174174

@@ -240,7 +240,7 @@ public function dumpData($table, Table $tableConfig, Connection $db, bool $noPro
240240
$this->output->writeln(';', OutputInterface::OUTPUT_RAW);
241241
}
242242

243-
$this->writeDataDumpEnd();
243+
$this->writeDataDumpEnd($table);
244244
}
245245

246246
/**
@@ -304,8 +304,15 @@ private function keepalive(Connection $db)
304304
}
305305
}
306306

307-
protected function writeDataDumpEnd(): void
307+
protected function writeDataDumpBegin($table): void
308+
{
309+
$this->output->writeln("LOCK TABLES `$table` WRITE;", OutputInterface::OUTPUT_RAW);
310+
$this->output->writeln("ALTER TABLE `$table` DISABLE KEYS;", OutputInterface::OUTPUT_RAW);
311+
}
312+
313+
protected function writeDataDumpEnd($table): void
308314
{
315+
$this->output->writeln("ALTER TABLE `$table` ENABLE KEYS;", OutputInterface::OUTPUT_RAW);
309316
$this->output->writeln("UNLOCK TABLES;", OutputInterface::OUTPUT_RAW);
310317
$this->output->writeln('', OutputInterface::OUTPUT_RAW);
311318
}

0 commit comments

Comments
 (0)