You are here

class Cleaner in Automatic Updates 8.2

Defines a cleaner service that makes the staged site directory writable.

Hierarchy

  • class \Drupal\automatic_updates\ComposerStager\Cleaner implements \PhpTuf\ComposerStager\Domain\CleanerInterface

Expanded class hierarchy of Cleaner

1 file declares its use of Cleaner
FileSystemOperationsTest.php in tests/src/Functional/FileSystemOperationsTest.php
1 string reference to 'Cleaner'
automatic_updates.services.yml in ./automatic_updates.services.yml
automatic_updates.services.yml
1 service uses Cleaner
automatic_updates.cleaner in ./automatic_updates.services.yml
Drupal\automatic_updates\ComposerStager\Cleaner

File

src/ComposerStager/Cleaner.php, line 13

Namespace

Drupal\automatic_updates\ComposerStager
View source
class Cleaner implements CleanerInterface {

  /**
   * The decorated cleaner service.
   *
   * @var \PhpTuf\ComposerStager\Domain\CleanerInterface
   */
  protected $decorated;

  /**
   * The current site path, without leading or trailing slashes.
   *
   * @var string
   */
  protected $sitePath;

  /**
   * The path locator service.
   *
   * @var \Drupal\automatic_updates\PathLocator
   */
  protected $pathLocator;

  /**
   * Constructs a Cleaner object.
   *
   * @param \PhpTuf\ComposerStager\Domain\CleanerInterface $decorated
   *   The decorated cleaner service.
   * @param string $site_path
   *   The current site path (e.g., 'sites/default'), without leading or
   *   trailing slashes.
   * @param \Drupal\automatic_updates\PathLocator $locator
   *   The path locator service.
   */
  public function __construct(CleanerInterface $decorated, string $site_path, PathLocator $locator) {
    $this->decorated = $decorated;
    $this->sitePath = $site_path;
    $this->pathLocator = $locator;
  }

  /**
   * {@inheritdoc}
   */
  public function clean(string $stagingDir, ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120) : void {

    // Ensure that the staged site directory is writable so we can delete it.
    $site_dir = implode(DIRECTORY_SEPARATOR, [
      $stagingDir,
      $this->pathLocator
        ->getWebRoot() ?: '.',
      $this->sitePath,
    ]);
    if ($this
      ->directoryExists($site_dir)) {
      (new Filesystem())
        ->chmod($site_dir, 0777);
    }
    $this->decorated
      ->clean($stagingDir, $callback, $timeout);
  }

  /**
   * {@inheritdoc}
   */
  public function directoryExists(string $stagingDir) : bool {
    return $this->decorated
      ->directoryExists($stagingDir);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Cleaner::$decorated protected property The decorated cleaner service.
Cleaner::$pathLocator protected property The path locator service.
Cleaner::$sitePath protected property The current site path, without leading or trailing slashes.
Cleaner::clean public function
Cleaner::directoryExists public function
Cleaner::__construct public function Constructs a Cleaner object.