hasPermission('excluded_from_login_tracking'); // Allow other modules to override whether or not we're tracking this // login. \Drupal::moduleHandler()->alter('login_tracker_track_login', $track_login, $account); if (!$track_login) { return; } $data = []; \Drupal::moduleHandler()->alter('login_tracker_login_data', $data, $account); $data = serialize($data); $fields = [ 'uid' => $account->id(), 'login_timestamp' => \Drupal::time()->getRequestTime(), 'data' => $data, ]; // Core 11 narrowed Merge::key() to a string field, so the historical // merge->key(['record_id' => NULL]) trick no longer works. A plain insert // is exactly what it did (the NULL key never matched, forcing an insert // per login). \Drupal::database()->insert('login_tracker') ->fields($fields) ->execute(); } /** * Implements hook_cron(). */ function login_tracker_cron() { $settings = \Drupal::state()->get('login_tracker_settings', []); if (!empty($settings['purge_interval'])) { $query = \Drupal::database()->delete('login_tracker'); $query->condition('login_timestamp', time() - $settings['purge_interval'], '<='); $results = $query->execute(); if ($results) { \Drupal::logger('login_tracker')->notice( t( '@logs records have been purged with success from table @table', ['@logs' => $results, '@table' => 'login_tracker'] ) ); } else { \Drupal::logger('login_tracker')->notice(t('Nothing to purge from table @table', ['@table' => 'login_tracker'])); } } }