HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: /var/www/html/drupal/20210422/public_html/modules/view_custom_table/view_custom_table.install
<?php

/**
 * @file
 * Installation functions for the View Custom Table module.
 */

use Drupal\Core\Database\Database;

/**
 * Add 'table_database' column so tables from other database can be implemented.
 */
function view_custom_table_update_8101() {
  $table_database = [
    'description' => 'Database of the table.',
    'type' => 'varchar',
    'length' => 100,
    'not null' => TRUE,
    'default' => 'default',
  ];
  $schema = Database::getConnection()->schema();
  $schema->addField('custom_table_view_data', 'table_database', $table_database);
}

/**
 * Take values from database and save to config file.
 */
function view_custom_table_update_8102() {
  $connection = Database::getConnection();
  $query = $connection->select('custom_table_view_data')
    ->fields('custom_table_view_data');
  $result = $query->execute()->fetchAll();
  if (!empty($result)) {
    $config = \Drupal::service('config.factory')->getEditable('view_custom_table.tables');
    foreach ($result as $row) {
      $config->set($row->table_name . '.table_name', $row->table_name);
      $config->set($row->table_name . '.table_database', $row->table_database);
      $config->set($row->table_name . '.description', $row->description);
      $config->set($row->table_name . '.column_relations', $row->column_relations);
      $config->set($row->table_name . '.created_by', $row->created_by);
    }
    $config->save();
  }
  Database::getConnection()->schema()->dropTable('custom_table_view_data');
}