From d391980b069709cbc838c0067e4a4198ae5ebe7a Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 17 May 2022 17:01:23 -0700 Subject: [PATCH] Do some better erroring if you can't launch the mysql binary --- app/Console/Commands/RestoreFromBackup.php | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) 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); + 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) { - $stdout = fgets($pipes[1]); - $this->info($stdout); - $stderr = fgets($pipes[2]); - $this->info($stderr); - return false; + 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) {