contact.install 2.77 KB
Newer Older
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Install, update and uninstall functions for the contact module.
 */

8 9
use Drupal\Component\Uuid\Uuid;

10
/**
11
 * Implements hook_install().
12 13
 */
function contact_install() {
14 15 16 17
  $site_mail = config('system.site')->get('mail');
  if (empty($site_mail)) {
    $site_mail = ini_get('sendmail_from');
  }
18
  config('contact.category.feedback')->set('recipients', array($site_mail))->save();
19 20
}

21 22 23 24 25
/**
 * @addtogroup updates-7.x-to-8.x
 * @{
 */

26 27 28 29 30 31 32 33 34 35 36
/**
 * 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;
}

37
/**
38 39 40
 * Moves contact setting from variable to config.
 *
 * @ingroup config_upgrade
41
 */
42 43 44 45 46 47
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',
  ));
48
}
49 50 51 52 53 54 55

/**
 * Migrate contact categories into configuration.
 *
 * @ingroup config_upgrade
 */
function contact_update_8001() {
56
  $uuid = new Uuid();
57
  $result = db_query('SELECT * FROM {contact}');
58
  $ids = array();
59 60 61
  foreach ($result as $category) {
    // Take over the category's serial ID as new machine name.
    $category->id = $category->cid;
62 63
    // Save the id to add to the manifest file.
    $ids[] = $category->id;
64 65 66 67 68 69 70 71 72
    // 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)
73
      ->set('uuid', $uuid->generate())
74 75 76 77
      ->set('label', $category->category)
      ->set('recipients', explode(',', $category->recipients))
      ->set('reply', $category->reply)
      ->set('weight', $category->weight)
78
      ->set('langcode', LANGUAGE_NOT_SPECIFIED)
79 80
      ->save();
  }
81 82

  update_config_manifest_add('contact.category', $ids);
83 84 85 86 87 88 89 90 91
}

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

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/**
 * 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();
}

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