views.install 18.3 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
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
merlinofchaos's avatar
merlinofchaos committed
85
      'id' => array(
merlinofchaos's avatar
merlinofchaos committed
86 87
        'type' => 'varchar',
        'length' => '64',
88
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
89
        'not null' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
90
        '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.'),
91
      ),
merlinofchaos's avatar
merlinofchaos committed
92
      'display_title' => array(
merlinofchaos's avatar
merlinofchaos committed
93 94
        'type' => 'varchar',
        'length' => '64',
95
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
96
        'not null' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
97 98 99 100 101 102 103 104
        'description' => t('The title of the display, viewable by the administrator.'),
      ),
      'display_plugin' => array(
        'type' => 'varchar',
        'length' => '64',
        'default' => '',
        'not null' => TRUE,
        'description' => t('The type of the display. Usually page, block or embed, but is pluggable so may be other things.'),
105 106 107 108 109 110 111 112 113
      ),
      '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
114 115
        'type' => 'varchar',
        'length' => '64',
116
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
117
        'not null' => TRUE,
118 119 120
        '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
121 122
        'type' => 'varchar',
        'length' => '255',
123
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
124
        'not null' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
125
        'description' => t('The title of the view use for this display.'),
126 127
      ),
      'header' => array(
merlinofchaos's avatar
merlinofchaos committed
128
        'type' => 'blob',
129 130 131 132 133 134 135 136
        '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
137
        'type' => 'int',
138 139 140 141 142
        '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
143
        'type' => 'blob',
144 145 146 147 148 149 150 151
        '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
152
        'type' => 'int',
153 154 155 156 157
        '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
158
        'type' => 'blob',
159 160 161 162 163 164 165 166
        '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
167
        'type' => 'int',
168 169 170 171 172
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, this display will utilize the pager.'),
      ),
      'url' => array(
merlinofchaos's avatar
merlinofchaos committed
173 174
        'type' => 'varchar',
        'length' => '255',
175 176 177 178 179 180 181 182 183
        '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
184
        'type' => 'int',
185 186 187 188
        'default' => 0,
        'description' => t('The order in which this display is loaded.'),
      ),
      'display_options' => array(
merlinofchaos's avatar
merlinofchaos committed
189
        'type' => 'blob',
190 191 192 193 194
        '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
195
        'type' => 'blob',
196 197 198 199 200
        '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
201
        'type' => 'blob',
202 203 204
        'description' => t('A serialized array of options for this display\'s exposed filters.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
205
      ),
206 207 208 209 210 211 212 213
    ),
    '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
214 215 216
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
217 218 219 220 221
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
222
        'type' => 'int',
223 224 225 226
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
227 228
        'type' => 'varchar',
        'length' => '255',
229 230 231
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
232 233
        'type' => 'varchar',
        'length' => '255',
234 235 236
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
237 238
        'type' => 'varchar',
        'length' => '255',
239 240 241
        'description' => t('The relationship this field belongs to.'),
      ),
      'type' => 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.'),
      ),
      'style' => array(
merlinofchaos's avatar
merlinofchaos committed
249 250
        'type' => 'varchar',
        'length' => '64',
251
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
252
        'not null' => TRUE,
253 254 255
        '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
256 257
        'type' => 'varchar',
        'length' => '32',
258
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
259
        'not null' => TRUE,
260 261 262
        'description' => t('What to do if this argument is not present.'),
      ),
      'title' => array(
merlinofchaos's avatar
merlinofchaos committed
263 264
        'type' => 'varchar',
        'length' => '255',
265
        'default' => '',
merlinofchaos's avatar
merlinofchaos committed
266
        'not null' => TRUE,
267 268 269
        'description' => t('The title to use if this argument is present.'),
      ),
      'wildcard' => array(
merlinofchaos's avatar
merlinofchaos committed
270 271
        'type' => 'varchar',
        'length' => '32',
272 273 274 275
        'default' => '*',
        'description' => t('What to use for a wildcard in the URL for this argument.'),
      ),
      'wildcard_text' => array(
merlinofchaos's avatar
merlinofchaos committed
276
        'type' => 'varchar',
277 278 279 280 281
        '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
282
        'type' => 'blob',
283 284 285
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
286
      ),
287 288 289 290 291 292 293 294
    ),
    '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
295 296 297
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
298 299 300 301 302
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
303
        'type' => 'int',
