function LongLivedSandboxSubscriber::onConfigSave
Same name and namespace in other branches
- 11.x core/modules/package_manager/src/EventSubscriber/LongLivedSandboxSubscriber.php \Drupal\package_manager\EventSubscriber\LongLivedSandboxSubscriber::onConfigSave()
Reacts when config is saved.
Parameters
\Drupal\Core\Config\ConfigCrudEvent $event: The event object.
File
-
core/
modules/ package_manager/ src/ EventSubscriber/ LongLivedSandboxSubscriber.php, line 87
Class
- LongLivedSandboxSubscriber
- Maintains state for the long-lived sandbox directory.
Namespace
Drupal\package_manager\EventSubscriberCode
public function onConfigSave(ConfigCrudEvent $event) : void {
$config = $event->getConfig();
if ($config->getName() !== 'package_manager.settings' || !$event->isChanged('include_unknown_files_in_project_root')) {
return;
}
// Skip initial module install where the original value is NULL, no sandbox
// directory exists yet to clean up. Removing this guard will cause test
// failures (e.g., SymlinkValidatorTest) where the subscriber's side effects
// during module install are unexpected.
if ($config->getOriginal('include_unknown_files_in_project_root') === NULL) {
return;
}
// Ensure the sandbox directory is deleted when unknown files setting is
// changed to FALSE, as the rsync flags won't delete unknown files if they
// still exist in the source directory.
// @see \PhpTuf\ComposerStager\Internal\FileSyncer\Service\FileSyncer::buildCommand
if ($config->get('include_unknown_files_in_project_root') === FALSE) {
$sandbox_manager = new class ($this->container
->get(PathLocator::class), $this->container
->get(BeginnerInterface::class), $this->container
->get(StagerInterface::class), $this->container
->get(CommitterInterface::class), $this->container
->get(QueueFactory::class), $this->container
->get(EventDispatcherInterface::class), $this->container
->get(SharedTempStoreFactory::class), $this->container
->get(TimeInterface::class), $this->container
->get(PathFactoryInterface::class), $this->container
->get(FailureMarker::class)) extends SandboxManagerBase {
};
// In direct-write mode, getSandboxDirectory() returns the project root.
// There is no separate sandbox directory to delete.
if ($sandbox_manager->isDirectWrite()) {
return;
}
$is_available = $sandbox_manager->isAvailable();
$sandbox_dir = $sandbox_manager->getSandboxDirectory();
if (file_exists($sandbox_dir) && $is_available) {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = $this->container
->get(FileSystemInterface::class);
$file_system->deleteRecursive($sandbox_dir, function (string $path) use ($file_system) : void {
$file_system->chmod($path, is_dir($path) ? 0700 : 0600);
});
$this->container
->get(StateInterface::class)
->delete(static::STATE_KEY);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.