Skip to content
Snippets Groups Projects

Issue #3231992: Make the staged sites/default writable before cleaning

Merged Issue #3231992: Make the staged sites/default writable before cleaning
1 unresolved thread
1 unresolved thread
Files
14
+ 75
0
<?php
namespace Drupal\automatic_updates\ComposerStager;
use Drupal\automatic_updates\Locator;
use PhpTuf\ComposerStager\Domain\CleanerInterface;
use PhpTuf\ComposerStager\Domain\Output\ProcessOutputCallbackInterface;
use Symfony\Component\Filesystem\Filesystem;
/**
* Defines a cleaner service that makes the staged site directory writable.
*/
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 locator service.
*
* @var \Drupal\automatic_updates\Locator
*/
protected $locator;
/**
* @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\Locator $locator
* The locator service.
*/
public function __construct(CleanerInterface $decorated, string $site_path, Locator $locator) {
$this->decorated = $decorated;
$this->sitePath = $site_path;
$this->locator = $locator;
}
/**
* {@inheritdoc}
*/
public function clean(string $stagingDir, ?ProcessOutputCallbackInterface $callback, ?int $timeout = 120): void {
// Ensure that the staged site path is writable.
$site_dir = implode(DIRECTORY_SEPARATOR, [
$stagingDir,
$this->locator->getProjectRoot() ?: '.',
$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);
}
}
Loading