You are here

function search_by_page_update_6000 in Search by Page 6

Same name and namespace in other branches
  1. 7 search_by_page.install \search_by_page_update_6000()

Adds language, environment, and uid fields to sbp_path table.

File

./search_by_page.install, line 150
Install hooks for search_by_page module

Code

function search_by_page_update_6000() {
  $ret = array();
  db_add_field($ret, 'sbp_path', 'language', array(
    'description' => t('Language for this path'),
    'type' => 'varchar',
    'length' => '12',
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'sbp_path', 'environment', array(
    'description' => t('Environment ID'),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index($ret, 'sbp_path', 'envi', array(
    'environment',
  ));
  db_add_field($ret, 'sbp_path', 'uid', array(
    'description' => t('User ID used to index this path'),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));

  // Set up environment based on previous settings, if no environment exists
  $stuff = variable_get('search_by_page_settings', array());
  if (!count($stuff)) {
    $envid = 1;
    search_by_page_setting_set('environment_name', $envid, t('default'));
    search_by_page_setting_set('block_title', $envid, t('Search'));
    search_by_page_setting_set('page_title', $envid, t('Search'));
    search_by_page_setting_set('page_path', $envid, 'search_pages');
    variable_set('search_by_page_default_environment', $envid);

    // Note: Do the sub-module settings here too, because they should all be
    // done in one update.
    $fields = array(
      'field_label' => 'search_by_page_field_label',
      'button_label' => 'search_by_page_button_label',
      'sbp_users_roles_indexed' => 'sbp_users_roles_indexed',
      'sbp_nodes_types_indexed' => 'sbp_nodes_types_indexed',
      'sbp_nodes_display_type' => 'sbp_nodes_display_type',
      'sbp_attach_only_listed' => 'sbp_attach_only_listed',
      'sbp_attach_node_types' => 'sbp_attach_node_types',
      'sbp_attach_field_types' => 'sbp_attach_field_types',
      'sbp_attach_only_listed' => 'sbp_attach_only_listed',
      'sbp_attach_prepend_node_titles' => 'sbp_attach_prepend_node_titles',
      'sbp_attach_title_sep' => 'sbp_attach_title_sep',
      'sbp_attach_use_description' => 'sbp_attach_use_description',
    );
    foreach ($fields as $field => $oldfield) {
      if ($value = variable_get($oldfield, 0)) {
        search_by_page_setting_set($field, $envid, $value);
        variable_del($oldfield);
      }
    }
  }

  // Set default environment and language
  $lang = language_default('language');
  $ret[] = update_sql("UPDATE {sbp_path} SET language='%s'", $lang);
  $ret[] = update_sql("UPDATE {sbp_path} SET environment=1");
  return $ret;
}