You are here

public function PackageController::download in Ludwig 8

Downloads missing packages.

1 call to PackageController::download()
PackageController::page in src/Controller/PackageController.php
Shows the status of all required packages.

File

src/Controller/PackageController.php, line 223

Class

PackageController
Displays the Packages report.

Namespace

Drupal\ludwig\Controller

Code

public function download() {
  $packages = array_filter($this->packageManager
    ->getPackages(), function ($package) {
    return empty($package['installed']);
  });
  if (!empty($packages)) {
    $logger = \Drupal::logger('ludwig');
    $messenger = \Drupal::messenger();
    foreach ($packages as $name => $package) {
      try {
        $this->packageDownloader
          ->download($package);
        $logger
          ->info($this
          ->t('The @name package has been downloaded and unpacked successfully.', [
          '@name' => $name,
        ]));
        $messenger
          ->addMessage(t('The @name package has been downloaded and unpacked successfully.', [
          '@name' => $name,
        ]));
      } catch (FileTransferException $e) {
        $logger
          ->error($e
          ->getMessage());
        $messenger
          ->addMessage($e
          ->getMessage(), 'error');
        continue;
      } catch (\Exception $e) {
        $logger
          ->error($e
          ->getMessage());
        $messenger
          ->addMessage($e
          ->getMessage(), 'error');
        continue;
      }
    }
  }
}