You are here

public function UserRestrictionsManager::deleteExpiredRules in User restrictions 8

Delete expired rules.

Return value

\Drupal\user_restrictions\UserRestrictionsManagerInterface The service for chaining.

Overrides UserRestrictionsManagerInterface::deleteExpiredRules

File

src/UserRestrictionsManager.php, line 103

Class

UserRestrictionsManager
Defines the user restriction manager.

Namespace

Drupal\user_restrictions

Code

public function deleteExpiredRules() {
  $rules = $this->entityStorage
    ->loadMultiple();

  /* @var $rule \Drupal\user_restrictions\Entity\UserRestrictions */
  foreach ($rules as $rule) {
    $expiry = $rule
      ->getExpiry();
    if ($expiry !== UserRestrictions::NO_EXPIRY && $expiry < \Drupal::time()
      ->getRequestTime()) {
      $rule
        ->delete();
      $this->logger
        ->notice('Expired rule %label has been deleted.', [
        '%label' => $rule
          ->label(),
      ]);
    }
  }
  return $this;
}