drupalorg_migrate-1.0.x-dev/drupalorg_migrate.install

drupalorg_migrate.install
<?php

/**
 * @file
 * Drupal.org Custom Migrations install hooks.
 */

use Drupal\Core\Database\Database;

/**
 * Implements hook_update_N().
 */
function drupalorg_migrate_update_10001() {
  drupalorg_migrate_ensure_auto_increment_values();
}

/**
 * Implements hook_update_N().
 *
 * Ensure auto increment values are set.
 */
function drupalorg_migrate_update_10002() {
  drupalorg_migrate_ensure_auto_increment_values();
}

/**
 * Implements hook_update_N().
 *
 * Ensure auto increment values are set.
 */
function drupalorg_migrate_update_10003() {
  drupalorg_migrate_ensure_auto_increment_values();
}

/**
 * Ensure auto increment values.
 */
function drupalorg_migrate_ensure_auto_increment_values() {
  $connection = Database::getConnection();
  $database = $connection->getConnectionOptions()['database'];
  $auto_increment_new_values = [
    'node' => 10000000,
    'node_revision' => 20000000,
    'paragraphs_item' => 2000000,
    'paragraphs_item_revision' => 20000000,
    'comment' => 30000000,
  ];
  foreach ($auto_increment_new_values as $table => $value) {
    $current_value = $connection->query("
      SELECT AUTO_INCREMENT
      FROM  INFORMATION_SCHEMA.TABLES
      WHERE TABLE_SCHEMA = '$database' AND TABLE_NAME = '$table'
    ")->fetchField();
    if (is_numeric($current_value) && $current_value < $value) {
      $connection->query("ALTER TABLE {" . $table . "} AUTO_INCREMENT = " . $value);
    }
  }
}

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

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