acknowledgements-8.x-1.0-beta11/sign_for_acknowledgement.install

sign_for_acknowledgement.install
<?php
/**
 * @file
 * Module installation.
 */
use Drupal\sign_for_acknowledgement\Service\AcknowledgementsNodeFields;
use Drupal\Core\Database\Database;

/**
 * Change alternate field type.
 */
function sign_for_acknowledgement_update_8101(&$sandbox) {
  $fieldman = \Drupal::service('sign_for_acknowledgement.field_manager');
  $fieldman->resetFields();
  $table = 'sign_for_acknowledgement';
  $field = 'alternate';
  $tableSchema = drupal_get_module_schema('sign_for_acknowledgement', $table);
  $dbSchema = Database::getConnection()->schema();
  $dbSchema->changeField($table, $field, $field, $tableSchema['fields'][$field]);
  if (!$dbSchema->indexExists($table, 'nid_uid')) {
    $dbSchema->addIndex($table, 'nid_uid', array('node_id', 'user_id'), $tableSchema);
  }
  if (!$dbSchema->indexExists($table, 'mydate')) {
    $dbSchema->addIndex($table, 'mydate', array('mydate'), $tableSchema);
  }
  $table = 'sign_for_acknowledgement_email';
  $tableSchema = drupal_get_module_schema('sign_for_acknowledgement', $table);
  if (!$dbSchema->indexExists($table, 'nid_uid')) {
    $dbSchema->addIndex($table, 'nid_uid', array('node_id', 'user_id'), $tableSchema);
  }
  if (!$dbSchema->indexExists($table, 'mydate')) {
    $dbSchema->addIndex($table, 'mydate', array('mydate'), $tableSchema);
  }
}

/**
 * Create mail queue table.
 */
function sign_for_acknowledgement_update_9101() {
  $database = \Drupal::database();
  $schema = $database->schema();
  $table_name = 'sign_for_acknowledgement_mail_spool';
  // deprecato
  if ($database->schema()->tableExists($table_name)) {
    echo 'table exist!';
  }
  else {
    $table_schema = drupal_get_module_schema('sign_for_acknowledgement', $table_name);
    $schema->createTable($table_name, $table_schema);
  }
}

/**
 * Implements hook_install().
 */
function sign_for_acknowledgement_install() {
  $fieldman = \Drupal::service('sign_for_acknowledgement.field_manager');
  $fieldman->resetFields();
}
/**
 * Implements hook_schema().
 */
function sign_for_acknowledgement_schema() {
  $schema['sign_for_acknowledgement'] = array(
    'description' => 'Having read table.',
    'fields' => array(
      'hid'  => array(
        'description' => 'autoincremental index',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'node_id'  => array(
        'description' => 'node id',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'user_id' => array(
        'description' => 'user id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'mydate' => array(
        'description' => 'datestamp of the signature',
        'type' => 'int',
        'not null' => FALSE,
      ),
      'alternate' => array(
        'type' => 'text',
        'size' => 'medium',
        'not null' => FALSE,
        'description' => 'User selection in alternate form.',
      ),
      'annotation' => array(
        'type' => 'text',
        'size' => 'medium',
        'not null' => FALSE,
        'description' => 'User annotation any form.',
      ),
    ),
    'primary key' => array('hid'),
    'indexes' => array(
      'nid_uid' => array('node_id', 'user_id'),
      'mydate' => array('mydate'),
    ),
  );
  $schema['sign_for_acknowledgement_email'] = array(
    'description' => 'Emails sent table.',
    'fields' => array(
      'eid'  => array(
        'description' => 'autoincremental index',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'node_id'  => array(
        'description' => 'node id',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'user_id' => array(
        'description' => 'user id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'mydate' => array(
        'description' => 'datestamp of the email',
        'type' => 'int',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array('eid'),
    'indexes' => array(
      'nid_uid' => array('node_id', 'user_id'),
      'mydate' => array('mydate'),
    ),
  );
  $schema['sign_for_acknowledgement_mail_spool'] = [
    'description' => 'Spool for temporary storage of emails.',
    'fields' => [
      'msid' => [
        'description' => 'The primary identifier for a mail spool record.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'nid' => [
        'description' => 'The {node}.nid related to this acknowledgement.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'receivers' => [
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of name value pairs that are related to the email address.',
      ],
      'current_receiver' => [
        'description' => 'The formatted email address of mail message recipient.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'status' => [
        'description' => 'The sent status of the email (0 = hold, 1 = pending, 2 = done).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ],
      'no_signature' => [
        'description' => 'no signature mode(boolean).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ],
      'error' => [
        'description' => 'A boolean indicating whether an error occured while sending the email.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ],
      'timestamp' => [
        'description' => 'The time status was set or changed.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => ['msid'],
    'indexes' => [
      'status' => ['status'],
    ],
    'foreign keys' => [
      'nid' => [
        'table' => 'node',
        'columns' => ['nid' => 'nid'],
      ],
    ],
  ];

  return $schema;
}
/**
 * Implements hook_uninstall().
 */
function sign_for_acknowledgement_uninstall() {
  // Remove the sfa fields.
  $fields = \Drupal::entityTypeManager()
    ->getStorage('field_storage_config')
    ->loadByProperties(['type' => 'sign_for_acknowledgement']);
  foreach ($fields as $field) {
    $field->delete();
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc