function DiskSpaceValidator::validate

Validates that there is enough free disk space to do stage operations.

Parameters

\Drupal\package_manager\Event\SandboxValidationEvent $event: The event being handled.

Overrides BaseRequirementValidatorTrait::validate

File

core/modules/package_manager/src/Validator/DiskSpaceValidator.php, line 91

Class

DiskSpaceValidator
Validates that there is enough free disk space to do stage operations.

Namespace

Drupal\package_manager\Validator

Code

public function validate(SandboxValidationEvent $event) : void {
  $root_path = $this->pathLocator
    ->getProjectRoot();
  $vendor_path = $this->pathLocator
    ->getVendorDirectory();
  $messages = [];
  // @todo Make this configurable or set to a different value in
  //   https://www.drupal.org/i/3166416.
  $minimum_mb = 1024;
  $minimum_bytes = Bytes::toNumber($minimum_mb . 'M');
  if (!$this->areSameLogicalDisk($root_path, $vendor_path)) {
    if ($this->freeSpace($root_path) < $minimum_bytes) {
      $messages[] = $this->t('Drupal root filesystem "@root" has insufficient space. There must be at least @space megabytes free.', [
        '@root' => $root_path,
        '@space' => $minimum_mb,
      ]);
    }
    if (is_dir($vendor_path) && $this->freeSpace($vendor_path) < $minimum_bytes) {
      $messages[] = $this->t('Vendor filesystem "@vendor" has insufficient space. There must be at least @space megabytes free.', [
        '@vendor' => $vendor_path,
        '@space' => $minimum_mb,
      ]);
    }
  }
  elseif ($this->freeSpace($root_path) < $minimum_bytes) {
    $messages[] = $this->t('Drupal root filesystem "@root" has insufficient space. There must be at least @space megabytes free.', [
      '@root' => $root_path,
      '@space' => $minimum_mb,
    ]);
  }
  $temp = $this->temporaryDirectory();
  if ($this->freeSpace($temp) < $minimum_bytes) {
    $messages[] = $this->t('Directory "@temp" has insufficient space. There must be at least @space megabytes free.', [
      '@temp' => $temp,
      '@space' => $minimum_mb,
    ]);
  }
  if ($messages) {
    $summary = count($messages) > 1 ? $this->t("There is not enough disk space to create a stage directory.") : NULL;
    $event->addError($messages, $summary);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.