You are here

function webform_update_8032 in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.install.update.inc \webform_update_8032()

Issue #2854020: Provide a mechanism to log submission transactions.

File

includes/webform.install.update.inc, line 653
Archived Webform update hooks.

Code

function webform_update_8032() {
  _webform_update_webform_submission_storage_schema();
  if (!\Drupal::database()
    ->schema()
    ->tableExists('webform_submission_log')) {

    // Copied from:
    // \Drupal\webform\WebformSubmissionStorageSchema::getEntitySchema.
    $schema = [
      'description' => 'Table that contains logs of all webform submission events.',
      'fields' => [
        'lid' => [
          'type' => 'serial',
          'not null' => TRUE,
          'description' => 'Primary Key: Unique log event ID.',
        ],
        'webform_id' => [
          'description' => 'The webform id.',
          'type' => 'varchar',
          'length' => 32,
          'not null' => TRUE,
        ],
        'sid' => [
          'description' => 'The webform submission id.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
        ],
        'handler_id' => [
          'description' => 'The webform handler id.',
          'type' => 'varchar',
          'length' => 64,
          'not null' => FALSE,
        ],
        'uid' => [
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
          'description' => 'The {users}.uid of the user who triggered the event.',
        ],
        'operation' => [
          'type' => 'varchar_ascii',
          'length' => 64,
          'not null' => TRUE,
          'default' => '',
          'description' => 'Type of operation, for example "save", "sent", or "update."',
        ],
        'message' => [
          'type' => 'text',
          'not null' => TRUE,
          'size' => 'big',
          'description' => 'Text of log message.',
        ],
        'data' => [
          'type' => 'blob',
          'not null' => TRUE,
          'size' => 'big',
          'description' => 'Serialized array of data.',
        ],
        'timestamp' => [
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
          'description' => 'Unix timestamp of when event occurred.',
        ],
      ],
      'primary key' => [
        'lid',
      ],
      'indexes' => [
        'webform_id' => [
          'webform_id',
        ],
        'sid' => [
          'sid',
        ],
        'uid' => [
          'uid',
        ],
        'handler_id' => [
          'handler_id',
        ],
        'handler_id_operation' => [
          'handler_id',
          'operation',
        ],
      ],
    ];
    \Drupal::database()
      ->schema()
      ->createTable('webform_submission_log', $schema);
  }
}