Commit 60e80843 authored by Duro Arezina's avatar Duro Arezina Committed by Duro Arezina
Browse files

Issue #3256573 by devad: Fatal error: The website encountered an unexpected...

Issue #3256573 by devad: Fatal error: The website encountered an unexpected error. Please try again later
parent b0341f85
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
ludwig.packages:
  route_name: ludwig.packages
  base_route: ludwig.packages
  title: 'List'
  title: 'Packages list'
ludwig.packages_skip:
  route_name: ludwig.packages_skip
  base_route: ludwig.packages
  title: 'Packages list (skip download)'
+7 −0
Original line number Diff line number Diff line
@@ -5,3 +5,10 @@ ludwig.packages:
    _title: 'Packages'
  requirements:
    _permission: 'access site reports'
ludwig.packages_skip:
  path: '/admin/reports/packages_skip'
  defaults:
    _controller: '\Drupal\ludwig\Controller\PackageController::page'
    _title: 'Packages (skip download)'
  requirements:
    _permission: 'access site reports'
+14 −25
Original line number Diff line number Diff line
@@ -11,9 +11,8 @@ use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Url;
use Drupal\Core\FileTransfer\FileTransferException;
use Drupal\Core\Path\CurrentPathStack;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * Displays the Packages report.
@@ -44,11 +43,11 @@ class PackageController implements ContainerInjectionInterface {
  protected $moduleExtensionList;

  /**
   * The RequestStack object.
   * The current path stack.
   *
   * @var Symfony\Component\HttpFoundation\RequestStack
   * @var \Drupal\Core\Path\CurrentPathStack
   */
  private $requestStack;
  protected $currentPathStack;

  /**
   * Constructs a new PackageController object.
@@ -61,15 +60,15 @@ class PackageController implements ContainerInjectionInterface {
   *   The string translation service.
   * @param \Drupal\Core\Extension\ModuleExtensionList $module_extension_list
   *   The module extension list.
   * @param Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The RequestStack object.
   * @param \Drupal\Core\Path\CurrentPathStack $currentPathStack
   *   The current path stack.
   */
  public function __construct(PackageManagerInterface $package_manager, PackageDownloaderInterface $package_downloader, TranslationInterface $string_translation, ModuleExtensionList $module_extension_list, RequestStack $request_stack) {
  public function __construct(PackageManagerInterface $package_manager, PackageDownloaderInterface $package_downloader, TranslationInterface $string_translation, ModuleExtensionList $module_extension_list, CurrentPathStack $currentPathStack) {
    $this->packageManager = $package_manager;
    $this->packageDownloader = $package_downloader;
    $this->setStringTranslation($string_translation);
    $this->moduleExtensionList = $module_extension_list;
    $this->requestStack = $request_stack;
    $this->currentPathStack = $currentPathStack;
  }

  /**
@@ -81,7 +80,7 @@ class PackageController implements ContainerInjectionInterface {
      $container->get('ludwig.package_downloader'),
      $container->get('string_translation'),
      $container->get('extension.list.module'),
      $container->get('request_stack')
      $container->get('path.current'),
    );
  }

@@ -93,9 +92,10 @@ class PackageController implements ContainerInjectionInterface {
   */
  public function page() {
    // If requested, download the missing packages first.
    if ($this->requestStack->getCurrentRequest()->query->get('missing') == 'download') {
    $current_path = $this->currentPathStack->getPath();
    $skip_path = Url::fromRoute('ludwig.packages_skip')->toString();
    if ($current_path != $skip_path) {
      $this->download();
      return new RedirectResponse(Url::fromRoute('ludwig.packages')->toString());
    }
    $info = $this->moduleExtensionList->getAllInstalledInfo();
    $build = [];
@@ -233,19 +233,8 @@ class PackageController implements ContainerInjectionInterface {
      ];
    }

    if (!empty($missing)) {
      // There are some missing packages, so render the
      // "Download all missing packages" clickable button.
      $build['#markup'] = $this->t('<div class="button"><a href="@packages-url">Download and unpack all missing packages (@missing)</a></div><div>&nbsp;</div>', [
        '@packages-url' => Url::fromRoute('ludwig.packages')->toString() . '?missing=download',
        '@missing' => $missing,
      ]);
    }
    else {
      // There are no missing packages. For the UX consistency
      // purpose render the button again, but as disabled one.
      $build['#markup'] = $this->t('<div class="button is-disabled">Download and unpack missing packages (0)</div><div>&nbsp;</div>');
    }
    // Render the 'Download missing packages' action button.
    $build['#markup'] = '<div class="action-links"><div class="button button--small"><a href="' . Url::fromRoute('ludwig.packages')->toString() . '">' . $this->t('Download missing packages') . ' (' . $missing . ')</a></div></div>';

    return $build;
  }