views.install 18.1 KB
Newer Older
1
<?php
2
// $Id$
3
/**
4 5
 * @file views.install
 * Contains install and update functions for Views.
6
 */
merlinofchaos's avatar
merlinofchaos committed
7

8 9 10 11
function views_install() {
  drupal_set_message('Installing views');
  drupal_install_schema('views');
  db_query("UPDATE {system} SET weight = 10 WHERE name = 'views'");
12
}
13

14 15
function views_uninstall() {
  drupal_uninstall_schema('views');
16
}
17 18 19 20 21 22 23 24 25

/**
 * Implementation of hook_schema
 */
function views_schema() {
  $schema['views_view'] = array(
    'description' => t('Stores the general data for a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
26 27 28
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
29 30 31 32
        'description' => t('The view ID of the field, defined by the database.'),
        'no export' => TRUE,
      ),
      'name' => array(
merlinofchaos's avatar
merlinofchaos committed
33 34
        'type' => 'varchar',
        'length' => '32',
35
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
36
        'not null' => TRUE,
37 38 39
        'description' => t('The unique name of the view. This is the primary field views are loaded from, and is used so that views may be internal and not necessarily in the database. May only be alphanumeric characters plus underscores.'),
      ),
      'description' => array(
merlinofchaos's avatar
merlinofchaos committed
40 41
        'type' => 'varchar',
        'length' => '255',
42 43 44
        'default' => '',
        'description' => t('A description of the view for the admin interface.'),
      ),
merlinofchaos's avatar
merlinofchaos committed
45 46 47 48 49 50
      'tag' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('A tag used to group/sort views in the admin interface'),
      ),
51
      'view_php' => array(
merlinofchaos's avatar
merlinofchaos committed
52
        'type' => 'blob',
53 54 55 56
        'default' => '',
        'description' => t('A chunk of PHP code that can be used to provide modifications to the view prior to building.'),
      ),
      'base_table' => array(
merlinofchaos's avatar
merlinofchaos committed
57 58
        'type' => 'varchar',
        'length' => '32',
59
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
60
        'not null' => TRUE,
61 62 63
        'description' => t('What table this view is based on, such as node, user, comment, or term.'),
      ),
      'is_cacheable' => array(
merlinofchaos's avatar
merlinofchaos committed
64
        'type' => 'int',
65 66 67 68 69 70 71 72 73 74 75 76 77
        'default' => 0,
        'size' => 'tiny',
        'description' => t('A boolean to indicate whether or not this view may have its query cached.'),
      ),
    ),
    'primary key' => array('vid'),
    'unique key' => array('name' => array('name')),
  );

  $schema['views_display'] = array(
    'description' => t('Stores information about each display attached to a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
78 79 80
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
81 82 83 84 85
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'display_plugin' => array(
merlinofchaos's avatar
merlinofchaos committed
86 87
        'type' => 'varchar',
        'length' => '64',
88
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
89
        'not null' => TRUE,
90 91 92
        'description' => t('The type of the display. Usually page, block or embed, but is pluggable so may be other things.'),
      ),
      'id' => array(
merlinofchaos's avatar
merlinofchaos committed
93 94
        'type' => 'varchar',
        'length' => '64',
95
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
96
        'not null' => TRUE,
97 98 99 100 101 102 103 104 105 106
        'description' => t('An identifier for this display; usually generated from the display_plugin, so should be something like page or page_1 or block_2, etc.'),
      ),
      'access' => array(
        'type' => 'varchar',
        'length' => 255,
        'description' => t('A serialized array describing who can access this display of the view.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
      'style_plugin' => array(
merlinofchaos's avatar
merlinofchaos committed
107 108
        'type' => 'varchar',
        'length' => '64',
109
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
110
        'not null' => TRUE,
111 112 113
        'description' => t('The output type of the display. Usually list, table, teasers or nodes, but is pluggable so may be other things.'),
      ),
      'title' => array(
merlinofchaos's avatar
merlinofchaos committed
114 115
        'type' => 'varchar',
        'length' => '255',
116
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
117
        'not null' => TRUE,
118 119 120
        'description' => t('The title to use for this display.'),
      ),
      'header' => array(
merlinofchaos's avatar
merlinofchaos committed
121
        'type' => 'blob',
122 123 124 125 126 127 128 129
        'description' => t('Text to display for the header.'),
      ),
      'header_format' => array(
        'type' => 'int',
        'default' => FILTER_FORMAT_DEFAULT,
        'description' => t('The output format for the header.'),
      ),
      'header_hide_empty' => array(
merlinofchaos's avatar
merlinofchaos committed
130
        'type' => 'int',
131 132 133 134 135
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, hide the header when the view has no records to display.'),
      ),
      'footer' => array(
merlinofchaos's avatar
merlinofchaos committed
136
        'type' => 'blob',
137 138 139 140 141 142 143 144
        'description' => t('Text to display for the footer.'),
      ),
      'footer_format' => array(
        'type' => 'int',
        'default' => FILTER_FORMAT_DEFAULT,
        'description' => t('The output format for the footer.'),
      ),
      'footer_hide_empty' => array(
merlinofchaos's avatar
merlinofchaos committed
145
        'type' => 'int',
146 147 148 149 150
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, hide the footer when the view has no records to display.'),
      ),
      'empty' => array(
merlinofchaos's avatar
merlinofchaos committed
151
        'type' => 'blob',
152 153 154 155 156 157 158 159
        'description' => t('Text to display if the view produces no records.'),
      ),
      'empty_format' => array(
        'type' => 'int',
        'default' => FILTER_FORMAT_DEFAULT,
        'description' => t('The output format for the empty text.'),
      ),
      'use_pager' => array(
merlinofchaos's avatar
merlinofchaos committed
160
        'type' => 'int',
161 162 163 164 165
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, this display will utilize the pager.'),
      ),
      'url' => array(
merlinofchaos's avatar
merlinofchaos committed
166 167
        'type' => 'varchar',
        'length' => '255',
168 169 170 171 172 173 174 175 176
        'description' => t('The URL of the display, if applicable.'),
      ),
      'block' => array(
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
        'description' => t('True if the display responds to hook_block; false otherwise.'),
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
177
        'type' => 'int',
178 179 180 181
        'default' => 0,
        'description' => t('The order in which this display is loaded.'),
      ),
      'display_options' => array(
merlinofchaos's avatar
merlinofchaos committed
182
        'type' => 'blob',
183 184 185 186 187
        'description' => t('A serialized array of options for this display; it contains options that are generally only pertinent to that display plugin type.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
      'style_options' => array(
merlinofchaos's avatar
merlinofchaos committed
188
        'type' => 'blob',
189 190 191 192 193
        'description' => t('A serialized array of options for this display\'s style plugin; it contains options that are generally only pertinent to that type.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
      'filter_options' => array(
merlinofchaos's avatar
merlinofchaos committed
194
        'type' => 'blob',
195 196 197
        'description' => t('A serialized array of options for this display\'s exposed filters.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
198
      ),
199 200 201 202 203 204 205 206
    ),
    'indexes' => array('vid' => array('vid', 'position')),
  );

  $schema['views_argument'] = array(
    'description' => t('Stores information about each argument attached to a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
207 208 209
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
210 211 212 213 214
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
215
        'type' => 'int',
216 217 218 219
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
220 221
        'type' => 'varchar',
        'length' => '255',
222 223 224
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
225 226
        'type' => 'varchar',
        'length' => '255',
227 228 229
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
230 231
        'type' => 'varchar',
        'length' => '255',
232 233 234
        'description' => t('The relationship this field belongs to.'),
      ),
      'type' => array(
merlinofchaos's avatar
merlinofchaos committed
235 236
        'type' => 'varchar',
        'length' => '64',
237
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
238
        'not null' => TRUE,
239 240 241
        'description' => t('The type of the display. Usually page, block or embed, but is pluggable so may be other things.'),
      ),
      'style' => array(
merlinofchaos's avatar
merlinofchaos committed
242 243
        'type' => 'varchar',
        'length' => '64',
244
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
245
        'not null' => TRUE,
246 247 248
        'description' => t('The type of the display. Usually page, block or embed, but is pluggable so may be other things.'),
      ),
      'default_action' => array(
merlinofchaos's avatar
merlinofchaos committed
249 250
        'type' => 'varchar',
        'length' => '32',
251
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
252
        'not null' => TRUE,
253 254 255
        'description' => t('What to do if this argument is not present.'),
      ),
      'title' => array(
merlinofchaos's avatar
merlinofchaos committed
256 257
        'type' => 'varchar',
        'length' => '255',
258
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
259
        'not null' => TRUE,
260 261 262
        'description' => t('The title to use if this argument is present.'),
      ),
      'wildcard' => array(
merlinofchaos's avatar
merlinofchaos committed
263 264
        'type' => 'varchar',
        'length' => '32',
265 266 267 268
        'default' => '*',
        'description' => t('What to use for a wildcard in the URL for this argument.'),
      ),
      'wildcard_text' => array(
merlinofchaos's avatar
merlinofchaos committed
269
        'type' => 'varchar',
270 271 272 273 274
        'length' => '64',
        'default' => t('All'),
        'description' => t('The textual representation of the argument, for use in titles. For example, if the argument is *, the text represnation might be "all".'),
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
275
        'type' => 'blob',
276 277 278
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
279
      ),
280 281 282 283 284 285 286 287
    ),
    'indexes' => array('vid' => array('vid', 'position')),
  );

  $schema['views_field'] = array(
    'description' => t('Stores information about each field attached to a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
288 289 290
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
291 292 293 294 295
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
296
        'type' => 'int',
297 298 299 300
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'display_id' => array(
merlinofchaos's avatar
merlinofchaos committed
301
        'type' => 'int',
302 303 304 305
        'default' => 0,
        'description' => t('The display for which these fields are valid.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
306 307
        'type' => 'varchar',
        'length' => '255',
308 309 310
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
311 312
        'type' => 'varchar',
        'length' => '255',
313 314 315
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
316 317
        'type' => 'varchar',
        'length' => '255',
318 319 320
        'description' => t('The relationship this field belongs to.'),
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
321
        'type' => 'blob',
322 323 324
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
325
      ),
326 327 328 329 330 331 332 333
    ),
    'indexes' => array('vid' => array('vid', 'position')),
  );

  $schema['views_sort'] = array(
    'description' => t('Stores information about each sort criterion attached to a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
334 335 336
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
337 338 339 340 341
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
342
        'type' => 'int',
343 344 345 346
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
347 348
        'type' => 'varchar',
        'length' => '255',
349 350 351
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
352 353
        'type' => 'varchar',
        'length' => '255',
354 355 356
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
357 358
        'type' => 'varchar',
        'length' => '255',
359 360 361
        'description' => t('The relationship this field belongs to.'),
      ),
      'order' => array(
merlinofchaos's avatar
merlinofchaos committed
362 363
        'type' => 'varchar',
        'length' => '4',
364 365 366
        'description' => t('Either ASC or DESC.'),
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
367
        'type' => 'blob',
368 369 370
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
371
      ),
372
      'exposed' => array(
merlinofchaos's avatar
merlinofchaos committed
373
        'type' => 'int',
374 375 376 377 378
        'default' => 0,
        'size' => 'tiny',
        'description' => t('True if this sort is exposed in the UI.'),
      ),
      'exposed_options' => array(
merlinofchaos's avatar
merlinofchaos committed
379
        'type' => 'blob',
380 381 382
        'description' => t('A serialized array of options for exposed sorts.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
383
      ),
384 385 386 387 388 389 390 391
    ),
    'indexes' => array('vid' => array('vid', 'position')),
  );

  $schema['views_filter'] = array(
    'description' => t('Stores information about each filter attached to a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
392 393 394
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
395 396 397 398 399
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
400
        'type' => 'int',
401 402 403 404
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'group' => array(
merlinofchaos's avatar
merlinofchaos committed
405
        'type' => 'int',
406 407 408 409
        'default' => 0,
        'description' => t('Which filter group this filter belongs to, so that AND and OR can be separated properly.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
410 411
        'type' => 'varchar',
        'length' => '255',
412 413 414
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
415 416
        'type' => 'varchar',
        'length' => '255',
417 418 419
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
420 421
        'type' => 'varchar',
        'length' => '255',
422 423 424
        'description' => t('The relationship this field belongs to.'),
      ),
      'operator' => array(
merlinofchaos's avatar
merlinofchaos committed
425 426
        'type' => 'varchar',
        'length' => '255',
427 428 429
        'description' => t('The operator for this filter. For example, == or > or <.'),
      ),
      'value' => array(
merlinofchaos's avatar
merlinofchaos committed
430 431
        'type' => 'varchar',
        'length' => '255',
432 433 434 435 436
        'description' => t('The value being tested for this filter.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
437
        'type' => 'blob',
438 439 440
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
441
      ),
442
      'exposed' => array(
merlinofchaos's avatar
merlinofchaos committed
443
        'type' => 'int',
444 445 446 447 448
        'default' => 0,
        'size' => 'tiny',
        'description' => t('True if this filter is exposed in the UI.'),
      ),
      'exposed_options' => array(
merlinofchaos's avatar
merlinofchaos committed
449
        'type' => 'blob',
450 451 452
        'description' => t('A serialized array of options for exposed filters.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
453
      ),
454 455 456 457 458 459 460 461
    ),
    'indexes' => array('vid' => array('vid', 'position')),
  );

  $schema['views_relationship'] = array(
    'description' => t('Stores information about each filter attached to a view.'),
    'fields' => array(
      'vid' => array(
merlinofchaos's avatar
merlinofchaos committed
462 463 464
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
465 466 467 468 469
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
470
        'type' => 'int',
471 472 473 474
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
475 476
        'type' => 'varchar',
        'length' => '255',
477 478 479
        'description' => t('The actual relationship used.'),
      ),
      'link' => array(
merlinofchaos's avatar
merlinofchaos committed
480 481
        'type' => 'varchar',
        'length' => '255',
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
        'description' => t('The relationship this links back to.'),
      ),
    ),
    'indexes' => array('vid' => array('vid', 'position')),
  );

  // This is unfortunately cut & pasted from system.module since cache has no way of
  // telling us what the proper schema is.
  $schema['cache_views'] = array(
    'fields' => array(
      'cid'        => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
      'data'       => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
      'expire'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'created'    => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'headers'    => array('type' => 'text', 'not null' => FALSE),
      'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
    ),
    'indexes' => array('expire' => array('expire')),
    'primary key' => array('cid'),
  );

merlinofchaos's avatar
merlinofchaos committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
  $schema['views_object_cache'] = array(
    'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'),
    'fields' => array(
      'sid' => array(
        'type' => 'varchar',
        'length' => '64',
        'description' => t('The session ID this cache object belongs to.'),
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => '32',
        'description' => t('The name of the view this cache is attached to.'),
      ),
      'obj' => array(
        'type' => 'varchar',
        'length' => '32',
        'description' => t('The name of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.'),
      ),
      'updated' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('The time this cache was created or updated.'),
      ),
      'data' => array(
        'type' => 'blob',
        'default' => '',
        'description' => t('Serialized data being stored.'),
        'serialize' => TRUE,
      ),
    ),
    'indexes' => array(
      'sid_obj_name' => array('sid', 'obj', 'name'),
      'updated' => array('updated'),
    ),
  );
540 541
  return $schema;
}