You are here

function weight_update_7200 in Weight 7.2

Insert existing settings into {weight_settings}.

File

./weight.install, line 165

Code

function weight_update_7200() {
  $types = node_type_get_names();
  $weight_types = variable_get('weight_node_types', array());
  $range = variable_get('weight_range', 20);
  $menu_weight = (int) variable_get('weight_use_menu', 0);
  $default = (int) variable_get('weight_default', 0);

  // This is essentially the same as calling drupal_install_schema(), but
  // using weight_schema_7200() rather than the default weight_schema().
  // This is important for processing subsequent table updates.
  $schema = weight_schema_7200();
  _drupal_schema_initialize($schema, 'weight');
  foreach ($schema as $name => $table) {
    db_create_table($name, $table);
  }

  // If there are no content types, there is nothing to convert.
  if (empty($types)) {
    return;
  }
  foreach ($types as $type => $name) {
    if (in_array($type, $weight_types)) {
      $enabled = 1;
    }
    else {
      $enabled = 0;
    }
    $query = db_insert('weight_settings')
      ->fields(array(
      'type' => $type,
      'weight_enabled' => $enabled,
      'weight_range' => $range,
      'menu_weight' => $menu_weight,
      'weight_default' => $default,
    ))
      ->execute();
  }
}