pki_ra-8.x-1.x-dev/pki_ra.install

pki_ra.install
<?php

use Drupal\Core\Database\Database;

/**
 * @file
 * Install, update and uninstall functions for the pki_ra module.
 */

use Drupal\user\RoleInterface;

/**
 * Implements hook_install().
 */
function pki_ra_install() {
  // Allow anonymous users to create Registration records.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['create pki_ra_registration content']);
  // Allow anonymous verified users to submit CSRs through the REST interface via JS.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['restful post pki_ra_certificate_signing_request_rest_resource']);
}

/**
 * Implements hook_schema().
 */
function pki_ra_schema() {
  // Create EOI Source table.
  $schema['pki_ra_eoi_progress'] = [
    'description' => "Stores user's EOI progress.",
    'fields' => [
      'id' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key',
      ],
      'registration_id' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => "Registration ID",
      ],
      'eoi_source' => [
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'EOI Source',
      ],
      'status' => [
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Status',
      ],
      'updated' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Status',
       ],
    ],
    'primary key' => ['id'],
  ];
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function pki_ra_uninstall() {
  // Get the IDs for all of our records and delete them.
  $node_ids = \Drupal::entityQuery('node')
      ->condition('type', [
        'pki_ra_registration',
        'pki_ra_certificate',
      ], 'IN')
      ->execute();
  entity_delete_multiple('node', $node_ids);

  // Delete the Certificate content type first as it depends on Template.
  node_type_load('pki_ra_certificate')->delete();

  // Delete the Registration content type.
  node_type_load('pki_ra_registration')->delete();

  // Delete the configuration.
  \Drupal::configFactory()->getEditable('pki_ra.settings')->delete();
}

/**
 * Implements hook_update_n().
 *
 * Add EOI Sources progress table.
 */
function pki_ra_update_8001() {
  // Call schema function to get table columns information.
  $spec = pki_ra_schema();
  $schema = Database::getConnection()->schema();
  $schema->createTable('pki_ra_eoi_progress', $spec['pki_ra_eoi_progress']);
}

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

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