views.install 11.3 KB
Newer Older
1
<?php
2
  // $Id$
3 4

  function views_install() {
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    drupal_set_message('Installing views');
    switch ($GLOBALS['db_type']) {
      case 'mysqli':
      case 'mysql':
      db_query("CREATE TABLE if not exists {view_view} (
        vid int(10) unsigned NOT NULL default '0',
        name varchar(32) NOT NULL UNIQUE,
        description varchar(255),
        access varchar(255),
        -- page fields
        page int(1),
        page_title varchar(255),
        page_header longtext,
        page_header_format int(4) NOT NULL,
        page_empty longtext,
        page_empty_format int(4) NOT NULL,
merlinofchaos's avatar
merlinofchaos committed
21 22
        page_footer longtext,
        page_footer_format int(4) NOT NULL,
23 24
        page_type varchar(20),
        use_pager int(1),
merlinofchaos's avatar
merlinofchaos committed
25
        nodes_per_page int(5),
26 27 28 29 30 31 32 33 34 35 36 37 38
        url varchar(255),
        -- menu fields
        menu int(1),
        menu_tab int(1),
        menu_tab_default int(1),
        menu_tab_weight int(4),
        menu_title varchar(255),
        -- block fields
        block int(1),
        block_title varchar(255),
        block_use_page_header int(1),
        block_header longtext,
        block_header_format int(4) NOT NULL,
merlinofchaos's avatar
merlinofchaos committed
39 40 41
        block_use_page_footer int(1),
        block_footer longtext,
        block_footer_format int(4) NOT NULL,
42 43 44 45 46 47 48 49 50 51 52 53
        block_use_page_empty int(1),
        block_empty longtext,
        block_empty_format int(4) NOT NULL,
        block_type varchar(20),
        nodes_per_block int(5),
        block_more int(1),
        -- breadcrumb
        breadcrumb_no_home int(1), -- true means start breadcrumb trail from 'Home'.
        -- other
        changed int(11),
        query longtext,
        countquery longtext,
54
        view_args_php longtext,
55 56
        PRIMARY KEY (vid),
        KEY (name)
57
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
58

59 60 61 62 63 64 65 66
      db_query("CREATE TABLE if not exists {view_sort} (
        vid int(10) unsigned NOT NULL default '0',
        position int(2),
        field varchar(255),
        sortorder varchar(5),
        options varchar(255),
        tablename varchar(255),
        KEY (vid)
67
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
68

69 70
      db_query("CREATE TABLE if not exists {view_argument} (
        vid int(10) unsigned NOT NULL default '0',
71
        type varchar(255),
72 73 74 75
        argdefault varchar(255),
        title varchar(255),
        options varchar(255),
        position int(2),
76 77
        wildcard varchar(32),
        wildcard_substitution varchar(32),
78
        KEY (vid)
79
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
80

81 82 83 84 85 86 87 88
      db_query("CREATE TABLE if not exists {view_tablefield} (
        vid int(10) unsigned NOT NULL default '0',
        tablename varchar(255),
        field varchar(255),
        label varchar(255),
        handler varchar(255),
        sortable int(1),
        defaultsort varchar(5),
89
        options varchar(255),
90 91
        position int(2),
        KEY (vid)
92
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
93

94 95 96 97 98 99 100 101 102
      db_query("CREATE TABLE if not exists {view_filter} (
        vid int(10) unsigned NOT NULL default '0',
        tablename varchar(255),
        field varchar(255),
        value longtext,
        operator varchar(20),
        options varchar(255),
        position int(2),
        KEY (vid)
103
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
104

105
      db_query("CREATE TABLE if not exists {view_exposed_filter} (
106 107 108 109 110 111 112 113 114
        vid int(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional int(1),
        is_default int(1),
        operator int(1),
        single int(1),
        position int(2),
        KEY (vid)
115
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
116

117 118 119 120
      $success = TRUE;
      break;
    case 'pgsql':
      db_query("CREATE TABLE {view_view} (
merlinofchaos's avatar
merlinofchaos committed
121
        vid SERIAL,
122 123 124 125
        name varchar(32) NOT NULL UNIQUE,
        description varchar(255),
        access varchar(255),
        -- page fields
126
        page smallint,
127 128
        page_title varchar(255),
        page_header text,
129
        page_header_format smallint NOT NULL,
130
        page_empty text,
131 132 133
        page_empty_format smallint NOT NULL,
        page_footer text,
        page_footer_format smallint NOT NULL,
134
        page_type varchar(20),
135
        use_pager smallint,
merlinofchaos's avatar
merlinofchaos committed
136
        nodes_per_page smallint, 
137 138
        url varchar(255),
        -- menu fields
139 140 141 142
        menu smallint,
        menu_tab smallint,
        menu_tab_default smallint,
        menu_tab_weight smallint,
143 144
        menu_title varchar(255),
        -- block fields
145
        block smallint,
146
        block_title varchar(255),
147
        block_use_page_header smallint,
148
        block_header text,
149 150
        block_header_format smallint NOT NULL,
        block_use_page_footer smallint,
151
        block_footer text,
152 153
        block_footer_format smallint NOT NULL,
        block_use_page_empty smallint,
154
        block_empty text,
155
        block_empty_format smallint NOT NULL,
156
        block_type varchar(20),
157 158
        nodes_per_block smallint,
        block_more smallint,
159
        -- breadcrumb
160
        breadcrumb_no_home smallint, -- true means start breadcrumb trail from 'Home'.
161
        -- other
162
        changed integer,
163 164
        query text,
        countquery text,
165
        view_args_php text,
merlinofchaos's avatar
merlinofchaos committed
166
        PRIMARY KEY (vid)
167
      )");
merlinofchaos's avatar
merlinofchaos committed
168
      db_query("CREATE INDEX {view_view}_name_idx ON {view_view} (name)");
169 170

      db_query("CREATE TABLE {view_sort} (
171 172
        vid integer NOT NULL default '0',
        position smallint,
173 174 175 176 177
        field varchar(255),
        sortorder varchar(5),
        options varchar(255),
        tablename varchar(255)
      )");
merlinofchaos's avatar
merlinofchaos committed
178
      db_query("CREATE INDEX {view_sort}_vid_idx ON {view_sort} (vid)");
179 180

      db_query("CREATE TABLE {view_argument} (
181
        vid integer NOT NULL default '0',
182
        type varchar(255),
183 184 185
        argdefault varchar(255),
        title varchar(255),
        options varchar(255),
186
        position smallint,
187
        wildcard varchar(32),
188
        wildcard_substitution varchar(32)
189
      )");
merlinofchaos's avatar
merlinofchaos committed
190
      db_query("CREATE INDEX {view_argument}_vid_idx ON {view_argument} (vid)");
191 192

      db_query("CREATE TABLE {view_tablefield} (
193
        vid integer NOT NULL default '0',
194 195 196 197
        tablename varchar(255),
        field varchar(255),
        label varchar(255),
        handler varchar(255),
198
        sortable smallint,
199
        defaultsort varchar(5),
200
        options varchar(255),
201
        position smallint
202
      )");
merlinofchaos's avatar
merlinofchaos committed
203
      db_query("CREATE INDEX {view_tablefield}_vid_idx ON {view_tablefield} (vid)");
204 205

      db_query("CREATE TABLE {view_filter} (
206
        vid integer NOT NULL default '0',
207 208 209 210 211
        tablename varchar(255),
        field varchar(255),
        value text,
        operator varchar(20),
        options varchar(255),
212
        position smallint
213
      )");
merlinofchaos's avatar
merlinofchaos committed
214
      db_query("CREATE INDEX {view_filter}_vid_idx ON {view_filter} (vid)");
215
      db_query("CREATE TABLE {view_exposed_filter} (
216
        vid integer NOT NULL default '0',
217 218
        field varchar(255),
        label varchar(255),
219 220 221 222 223
        optional smallint,
        is_default smallint,
        operator smallint,
        single smallint,
        position smallint
224
      )");
merlinofchaos's avatar
merlinofchaos committed
225 226 227
      db_query("CREATE INDEX {view_exposed_filter}_vid_idx ON {view_exposed_filter} (vid)");

      $success = TRUE;
228 229 230
      break;
  } // End case

231
  db_query("UPDATE {system} SET weight = 10 WHERE name = 'views'");
232
  if ($success) {
233
    module_enable(array('views_ui'));
234 235 236 237 238
    drupal_set_message(t('Views module installed tables successfully.'));
  }
  else {
    drupal_set_message(t('The installation of views module was unsuccessful.'), 'error');
  }
239
}
240

241 242 243 244 245 246 247 248 249
function views_uninstall() {
  db_query("DROP TABLE IF EXISTS {view_view}");
  db_query("DROP TABLE IF EXISTS {view_sort}");
  db_query("DROP TABLE IF EXISTS {view_argument}");
  db_query("DROP TABLE IF EXISTS {view_tablefield}");
  db_query("DROP TABLE IF EXISTS {view_filter}");
  db_query("DROP TABLE IF EXISTS {view_exposed_filter}");
}

250 251 252 253 254 255
/*
 * update module for UTF.
 */
function views_update_1() {
  return _system_update_utf8(array('view_view', 'view_tablefield', 'view_filter', 'view_sort', 'view_argument'));
}
256 257 258 259 260 261 262 263

/**
 * Dummy function cause we're apparently not to skip update #s.
 */
function views_update_2() {
// dummy function
  return array();
}
264
/*
merlinofchaos's avatar
merlinofchaos committed
265
 * update module for exposed filters.
266
 */
267 268
function views_update_3() {
  $ret = array();
269 270 271 272 273
//  db_add_column($ret, 'view_view', 'page_empty', 'longtext');
//  db_add_column($ret, 'view_view', 'page_empty_format', 'int(4)', array('not null' => TRUE));
//  db_add_column($ret, 'view_view', 'block_use_page_empty', 'int(1)');
//  db_add_column($ret, 'view_view', 'block_empty', 'longtext');
//  db_add_column($ret, 'view_view', 'block_empty_format', 'int(4)', array('not null' => TRUE));
274
  switch($GLOBALS['db_type']) {
275 276
    case 'mysql':
    case 'mysqli':
277
    $ret[] = update_sql("CREATE TABLE if not exists {view_exposed_filter} (
278 279 280 281 282 283 284 285 286 287 288 289
        vid int(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional int(1),
        is_default int(1),
        operator int(1),
        single int(1),
        position int(2),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
290
      $ret[] = update_sql("CREATE TABLE {view_exposed_filter} (
291 292 293 294 295 296 297 298 299
        vid numeric(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional numeric(1),
        is_default numeric(1),
        operator numeric(1),
        single numeric(1),
        position numeric(2),
      )");
merlinofchaos's avatar
merlinofchaos committed
300
      $ret[] = update_sql("CREATE INDEX {view_exposed_filter}_vid_idx ON {view_exposed_filter} (vid)");
301 302
      break;
  }
303
  return $ret;
304
}
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319

function views_update_4() {
  $ret = array();
  db_add_column($ret, 'view_view', 'page_footer', 'longtext');
  db_add_column($ret, 'view_view', 'page_footer_format', 'int(4)', array('default' => 0));
  db_add_column($ret, 'view_view', 'block_use_page_footer', 'int(1)');
  db_add_column($ret, 'view_view', 'block_footer', 'longtext');
  db_add_column($ret, 'view_view', 'block_footer_format', 'int(4)', array('default' => 0));
  db_add_column($ret, 'view_view', 'page_empty', 'longtext');
  db_add_column($ret, 'view_view', 'page_empty_format', 'int(4)', array('default' => 0));
  db_add_column($ret, 'view_view', 'block_use_page_empty', 'int(1)');
  db_add_column($ret, 'view_view', 'block_empty', 'longtext');
  db_add_column($ret, 'view_view', 'block_empty_format', 'int(4)', array('default' => 0));
  return $ret;
}
320 321 322 323 324 325

function views_update_5() {
  $ret = array();
  db_add_column($ret, 'view_view', 'view_args_php', 'longtext');
  return $ret;
}
326 327 328 329 330 331

function views_update_6() {
  $ret = array();
  db_add_column($ret, 'view_tablefield', 'options', 'varchar(255)');
  return $ret;
}
332 333 334

function views_update_7() {
  $ret = array();
335
  $ret[] = update_sql("ALTER TABLE {view_argument} MODIFY type varchar(255)");
336 337
  return $ret;
}
merlinofchaos's avatar
merlinofchaos committed
338 339 340 341 342 343

function views_update_8() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {view_view} MODIFY nodes_per_page int(5)");
  return $ret;
}
344 345 346 347 348 349

function views_update_9() {
  $ret = array();
  db_add_column($ret, 'view_argument', 'wildcard', 'varchar(32)');
  db_add_column($ret, 'view_argument', 'wildcard_substitution', 'varchar(32)');
  return $ret;
350
}
351 352 353 354 355 356

function views_update_10() {
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'views'");
  return $ret;
}
357 358 359 360 361 362 363

function views_update_11() {
  // running this again because fresh installs of 1.4 didn't get it.
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'views'");
  return $ret;
}