dcat-8.x-1.x-dev/dcat_import/dcat_import.module
dcat_import/dcat_import.module
<?php
/**
* @file
* Contains dcat_import.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function dcat_import_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the dcat_import module.
case 'help.page.dcat_import':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Import DCAT feeds.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_cron().
*
* Controls the size of the log table.
*/
function dcat_import_cron() {
$row_limit = 10000;
if (\Drupal::service('module_handler')->moduleExists('dblog')) {
$row_limit = \Drupal::config('dblog.settings')->get('row_limit');
}
// For row limit n, get the wid of the nth row in descending id order.
// Counting the most recent n rows avoids issues with wid number sequences,
// e.g. auto_increment value > 1 or rows deleted directly from the table.
if ($row_limit > 0) {
$db = \Drupal::database();
$min_row = $db->select('dcat_import_log', 'l')
->fields('l', ['id'])
->orderBy('id', 'DESC')
->range($row_limit - 1, 1)
->execute()->fetchField();
// Delete all table entries older than the nth row, if nth row was found.
if ($min_row) {
$db->delete('dcat_import_log')
->condition('id', $min_row, '<')
->execute();
}
}
}
