You are here

class DiskSpace in Automatic Updates 8

Disk space checker.

Hierarchy

Expanded class hierarchy of DiskSpace

1 file declares its use of DiskSpace
DiskSpaceTest.php in tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php
1 string reference to 'DiskSpace'
automatic_updates.services.yml in ./automatic_updates.services.yml
automatic_updates.services.yml
1 service uses DiskSpace
automatic_updates.disk_space_checker in ./automatic_updates.services.yml
Drupal\automatic_updates\ReadinessChecker\DiskSpace

File

src/ReadinessChecker/DiskSpace.php, line 10

Namespace

Drupal\automatic_updates\ReadinessChecker
View source
class DiskSpace extends Filesystem {

  /**
   * Minimum disk space (in bytes) is 10mb.
   */
  const MINIMUM_DISK_SPACE = 10000000;

  /**
   * Megabyte divisor.
   */
  const MEGABYTE_DIVISOR = 1000000;

  /**
   * {@inheritdoc}
   */
  protected function doCheck() {
    return $this
      ->diskSpaceCheck();
  }

  /**
   * Check if the filesystem has sufficient disk space.
   *
   * @return array
   *   An array of translatable strings if there is not sufficient space.
   */
  protected function diskSpaceCheck() {
    $messages = [];
    if (!$this
      ->areSameLogicalDisk($this
      ->getRootPath(), $this
      ->getVendorPath())) {
      if (disk_free_space($this
        ->getRootPath()) < static::MINIMUM_DISK_SPACE) {
        $messages[] = $this
          ->t('Drupal root filesystem "@root" has insufficient space. There must be at least @space megabytes free.', [
          '@root' => $this
            ->getRootPath(),
          '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR,
        ]);
      }
      if (is_dir($this
        ->getVendorPath()) && disk_free_space($this
        ->getVendorPath()) < static::MINIMUM_DISK_SPACE) {
        $messages[] = $this
          ->t('Vendor filesystem "@vendor" has insufficient space. There must be at least @space megabytes free.', [
          '@vendor' => $this
            ->getVendorPath(),
          '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR,
        ]);
      }
    }
    elseif (disk_free_space($this
      ->getRootPath()) < static::MINIMUM_DISK_SPACE) {
      $messages[] = $this
        ->t('Logical disk "@root" has insufficient space. There must be at least @space megabytes free.', [
        '@root' => $this
          ->getRootPath(),
        '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR,
      ]);
    }
    $temp = FileSystemComponent::getOsTemporaryDirectory();
    if (disk_free_space($temp) < static::MINIMUM_DISK_SPACE) {
      $messages[] = $this
        ->t('Directory "@temp" has insufficient space. There must be at least @space megabytes free.', [
        '@temp' => $temp,
        '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR,
      ]);
    }
    return $messages;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DiskSpace::diskSpaceCheck protected function Check if the filesystem has sufficient disk space.
DiskSpace::doCheck protected function Perform checks. Overrides Filesystem::doCheck
DiskSpace::MEGABYTE_DIVISOR constant Megabyte divisor.
DiskSpace::MINIMUM_DISK_SPACE constant Minimum disk space (in bytes) is 10mb. 1
Filesystem::$rootPath protected property The root file path.
Filesystem::$vendorPath protected property The vendor file path.
Filesystem::areSameLogicalDisk protected function Determine if the root and vendor file system are the same logical disk. 2
Filesystem::getRootPath protected function Get the root file path.
Filesystem::getVendorPath protected function Get the vendor file path.
Filesystem::run public function Run check. Overrides ReadinessCheckerInterface::run
Filesystem::__construct public function Filesystem constructor. 1
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.