Skip to content

A free open source IT asset/license management system

Do some better erroring if you can't launch the mysql binary

Brady Wetheringtond391980b0697
diff --git a/app/Console/Commands/RestoreFromBackup.php b/app/Console/Commands/RestoreFromBackup.php
index e0f4eeab16..52d0209742 100644
--- a/app/Console/Commands/RestoreFromBackup.php
+++ b/app/Console/Commands/RestoreFromBackup.php
@@ -227,6 +227,9 @@ class RestoreFromBackup extends Command
return $this->error('Unable to invoke mysql via CLI');
}
+ stream_set_blocking($pipes[1], false); // use non-blocking reads for stdout
+ stream_set_blocking($pipes[2], false); // use non-blocking reads for stderr
+
// $this->info("Stdout says? ".fgets($pipes[1])); //FIXME: I think we might need to set non-blocking mode to use this properly?
// $this->info("Stderr says? ".fgets($pipes[2])); //FIXME: ditto, same.
// should we read stdout?
@@ -247,18 +250,25 @@ class RestoreFromBackup extends Command
}
$bytes_read = 0;
- while (($buffer = fgets($sql_contents, self::$buffer_size)) !== false) {
- $bytes_read += strlen($buffer);
- // \Log::debug("Buffer is: '$buffer'");
- $bytes_written = fwrite($pipes[0], $buffer);
-
- if ($bytes_written === false) {
- $stdout = fgets($pipes[1]);
- $this->info($stdout);
- $stderr = fgets($pipes[2]);
- $this->info($stderr);
- return false;
+ try {
+ while (($buffer = fgets($sql_contents, self::$buffer_size)) !== false) {
+ $bytes_read += strlen($buffer);
+ // \Log::debug("Buffer is: '$buffer'");
+ $bytes_written = fwrite($pipes[0], $buffer);
+
+ if ($bytes_written === false) {
+ throw new Exception("Unable to write to pipe");
+ }
}
+ } catch (\Exception $e) {
+ \Log::error("Error during restore!!!! ".$e->getMessage());
+ $err_out = fgets($pipes[1]);
+ $err_err = fgets($pipes[2]);
+ \Log::error("Error OUTPUT: ".$err_out);
+ $this->info($err_out);
+ \Log::error("Error ERROR : ".$err_err);
+ $this->error($err_err);
+ throw $e;
}
if (!feof($sql_contents) || $bytes_read == 0) {