You are here

public function SqlRedirectNotFoundStorage::logRequest in Redirect 8

Merges a 404 request log in the database.

Parameters

string $path: The path of the current request.

string $langcode: The ID of the language code.

Overrides RedirectNotFoundStorageInterface::logRequest

File

modules/redirect_404/src/SqlRedirectNotFoundStorage.php, line 53

Class

SqlRedirectNotFoundStorage
Provides an SQL implementation for redirect not found storage.

Namespace

Drupal\redirect_404

Code

public function logRequest($path, $langcode) {
  if (mb_strlen($path) > static::MAX_PATH_LENGTH) {

    // Don't attempt to log paths that would result in an exception. There is
    // no point in logging truncated paths, as they cannot be used to build a
    // new redirect.
    return;
  }

  // Ignore invalid UTF-8, which can't be logged.
  if (!Unicode::validateUtf8($path)) {
    return;
  }

  // If the request is not new, update its count and timestamp.
  $this->database
    ->merge('redirect_404')
    ->key('path', $path)
    ->key('langcode', $langcode)
    ->expression('count', 'count + 1')
    ->expression('daily_count', 'daily_count + 1')
    ->fields([
    'timestamp' => \Drupal::time()
      ->getRequestTime(),
    'count' => 1,
    'daily_count' => 1,
    'resolved' => 0,
  ])
    ->execute();
}