You are here

protected function ForwardForm::logEvent in Forward 4.x

Same name and namespace in other branches
  1. 8.3 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::logEvent()
  2. 8 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::logEvent()
  3. 8.2 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::logEvent()
  4. 4.0.x src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::logEvent()

Logging.

1 call to ForwardForm::logEvent()
ForwardForm::submitForm in src/Form/ForwardForm.php
Form submission handler.

File

src/Form/ForwardForm.php, line 710

Class

ForwardForm
Forward a page to a friend.

Namespace

Drupal\forward\Form

Code

protected function logEvent(EntityInterface $entity) {
  $entity_type = $entity
    ->getEntityTypeId();
  $bundle = $entity
    ->bundle();
  $entity_id = $entity
    ->id();
  $uid = $this
    ->currentUser()
    ->id();
  $path = substr($entity
    ->toUrl()
    ->toString(), 1);
  $ip_address = $this->requestStack
    ->getCurrentRequest()
    ->getClientIp();
  $timestamp = REQUEST_TIME;

  // Insert into log.
  $this->database
    ->insert('forward_log')
    ->fields([
    'type' => $entity_type,
    'id' => $entity_id,
    'path' => $path,
    'action' => 'SENT',
    'timestamp' => $timestamp,
    'uid' => $uid,
    'hostname' => $ip_address,
  ])
    ->execute();

  // Update statistics.
  $this->database
    ->merge('forward_statistics')
    ->key([
    'type' => $entity_type,
    'bundle' => $bundle,
    'id' => $entity_id,
  ])
    ->fields([
    'forward_count' => 1,
    'last_forward_timestamp' => $timestamp,
  ])
    ->expression('forward_count', 'forward_count + 1')
    ->execute();
}