Skip to content
Snippets Groups Projects

Issue #3364958: Stages should be destroyed in the background, during cron runs

Merged Issue #3364958: Stages should be destroyed in the background, during cron runs
1 unresolved thread
1 unresolved thread
3 files
+ 50
16
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 41
0
<?php
declare(strict_types = 1);
namespace Drupal\package_manager;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class Cleaner implements ContainerInjectionInterface {
private const STATE_KEY = 'package_manager_clean';
public function __construct(
private readonly StateInterface $state,
private readonly FileSystemInterface $fileSystem,
) {}
public static function create(ContainerInterface $container) {
return new static(
$container->get(StateInterface::class),
$container->get(FileSystemInterface::class),
);
}
public static function addDirectory(string $dir): void {
\Drupal::state()->set(static::STATE_KEY, $dir);
}
public function hookCron(): void {
$staging_root = $this->state->get(static::STATE_KEY);
if ($staging_root && file_exists($staging_root)) {
$this->fileSystem->deleteRecursive($staging_root, function (string $path): void {
$this->fileSystem->chmod($path, 0777);
});
}
}
}
Loading