You are here

private function ForwardForm::logEvent in Forward 8

Same name and namespace in other branches
  1. 8.3 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::logEvent()
  2. 8.2 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::logEvent()
  3. 4.x 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 268

Class

ForwardForm
Forward a page to a friend

Namespace

Drupal\forward\Form

Code

private 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(array(
    '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(array(
    'type' => $entity_type,
    'bundle' => $bundle,
    'id' => $entity_id,
  ))
    ->fields(array(
    'forward_count' => 1,
    'last_forward_timestamp' => $timestamp,
  ))
    ->expression('forward_count', 'forward_count + 1')
    ->execute();
}