content_synchronizer.install in Content Synchronizer 8
Same filename and directory in other branches
Installation hooks for content_synchronizer module.
File
content_synchronizer.installView source
<?php
/**
* @file
* Installation hooks for content_synchronizer module.
*/
/**
* Define schema.
*/
function content_synchronizer_get_schema() {
$schema['content_synchronizer_global_reference'] = [
'description' => 'Table for global reference',
'fields' => [
'gid' => [
'type' => 'varchar',
'size' => 'normal',
'length' => 100,
'default' => '',
'not null' => TRUE,
],
'entity_id' => [
'type' => 'varchar',
'size' => 'normal',
'length' => 100,
'default' => '',
'not null' => TRUE,
],
'entity_type' => [
'type' => 'varchar',
'size' => 'normal',
'length' => 100,
'default' => '',
'not null' => TRUE,
],
],
'primary key' => [
'gid',
],
];
$schema['content_synchronizer_export_items'] = [
'description' => 'Table for export items',
'fields' => [
'export_id' => [
'type' => 'int',
'default' => 0,
'size' => 'normal',
'not null' => TRUE,
],
'entity_id' => [
'type' => 'varchar',
'size' => 'normal',
'length' => 100,
'default' => '',
'not null' => TRUE,
],
'entity_type' => [
'type' => 'varchar',
'size' => 'normal',
'length' => 100,
'default' => '',
'not null' => TRUE,
],
],
'primary key' => [
'export_id',
'entity_id',
'entity_type',
],
];
return $schema;
}
/**
* Create useful tables from schema.
*/
function content_synchronizer_create_tables() {
foreach (content_synchronizer_get_schema() as $table => $definition) {
try {
\Drupal::database()
->schema()
->createTable($table, $definition);
} catch (\Exception $e) {
echo $e
->getMessage();
}
}
}
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function content_synchronizer_install() {
// Add custom tables :
content_synchronizer_create_tables();
}
/**
* Delete tables.
*/
function content_synchronizer_uninstall() {
foreach (content_synchronizer_get_schema() as $table => $definition) {
try {
if (\Drupal::database()
->schema()
->tableExists($table)) {
\Drupal::database()
->schema()
->dropTable($table);
}
} catch (\Exception $e) {
echo $e
->getMessage();
}
}
}
Functions
Name | Description |
---|---|
content_synchronizer_create_tables | Create useful tables from schema. |
content_synchronizer_get_schema | Define schema. |
content_synchronizer_install | Implements hook_install(). |
content_synchronizer_uninstall | Delete tables. |