You are here

protected function ShurlySubscriber::shurlyRedirectTo in ShURLy 8

1 call to ShurlySubscriber::shurlyRedirectTo()
ShurlySubscriber::shurlyOnRespond in src/ShurlySubscriber.php

File

src/ShurlySubscriber.php, line 49

Class

ShurlySubscriber

Namespace

Drupal\shurly

Code

protected function shurlyRedirectTo($row) {
  \Drupal::moduleHandler()
    ->invokeAll('shurly_redirect_before', [
    $row,
  ]);
  $url = $row->destination;
  $url = str_replace([
    "\n",
    "\r",
  ], '', $url);
  session_write_close();
  $response = new RedirectResponse($url);
  $response
    ->send();
  $request_time = \Drupal::time()
    ->getRequestTime();
  \Drupal::database()
    ->query('UPDATE {shurly} SET count = count + 1, last_used = :time WHERE rid = :rid', [
    'time' => $request_time,
    'rid' => $row->rid,
  ]);
  \Drupal::moduleHandler()
    ->invokeAll('shurly_redirect_after', [
    $row,
  ]);
  exit;
}