contact.install

Install, update and uninstall functions for the contact module.

File

drupal/core/modules/contact/contact.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the contact module.
 */
use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Language\Language;

/**
 * Implements hook_install().
 */
function contact_install() {
  $site_mail = config('system.site')
    ->get('mail');
  if (empty($site_mail)) {
    $site_mail = ini_get('sendmail_from');
  }
  config('contact.category.feedback')
    ->set('recipients', array(
    $site_mail,
  ))
    ->save();
}

/**
 * @addtogroup updates-7.x-to-8.x
 * @{
 */

/**
 * Implements hook_update_dependencies().
 */
function contact_update_dependencies() {

  // Migrate users.data after User module prepared the tables.
  $dependencies['contact'][8003] = array(
    'user' => 8011,
  );
  return $dependencies;
}

/**
 * Moves contact setting from variable to config.
 *
 * @ingroup config_upgrade
 */
function contact_update_8000() {
  update_variables_to_config('contact.settings', array(
    'contact_default_status' => 'user_default_enabled',
    'contact_threshold_limit' => 'flood.limit',
    'contact_threshold_window' => 'flood.interval',
  ));
}

/**
 * Migrate contact categories into configuration.
 *
 * @ingroup config_upgrade
 */
function contact_update_8001() {
  $uuid = new Uuid();
  $result = db_query('SELECT * FROM {contact}');
  foreach ($result as $category) {

    // Take over the category's serial ID as new machine name.
    $category->id = $category->cid;

    // Save default category setting.
    if ($category->selected) {
      config('contact.settings')
        ->set('default_category', $category->id)
        ->save();
    }

    // Save the config object.
    config('contact.category.' . $category->id)
      ->set('id', $category->id)
      ->set('uuid', $uuid
      ->generate())
      ->set('label', $category->category)
      ->set('recipients', explode(',', $category->recipients))
      ->set('reply', $category->reply)
      ->set('weight', $category->weight)
      ->set('langcode', Language::LANGCODE_NOT_SPECIFIED)
      ->save();
  }
}

/**
 * Drop the {contact} table.
 */
function contact_update_8002() {
  db_drop_table('contact');
}

/**
 * Migrate {users}.data into {users_data}.
 */
function contact_update_8003() {
  $query = db_select('_d7_users_data', 'ud');
  $query
    ->condition('name', 'contact');
  $query
    ->addField('ud', 'uid');
  $query
    ->addExpression("'contact'", 'module');
  $query
    ->addExpression("'enabled'", 'name');
  $query
    ->addField('ud', 'value', 'value');
  $query
    ->addExpression(1, 'serialized');
  db_insert('users_data')
    ->from($query)
    ->execute();
  db_delete('_d7_users_data')
    ->condition('name', 'contact')
    ->execute();
}

/**
 * @} End of "defgroup updates-7.x-to-8.x".
 * The next series of updates should start at 9000.
 */

Functions

Namesort descending Description
contact_install Implements hook_install().
contact_update_8000 Moves contact setting from variable to config.
contact_update_8001 Migrate contact categories into configuration.
contact_update_8002 Drop the {contact} table.
contact_update_8003 Migrate {users}.data into {users_data}.
contact_update_dependencies Implements hook_update_dependencies().