Cleaner.php

Namespace

Drupal\package_manager\Plugin\QueueWorker

File

core/modules/package_manager/src/Plugin/QueueWorker/Cleaner.php

View source
<?php

namespace Drupal\package_manager\Plugin\QueueWorker;

use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Processes a queue of defunct stage directories, deleting them.
 *
 * @QueueWorker(
 *   id = "package_manager_cleanup",
 *   title = @Translation("Stage directory cleaner"),
 *   cron = {"time" = 30}
 * )
 */
final class Cleaner extends QueueWorkerBase implements ContainerFactoryPluginInterface {
    public function __construct(array $configuration, string $plugin_id, mixed $plugin_definition, FileSystemInterface $fileSystem) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static($configuration, $plugin_id, $plugin_definition, $container->get(FileSystemInterface::class));
    }
    
    /**
     * {@inheritdoc}
     */
    public function processItem($dir) : void {
        assert(is_string($dir));
        if (file_exists($dir)) {
            $this->fileSystem
                ->deleteRecursive($dir, function (string $path) : void {
                $this->fileSystem
                    ->chmod($path, is_dir($path) ? 0700 : 0600);
            });
        }
    }

}

Classes

Title Deprecated Summary
Cleaner Processes a queue of defunct stage directories, deleting them.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.