qtools_profiler-8.x-1.x-dev/qtools_profiler.install
qtools_profiler.install
<?php
/**
* @file
* Install hooks.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*/
function qtools_profiler_schema() {
$schema['qtools_profiler_route'] = [
'description' => 'Table for route names.',
'fields' => [
'id' => [
'description' => 'The primary identifier for route.',
'type' => 'serial',
'not null' => TRUE,
],
'route' => [
'description' => 'Route name.',
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
],
],
'primary key' => ['id'],
];
$schema['qtools_profiler_request'] = [
'description' => 'Table for storing user requests.',
'fields' => [
'id' => [
'description' => 'The primary identifier for request.',
'type' => 'serial',
'not null' => TRUE,
],
'uid' => [
'description' => 'User identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'rid' => [
'description' => 'Request route.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
],
'timestamp' => [
'description' => 'Request timestamp.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'uri' => [
'description' => 'Uri.',
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
],
'method' => [
'description' => 'Request method.',
'type' => 'varchar',
'length' => 7,
'not null' => TRUE,
'default' => "GET",
],
],
'indexes' => [
'rid' => ['rid'],
'timestamp' => ['timestamp'],
],
// For information only;
// foreign keys are not created in the database.
'foreign keys' => [
'uid' => [
'table' => 'users',
'columns' => ['uid' => 'uid'],
],
],
'primary key' => ['id'],
];
$schema['qtools_profiler_response'] = [
'description' => 'Table for storing user requests.',
'fields' => [
'rid' => [
'description' => 'The primary identifier for request.',
'type' => 'int',
'not null' => TRUE,
],
'memory' => [
'description' => 'Peak memory.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'time' => [
'description' => 'Page execution time.',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
],
'db_time' => [
'description' => 'Database query time.',
'type' => 'float',
'size' => 'big',
'not null' => FALSE,
],
'code' => [
'description' => 'Response code.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'report' => [
'type' => 'varchar',
'length' => 20,
'description' => 'Profile report type. Empty if no report.',
'default' => '',
],
],
'indexes' => [
'code' => ['code'],
],
'primary key' => ['rid'],
];
return $schema;
}
/**
* Implements hook_update_N().
*/
function qtools_profiler_update_8001(&$sandbox) {
$spec = [
'type' => 'int',
'description' => 'Has profiler report',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
];
$schema = Database::getConnection()->schema();
$schema->addField('qtools_profiler_response', 'report', $spec);
}
/**
* Implements hook_update_N().
*/
function qtools_profiler_update_8002(&$sandbox) {
$spec = [
'description' => 'Request method',
'type' => 'varchar',
'length' => 7,
'not null' => TRUE,
'default' => "GET",
];
$schema = Database::getConnection()->schema();
$schema->addField('qtools_profiler_request', 'method', $spec);
}
/**
* Implements hook_update_N().
*/
function qtools_profiler_update_8003(&$sandbox) {
// Update field.
$spec = [
'type' => 'varchar',
'length' => 20,
'description' => 'Profile report type. Empty if no report.',
'not null' => TRUE,
'default' => '',
];
$schema = Database::getConnection()->schema();
$schema->dropField('qtools_profiler_response', 'report');
$schema->addField('qtools_profiler_response', 'report', $spec);
// Set default field value.
$profiler = \Drupal::service('qtools_profiler.performance')->confGet('profiling')['extension'];
Database::getConnection()->update('qtools_profiler_response')
->fields(['report' => $profiler])
->execute();
}
/**
* Implements hook_update_N().
*/
function qtools_profiler_update_8004(&$sandbox) {
$spec = [
'description' => 'Database query time.',
'type' => 'float',
'size' => 'big',
'not null' => FALSE,
];
$schema = Database::getConnection()->schema();
$schema->addField('qtools_profiler_response', 'db_time', $spec);
}
