You are here

private function SpiController::getLastNodes in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::getLastNodes()
  2. 3.x src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::getLastNodes()

Get last 15 nodes created.

This can be useful to determine if you have some sort of spam on your site.

Return value

array Array of the details of last 15 nodes created.

1 call to SpiController::getLastNodes()
SpiController::get in src/Controller/SpiController.php
Gather site profile information about this site.

File

src/Controller/SpiController.php, line 413

Class

SpiController
SPI Controller class.

Namespace

Drupal\acquia_connector\Controller

Code

private function getLastNodes() {
  $last_five_nodes = [];
  if ($this
    ->moduleHandler()
    ->moduleExists('node')) {
    $result = Database::getConnection()
      ->select('node_field_data', 'n')
      ->fields('n', [
      'title',
      'type',
      'nid',
      'created',
      'langcode',
    ])
      ->condition('n.created', \Drupal::time()
      ->getRequestTime() - 3600, '>')
      ->orderBy('n.created', 'DESC')
      ->range(0, 15)
      ->execute();
    $count = 0;
    foreach ($result as $record) {
      $last_five_nodes[$count]['url'] = $this->pathAliasManager
        ->getAliasByPath('/node/' . $record->nid, $record->langcode);
      $last_five_nodes[$count]['title'] = $record->title;
      $last_five_nodes[$count]['type'] = $record->type;
      $last_five_nodes[$count]['created'] = $record->created;
      $count++;
    }
  }
  return $last_five_nodes;
}