You are here

public function WebformCliService::drush_webform_composer_update in Webform 6.x

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

Implements drush_hook_COMMAND().

Overrides WebformCliServiceInterface::drush_webform_composer_update

File

src/Commands/WebformCliService.php, line 1107

Class

WebformCliService
Drush version agnostic commands.

Namespace

Drupal\webform\Commands

Code

public function drush_webform_composer_update() {
  $composer_json = $this->composer_json;
  $composer_directory = $this->composer_directory;
  $json = file_get_contents($composer_json);
  $data = json_decode($json, FALSE, $this
    ->drush_webform_composer_get_json_encode_options());
  if (!isset($data->repositories)) {
    $data->repositories = (object) [];
  }
  if (!isset($data->require)) {
    $data->repositories = (object) [];
  }

  // Add drupal-library to installer paths.
  if (strpos($json, 'type:drupal-library') === FALSE) {
    $library_path = $composer_directory . 'libraries/{$name}';
    $data->extra->{'installer-paths'}->{$library_path}[] = 'type:drupal-library';
  }

  // Get repositories and require.
  $repositories =& $data->repositories;
  $require =& $data->require;

  // Remove all existing _webform repositories.
  foreach ($repositories as $repository_name => $repository) {
    if (!empty($repository->_webform)) {
      $package_name = $repositories->{$repository_name}->package->name;
      unset($repositories->{$repository_name}, $require->{$package_name});
    }
  }

  // Set disable tls.
  $this
    ->drush_webform_composer_set_disable_tls($data);

  // Set libraries.
  $this
    ->drush_webform_composer_set_libraries($repositories, $require);
  file_put_contents($composer_json, json_encode($data, $this
    ->drush_webform_composer_get_json_encode_options()));
  $this
    ->drush_print("{$composer_json} updated.");
  $this
    ->drush_print('Make sure to run `composer update --lock`.');
}