'-h', $this->host,
'-P', $this->port,
'-u', $this->user,
+ '--protocol=TCP',
$this->database,
'-e', "show tables;"
]);
'-h', $this->host,
'-P', $this->port,
'-u', $this->user,
+ '--protocol=TCP',
$this->database,
'-e', "source {$sqlFilePath}"
]);
HEREDOC;
}
- public function runDumpToFile(string $filePath): void
+ public function runDumpToFile(string $filePath): string
{
$file = fopen($filePath, 'w');
$errors = "";
+ $warnings = "";
$hasOutput = false;
try {
'-h', $this->host,
'-P', $this->port,
'-u', $this->user,
+ '--protocol=TCP',
'--single-transaction',
'--no-tablespaces',
$this->database,
], function ($data) use (&$file, &$hasOutput) {
fwrite($file, $data);
$hasOutput = true;
- }, function ($error) use (&$errors) {
- $errors .= $error . "\n";
+ }, function ($error) use (&$errors, &$warnings) {
+ $lines = explode("\n", $error);
+ foreach ($lines as $line) {
+ if (str_starts_with(strtolower($line), 'warning: ')) {
+ $warnings .= $line;
+ } else {
+ $errors .= $line . "\n";
+ }
+ }
});
} catch (\Exception $exception) {
fclose($file);
if ($errors) {
throw new Exception("Failed mysqldump with errors:\n" . $errors);
}
+
+ return $warnings;
}
public static function fromEnvOptions(array $env): static