304 305 306 307
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'display_id' => array(
merlinofchaos's avatar
merlinofchaos committed
308
        'type' => 'int',
309 310 311 312
        'default' => 0,
        'description' => t('The display for which these fields are valid.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
313 314
        'type' => 'varchar',
        'length' => '255',
315 316 317
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
318 319
        'type' => 'varchar',
        'length' => '255',
320 321 322
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
323 324
        'type' => 'varchar',
        'length' => '255',
325 326 327
        'description' => t('The relationship this field belongs to.'),
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
328
        'type' => 'blob',
329 330 331
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
332
      ),
333 334 335 336 337 338 339 340
    ),
    '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
341 342 343
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
344 345 346 347 348
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
349
        'type' => 'int',
350 351 352 353
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'tablename' => array(
merlinofchaos's avatar
merlinofchaos committed
354 355
        'type' => 'varchar',
        'length' => '255',
356 357 358
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
359 360
        'type' => 'varchar',
        'length' => '255',
361 362 363
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
364 365
        'type' => 'varchar',
        'length' => '255',
366 367 368
        'description' => t('The relationship this field belongs to.'),
      ),
      'order' => array(
merlinofchaos's avatar
merlinofchaos committed
369 370
        'type' => 'varchar',
        'length' => '4',
371 372 373
        'description' => t('Either ASC or DESC.'),
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
374
        'type' => 'blob',
375 376 377
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
378
      ),
379
      'exposed' => array(
merlinofchaos's avatar
merlinofchaos committed
380
        'type' => 'int',
381 382 383 384 385
        'default' => 0,
        'size' => 'tiny',
        'description' => t('True if this sort is exposed in the UI.'),
      ),
      'exposed_options' => array(
merlinofchaos's avatar
merlinofchaos committed
386
        'type' => 'blob',
387 388 389
        'description' => t('A serialized array of options for exposed sorts.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
390
      ),
391 392 393 394 395 396 397 398
    ),
    '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
399 400 401
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
402 403 404 405 406
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
407
        'type' => 'int',
408 409 410 411
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'group' => array(
merlinofchaos's avatar
merlinofchaos committed
412
        'type' => 'int',
413 414 415 416
        '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
417 418
        'type' => 'varchar',
        'length' => '255',
419 420 421
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
merlinofchaos's avatar
merlinofchaos committed
422 423
        'type' => 'varchar',
        'length' => '255',
424 425 426
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
427 428
        'type' => 'varchar',
        'length' => '255',
429 430 431
        'description' => t('The relationship this field belongs to.'),
      ),
      'operator' => array(
merlinofchaos's avatar
merlinofchaos committed
432 433
        'type' => 'varchar',
        'length' => '255',
434 435 436
        'description' => t('The operator for this filter. For example, == or > or <.'),
      ),
      'value' => array(
merlinofchaos's avatar
merlinofchaos committed
437 438
        'type' => 'varchar',
        'length' => '255',
439 440 441 442 443
        'description' => t('The value being tested for this filter.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
      'options' => array(
merlinofchaos's avatar
merlinofchaos committed
444
        'type' => 'blob',
445 446 447
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
448
      ),
449
      'exposed' => array(
merlinofchaos's avatar
merlinofchaos committed
450
        'type' => 'int',
451 452 453 454 455
        'default' => 0,
        'size' => 'tiny',
        'description' => t('True if this filter is exposed in the UI.'),
      ),
      'exposed_options' => array(
merlinofchaos's avatar
merlinofchaos committed
456
        'type' => 'blob',
457 458 459
        'description' => t('A serialized array of options for exposed filters.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
merlinofchaos's avatar
merlinofchaos committed
460
      ),
461 462 463 464 465 466 467 468
    ),
    '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
469 470 471
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
472 473 474 475 476
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
merlinofchaos's avatar
merlinofchaos committed
477
        'type' => 'int',
478 479 480 481
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'relationship' => array(
merlinofchaos's avatar
merlinofchaos committed
482 483
        'type' => 'varchar',
        'length' => '255',
484 485 486
        'description' => t('The actual relationship used.'),
      ),
      'link' => array(
merlinofchaos's avatar
merlinofchaos committed
487 488
        'type' => 'varchar',
        'length' => '255',
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
        '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
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 540 541 542 543 544 545 546
  $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'),
    ),
  );
547 548
  return $schema;
}