summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/page_title/page_title.install
blob: 08033f7b0ba154fe1d0b1a3cd6e63a27e74913c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php

/**
 * @file page_title.install
 *
 * Handles the install, uninstall and updating of Page Title
 */

/**
 * Implements hook_schema().
 */
function page_title_schema() {
  $schema['page_title'] = array(
    'fields' => array(
      'type'       => array('type' => 'varchar', 'length' => 15,  'not null' => TRUE, 'default' => 'node'),
      'id'         => array('type' => 'int', 'unsigned' => TRUE,  'not null' => TRUE, 'default' => 0),
      'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
    ),
    'primary key' => array('type', 'id'),
  );

  return $schema;
}


/**
 * Implements hook_update_n().
 */
function page_title_update_6200() {
  $ret = array();

  if (db_column_exists('page_title', 'id')) {
    return $ret;
  }

  db_create_table($ret, 'page_title_temp', array(
    'fields' => array(
      'type'       => array('type' => 'varchar', 'length' => 15,  'not null' => TRUE, 'default' => 'node'),
      'id'         => array('type' => 'int', 'unsigned' => TRUE,  'not null' => TRUE, 'default' => 0),
      'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
    ),
    'primary key' => array('type', 'id'),
  ));

  $ret[] = update_sql('INSERT INTO {page_title_temp} (id, page_title) SELECT nid, page_title FROM {page_title}');

  db_rename_table($ret, 'page_title', 'page_title_old');

  db_rename_table($ret, 'page_title_temp', 'page_title');

  $display_settings = variable_get('page_title_display', array());
  foreach ($display_settings as $type) {
    if ($type) {
      variable_set('page_title_type_' . $type . '_showfield', 1);
    }
  }
  variable_del('page_title_display');

  return $ret;
}


/**
 * Implements hook_update_n().
 * Rename all the Vocabulary settings to reference by the new Machine Name, rather than Vocab ID.
 */
function page_title_update_7200() {
  $ret = array();

  // If taxonomy not enabled, do no further updates
  if (!module_exists('taxonomy')) {
    return $ret;
  }

  foreach (taxonomy_get_vocabularies() as $vocab) {
    $page_title_vocab_settings = variable_get("page_title_vocab_{$vocab->vid}", FALSE);
    $page_title_vocab_showfield = variable_get("page_title_vocab_{$vocab->vid}_showfield", FALSE);

    if ($page_title_vocab_settings) {
      variable_set("page_title_vocab_{$vocab->machine_name}", $page_title_vocab_settings);
    }
    if ($page_title_vocab_showfield) {
      variable_set("page_title_vocab_{$vocab->machine_name}_showfield", $page_title_vocab_showfield);
    }
    variable_del("page_title_vocab_{$vocab->vid}_showfield");
    variable_del("page_title_vocab_{$vocab->vid}");
  }

  return $ret;
}


/**
 * Implements hook_uninstall().
 */
function page_title_uninstall() {
  // Clear variables
  variable_del('page_title_default');
  variable_del('page_title_individual');
  variable_del('page_title_front');
  variable_del('page_title_blog');
  variable_del('page_title_user');
  variable_del('page_title_user_showfield');
  variable_del('page_title_pager_pattern');
  variable_del('page_title_forum_root_title');
  variable_del('page_title_comment_reply');
  variable_del('page_title_comment_child_reply');

  // Clear the node specific variables
  $types = node_type_get_names();
  foreach ($types as $type => $name) {
    variable_del("page_title_type_{$type}");
    variable_del("page_title_type_{$type}_showfield");
  }

  // Clear the vocab specific variables
  if (module_exists('taxonomy')) {
    $vocabs = taxonomy_get_vocabularies();
    foreach ($vocabs as $vid => $vocab) {
      variable_del("page_title_vocab_{$vocab->machine_name}");
      variable_del("page_title_vocab_{$vocab->machine_name}_showfield");

      // Legacy delete - just in case the uninstall is happening befoer update 7200
      variable_del("page_title_vocab_{$vid}");
      variable_del("page_title_vocab_{$vid}_showfield");
    }
  }
}