You are here

public function WebformCommandsBase::drush_tarball_extract in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Commands/WebformCommandsBase.php \Drupal\webform\Commands\WebformCommandsBase::drush_tarball_extract()

File

src/Commands/WebformCommandsBase.php, line 115

Class

WebformCommandsBase
Base class for Webform commands for Drush 9.x.

Namespace

Drupal\webform\Commands

Code

public function drush_tarball_extract($path, $destination = FALSE) {
  $this
    ->drush_mkdir($destination);
  $cwd = getcwd();
  if (preg_match('/\\.tgz$/', $path)) {
    drush_op('chdir', dirname($path));
    $process = Drush::process([
      'tar',
      '-xvzf',
      $path,
      '-C',
      $destination,
    ]);
    $process
      ->run();
    $return = $process
      ->isSuccessful();
    drush_op('chdir', $cwd);
    if (!$return) {
      throw new \Exception(dt('Unable to extract !filename.' . PHP_EOL . implode(PHP_EOL, $process
        ->getOutput()), [
        '!filename' => $path,
      ]));
    }
  }
  else {
    drush_op('chdir', dirname($path));
    $process = Drush::process([
      'unzip',
      $path,
      '-d',
      $destination,
    ]);
    $process
      ->run();
    $return = $process
      ->isSuccessful();
    drush_op('chdir', $cwd);
    if (!$return) {
      throw new \Exception(dt('Unable to extract !filename.' . PHP_EOL . implode(PHP_EOL, $process
        ->getOutput()), [
        '!filename' => $path,
      ]));
    }
  }
  return $return;
}