dblog.install
Same filename and directory in other branches
Install, update and uninstall functions for the dblog module.
File
-
core/
modules/ dblog/ dblog.install
View source
<?php
/**
* @file
* Install, update and uninstall functions for the dblog module.
*/
use Drupal\Core\Database\SchemaDefinition\Column;
use Drupal\Core\Database\SchemaDefinition\ColumnSize;
use Drupal\Core\Database\SchemaDefinition\Index;
use Drupal\Core\Database\SchemaDefinition\IntValue;
use Drupal\Core\Database\SchemaDefinition\PrimaryKey;
use Drupal\Core\Database\SchemaDefinition\Schema;
use Drupal\Core\Database\SchemaDefinition\SchemaDefinitionType;
use Drupal\Core\Database\SchemaDefinition\StringValue;
use Drupal\Core\Database\SchemaDefinition\Table;
/**
* Implements hook_schema().
*/
function dblog_schema() : Schema {
$tables[] = new Table(name: 'watchdog', description: 'Table that contains logs of all system events.', columns: [
Column::serial(name: 'wid', description: 'Primary Key: Unique watchdog event ID.', size: ColumnSize::Big),
Column::int(name: 'uid', description: 'The {users}.uid of the user who triggered the event.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::varcharAscii(name: 'type', description: 'Type of log message, for example "user" or "page not found."', length: 64, notNull: TRUE, default: new StringValue('')),
Column::text(name: 'message', description: 'Text of log message to be passed into the t() function.', size: ColumnSize::Big, notNull: TRUE),
Column::blob(name: 'variables', description: 'Serialized array of variables that match the message string and that is passed into the t() function.', size: ColumnSize::Big, notNull: TRUE),
Column::int(name: 'severity', description: 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)', size: ColumnSize::Tiny, unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
Column::text(name: 'link', description: 'Link to view the result of the event.', notNull: FALSE),
Column::text(name: 'location', description: 'URL of the origin of the event.', notNull: TRUE),
Column::text(name: 'referer', description: 'URL of referring page.', notNull: FALSE),
Column::varcharAscii(name: 'hostname', description: 'Hostname of the user who triggered the event.', length: 128, notNull: TRUE, default: new StringValue('')),
Column::int(name: 'timestamp', description: 'Unix timestamp of when event occurred.', size: ColumnSize::Big, notNull: TRUE, default: new IntValue(0)),
], primaryKey: new PrimaryKey([
'wid',
]), indexes: [
new Index(name: 'type', columns: [
'type',
]),
new Index(name: 'uid', columns: [
'uid',
]),
new Index(name: 'severity', columns: [
'severity',
]),
]);
return new Schema(type: SchemaDefinitionType::Module, name: 'dblog', tables: $tables);
}
/**
* Implements hook_update_last_removed().
*/
function dblog_update_last_removed() : int {
return 10101;
}
/**
* Change the 'wid' of the 'watchdog' table to an unsigned big integer.
*/
function dblog_update_12100() : void {
$connection = \Drupal::database();
// Remove the - extreme case - rows that have a negative WID.
$connection->delete('watchdog')
->condition('wid', 0, '<')
->execute();
$connection->schema()
->changeField('watchdog', 'wid', 'wid', [
'size' => 'big',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique watchdog event ID.',
]);
}
Functions
| Title | Deprecated | Summary |
|---|---|---|
| dblog_schema | Implements hook_schema(). | |
| dblog_update_12100 | Change the 'wid' of the 'watchdog' table to an unsigned big integer. | |
| dblog_update_last_removed | Implements hook_update_last_removed(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.