VersionPress\Cli\VPCommandUtils::exec PHP Method

exec() public static method

Executes a command, optionally in a specified working directory.
public static exec ( string $command, string | null $cwd = null ) : Process
$command string
$cwd string | null
return VersionPress\Utils\Process
    public static function exec($command, $cwd = null)
    {
        // Changing env variables for debugging
        // If we run another wp-cli command from our command, it breaks and never continues (with xdebug).
        // So we need to turn xdebug off for all "nested" commands.
        if (isset($_SERVER["XDEBUG_CONFIG"])) {
            $env = $_SERVER;
            unset($env["XDEBUG_CONFIG"]);
        } else {
            $env = null;
        }
        $process = new Process($command, $cwd, $env);
        $process->run();
        return $process;
    }

Usage Example

Beispiel #1
1
 /**
  * Finishes `vp push`
  *
  * @subcommand finish-push
  *
  */
 public function finishPush($args, $assoc_args)
 {
     global $versionPressContainer;
     // Update working copy
     $resetCommand = "git reset --hard";
     $process = VPCommandUtils::exec($resetCommand);
     if (!$process->isSuccessful()) {
         WP_CLI::error("Working directory couldn't be reset");
     }
     // Run synchronization
     /** @var SynchronizationProcess $syncProcess */
     $syncProcess = $versionPressContainer->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS);
     $syncProcess->synchronizeAll();
     vp_flush_regenerable_options();
     vp_disable_maintenance();
     $this->flushRewriteRules();
     vp_enable_maintenance();
 }
All Usage Examples Of VersionPress\Cli\VPCommandUtils::exec