1 contact.install contact_update_1001()

Convert available database contact categories to configuration files.

Related topics

File

core/modules/contact/contact.install, line 56
Install, update and uninstall functions for the contact module.

Code

function contact_update_1001() {
  // Migrate categories to config.
  if (db_table_exists('contact')) {
    $contacts = db_query("SELECT * FROM {contact}");
    $categories = array();
    foreach ($contacts as $contact) {
      if ($contact->selected == 1) {
        // Add selected category to config.
        $config_data['contact_default_category'] = $contact->cid;
      }

      unset($contact->selected);
      $categories[] = (array) $contact;
    }

    $config_data['categories'] = $categories;

    $config = config('contact.categories');
    $config->setData($config_data);
    $config->save();

    db_drop_table('contact');
  }
}