]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 May 2019 16:37:26 +0000 (18:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 May 2019 16:37:26 +0000 (18:37 +0200)
src/app/Console/Commands/MagicCubistCommand.php

index 9425997b121a057c39690bc857d8ddeb4e26560f..79394a28d0282a2dd21d51cff84e35e3fc8db168 100644 (file)
@@ -3,12 +3,14 @@
 
 namespace Cubist\Backpack\app\Console\Commands;
 
-use Backpack\Base\app\Console\Commands\Install;
 use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
 use Cubist\Util\Files\Files;
 use Cubist\Util\PHP;
+use Illuminate\Console\Command;
+use Symfony\Component\Process\Exception\ProcessFailedException;
+use Symfony\Component\Process\Process;
 
-class MagicCubistCommand extends Install
+class MagicCubistCommand extends Command
 {
     /**
      * The name and signature of the console command.
@@ -58,4 +60,54 @@ class MagicCubistCommand extends Install
             }
         }
     }
+
+    /**
+     * Run a SSH command.
+     *
+     * @param string $command      The SSH command that needs to be run
+     * @param bool   $beforeNotice Information for the user before the command is run
+     * @param bool   $afterNotice  Information for the user after the command is run
+     *
+     * @return mixed Command-line output
+     */
+    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
+    {
+        $this->echo('info', $beforeNotice ? ' '.$beforeNotice : $command);
+
+        $process = new Process($command, null, null, null, $this->option('timeout'), null);
+        $process->run(function ($type, $buffer) {
+            if (Process::ERR === $type) {
+                $this->echo('comment', $buffer);
+            } else {
+                $this->echo('line', $buffer);
+            }
+        });
+
+        // executes after the command finishes
+        if (!$process->isSuccessful()) {
+            throw new ProcessFailedException($process);
+        }
+
+        if ($afterNotice) {
+            $this->echo('info', $afterNotice);
+        }
+    }
+
+    /**
+     * Write text to the screen for the user to see.
+     *
+     * @param [string] $type    line, info, comment, question, error
+     * @param [string] $content
+     */
+    public function echo($type, $content)
+    {
+        if ($this->option('debug') == false) {
+            return;
+        }
+
+        // skip empty lines
+        if (trim($content)) {
+            $this->{$type}($content);
+        }
+    }
 }