You are here

function _opigno_statistics_create_user_login_table in Opigno statistics 8

Creates user login table.

2 calls to _opigno_statistics_create_user_login_table()
opigno_statistics_install in ./opigno_statistics.install
Creates database table for tracking of the user login events.
opigno_statistics_update_8001 in ./opigno_statistics.install
Creates database table for tracking of the user login events.

File

./opigno_statistics.install, line 29
Install, update and uninstall functions for the Opigno Statistics module.

Code

function _opigno_statistics_create_user_login_table() {
  $schema = \Drupal::database()
    ->schema();
  $table_name = 'opigno_statistics_user_login';
  if (!$schema
    ->tableExists($table_name)) {
    $table = [
      'description' => 'Track user login events',
      'fields' => [
        'id' => [
          'type' => 'serial',
          'not null' => TRUE,
        ],
        'uid' => [
          'description' => 'User ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'date' => [
          'description' => 'Date of login',
          'type' => 'varchar',
          'length' => 20,
          'mysql_type' => 'datetime',
          'not null' => TRUE,
        ],
      ],
      'primary key' => [
        'id',
      ],
      'indexes' => [
        'uid' => [
          'uid',
        ],
      ],
      'foreign keys' => [
        'users' => [
          'uid' => 'uid',
        ],
      ],
    ];
    $schema
      ->createTable($table_name, $table);
  }
}