function CronHook::__invoke

Same name in this branch
  1. main core/modules/file/src/Hook/CronHook.php \Drupal\file\Hook\CronHook::__invoke()
Same name and namespace in other branches
  1. 11.x core/modules/file/src/Hook/CronHook.php \Drupal\file\Hook\CronHook::__invoke()
  2. 11.x core/modules/package_manager/src/Hook/CronHook.php \Drupal\package_manager\Hook\CronHook::__invoke()

Implements hook_cron().

File

core/modules/package_manager/src/Hook/CronHook.php, line 53

Class

CronHook
Implements hook_cron().

Namespace

Drupal\package_manager\Hook

Code

public function __invoke() : void {
  $sandbox_manager = new class ($this->pathLocator, $this->beginner, $this->stager, $this->committer, $this->queueFactory, $this->eventDispatcher, $this->sharedTempStoreFactory, $this->time, $this->pathFactory, $this->failureMarker) 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();
  $max_sandbox_age = $this->time
    ->getCurrentTime() - Settings::get('package_manager_max_sandbox_age', 14) * 24 * 60 * 60;
  $last_create_event = $this->state
    ->get(LongLivedSandboxSubscriber::STATE_KEY);
  // Only delete the sandbox directory if it is older than the max configured
  // age `package_manager_max_sandbox_age` setting, or defaults to 14 days.
  if (file_exists($sandbox_dir) && $last_create_event) {
    if ($last_create_event < $max_sandbox_age && $is_available) {
      $this->fileSystem
        ->deleteRecursive($sandbox_dir, function (string $path) : void {
        $this->fileSystem
          ->chmod($path, is_dir($path) ? 0700 : 0600);
      });
      $this->state
        ->delete(LongLivedSandboxSubscriber::STATE_KEY);
    }
  }
}

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