112 lines
2.7 KiB
Plaintext
112 lines
2.7 KiB
Plaintext
<?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 = Drupal::config('system.site')->get('mail');
|
|
if (empty($site_mail)) {
|
|
$site_mail = ini_get('sendmail_from');
|
|
}
|
|
Drupal::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) {
|
|
Drupal::config('contact.settings')
|
|
->set('default_category', $category->id)
|
|
->save();
|
|
}
|
|
// Save the config object.
|
|
Drupal::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.
|
|
*/
|