abjs.install in A/B Test JS 8
Same filename and directory in other branches
Install, update and uninstall functions for the abjs module.
Settings variables are initially set. All table schemas for the Test, Condition, and Experience data are defined in custom schemas. Two tables are used to store the Conditions and Experiences that are used in each Test.
File
abjs.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the abjs module.
*
* Settings variables are initially set. All table schemas for the Test,
* Condition, and Experience data are defined in custom schemas. Two tables are
* used to store the Conditions and Experiences that are used in each Test.
*/
use Drupal\Core\Url;
/**
* Implements hook_install().
*/
function abjs_install() {
$messenger = \Drupal::messenger();
$messenger
->addStatus(t('Module <em class="placeholder">A/B Test JS</em> has been enabled.'));
$messenger
->addStatus(t('Thanks for installing A/B Test JS'));
$messenger
->addStatus(t('Settings on <a href="@url_settings">Home » Admin » Config » User interface » A/B Test JS</a> or <a href="@url_settings">@url_settings</a>', [
'@url_settings' => Url::fromRoute('abjs.settings_admin')
->toString(),
]));
}
/**
* Implements hook_schema().
*/
function abjs_schema() {
$schema = [];
// Validate if exists the principal table, else create.
if (\Drupal::database()
->schema()
->tableExists('abjs_test')) {
return $schema;
}
$schema['abjs_test'] = [
'description' => 'The table for a/b tests.',
'fields' => [
'tid' => [
'description' => 'The primary identifier for a test.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'name' => [
'description' => 'The name of this test.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
],
'active' => [
'description' => 'Boolean indicating whether the test is active or not.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'created' => [
'description' => 'The Unix timestamp when the test was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'created_by' => [
'description' => 'The uid of the user who created the test.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'changed' => [
'description' => 'The Unix timestamp when the test was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'changed_by' => [
'description' => 'The uid of the user who last modified the test.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => [
'tid',
],
];
$schema['abjs_experience'] = [
'description' => 'The table for a/b test experiences.',
'fields' => [
'eid' => [
'description' => 'The primary identifier for an experience.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'name' => [
'description' => 'The name of this experience.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
],
'script' => [
'description' => 'The JavaScript for this experience.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
],
'created' => [
'description' => 'The Unix timestamp when the experience was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'created_by' => [
'description' => 'The uid of the user who created the experience.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'changed' => [
'description' => 'The Unix timestamp when the experience was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'changed_by' => [
'description' => 'The uid of the user who last modified the experience.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => [
'eid',
],
];
$schema['abjs_condition'] = [
'description' => 'The table for a/b test conditions.',
'fields' => [
'cid' => [
'description' => 'The primary identifier for a condition.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'name' => [
'description' => 'The name of this condition.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
],
'script' => [
'description' => 'The JavaScript for this condition.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
],
'created' => [
'description' => 'The Unix timestamp when the condition was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'created_by' => [
'description' => 'The uid of the user who created the condition.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'changed' => [
'description' => 'The Unix timestamp when the condition was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'changed_by' => [
'description' => 'The uid of the user who last modified the condition.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => [
'cid',
],
];
$schema['abjs_test_experience'] = [
'description' => 'The table associating a/b tests with experiences.',
'fields' => [
'teid' => [
'description' => 'The primary identifier for the test_experience table.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'tid' => [
'description' => 'The test.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'eid' => [
'description' => 'The experience.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'fraction' => [
'description' => 'The fraction of this test assigned to this experience.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
],
],
'foreign keys' => [
'test' => [
'table' => 'test',
'columns' => [
'tid' => 'tid',
],
],
'experience' => [
'table' => 'experience',
'columns' => [
'eid' => 'eid',
],
],
],
'primary key' => [
'teid',
],
];
$schema['abjs_test_condition'] = [
'description' => 'The table associating a/b tests with conditions.',
'fields' => [
'tcid' => [
'description' => 'The primary identifier for the test_condition table.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'tid' => [
'description' => 'The test.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'cid' => [
'description' => 'The condition.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
],
'foreign keys' => [
'test' => [
'table' => 'test',
'columns' => [
'tid' => 'tid',
],
],
'condition' => [
'table' => 'condition',
'columns' => [
'cid' => 'cid',
],
],
],
'primary key' => [
'tcid',
],
];
return $schema;
}
Functions
Name | Description |
---|---|
abjs_install | Implements hook_install(). |
abjs_schema | Implements hook_schema(). |