You are here

content_synchronizer.install in Content Synchronizer 3.x

Same filename and directory in other branches
  1. 8.2 content_synchronizer.install
  2. 8 content_synchronizer.install

Installation hooks for content_synchronizer module.

File

content_synchronizer.install
View 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();
}

Functions

Namesort descending Description
content_synchronizer_create_tables Create useful tables from schema.
content_synchronizer_get_schema Define schema.
content_synchronizer_install Implements hook_install().