You are here

function signature_forum_update_7000 in Signatures for Forums 7

Upgrade to Drupal 7.

File

./signature_forum.install, line 119
Installs, updates and uninstalls signature_forum module.

Code

function signature_forum_update_7000() {

  // Make sure signature_forum is loaded.
  drupal_load('module', 'signature_forum');
  _signature_forum_update_schema();

  // Move signatures to the core users table.
  switch (Database::getConnection()
    ->databaseType()) {
    case 'mysql':
    case 'mysqli':
      db_query('UPDATE {users}, {users_signature}
        SET {users}.signature = {users_signature}.signature
        WHERE {users}.uid = {users_signature}.uid');
      break;
    case 'pqsql':
      db_query('UPDATE {users} SET signature = {users_signature}.signature FROM {users_signature}}
        WHERE {users}.uid = {users_signature}.uid');
      break;
  }

  // Update the Drupal 6 schema.
  db_drop_table('users_signature');

  // Update the settings.
  $settings = variable_get('signature_forum_settings', array());
  $direct_transfer = array(
    'signature_forum_line_limit' => 'signature_forum_max_lines',
    'signature_forum_min_content_length' => 'signature_forum_short_content_length',
    'signature_forum_min_content_length_action' => 'signature_forum_short_content_action',
    'signature_forum_min_content_length_filter' => 'signature_forum_short_content_format',
    'signature_forum_show_once_options' => 'signature_forum_show_once_options',
  );
  foreach ($direct_transfer as $from => $to) {
    if (!empty($settings[$from])) {
      variable_set($to, $settings[$from]);
    }
  }
  if (empty($settings['signature_forum_min_content_length'])) {
    variable_set('signature_forum_short_content_action', SIGNATURE_FORUM_DO_NOTHING);
  }
  variable_del('signature_forum_settings');

  // Upgrade the visibility settings.
  $visibility_settings = array();
  foreach (node_type_get_names() as $type) {
    $visibility_settings[$type->type] = !empty($settings['signature_forum_show_for_' . $type->type]);
  }
  _signature_forum_update_bundle_settings('node', $visibility_settings);
}