You are here

public function ChosenLibCommands::drush_tarball_extract in Chosen 3.0.x

Same name and namespace in other branches
  1. 8.2 modules/chosen_lib/src/Commands/ChosenLibCommands.php \Drupal\chosen_lib\Commands\ChosenLibCommands::drush_tarball_extract()

Parameters

string $path: The filename or directory.

bool $destination: The destination path.

Return value

mixed

Throws

\Exception

1 call to ChosenLibCommands::drush_tarball_extract()
ChosenLibCommands::plugin in modules/chosen_lib/src/Commands/ChosenLibCommands.php
Download and install the Chosen plugin.

File

modules/chosen_lib/src/Commands/ChosenLibCommands.php, line 184

Class

ChosenLibCommands
A Drush commandfile.

Namespace

Drupal\chosen_lib\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;
}