views.install 16.7 KB
Newer Older
1
<?php
2
// $Id$
3
/**
4 5
 * @file views.install
 * Contains install and update functions for Views.
6
 */
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 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498

/**
 * Implementation of hook_schema
 */
function views_schema() {
  $schema['views_view'] = array(
    'description' => t('Stores the general data for a view.'),
    'fields' => array(
      'vid' => array(
        'type' => 'serial', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'description' => t('The view ID of the field, defined by the database.'),
        'no export' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar', 
        'length' => '32', 
        'default' => '',
        'not null' => TRUE, 
        '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(
        'type' => 'varchar', 
        'length' => '255', 
        'default' => '',
        'description' => t('A description of the view for the admin interface.'),
      ),
      'view_php' => array(
        'type' => 'blob', 
        'default' => '',
        'description' => t('A chunk of PHP code that can be used to provide modifications to the view prior to building.'),
      ),
      'base_table' => array(
        'type' => 'varchar', 
        'length' => '32', 
        'default' => '',
        'not null' => TRUE, 
        'description' => t('What table this view is based on, such as node, user, comment, or term.'),
      ),
      'is_cacheable' => array(
        'type' => 'int', 
        '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(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      '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.'),
      ),
      'id' => array(
        'type' => 'varchar', 
        'length' => '64', 
        'default' => '',
        'not null' => TRUE, 
        '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(
        'type' => 'varchar', 
        'length' => '64', 
        'default' => '',
        'not null' => TRUE, 
        'description' => t('The output type of the display. Usually list, table, teasers or nodes, but is pluggable so may be other things.'),
      ),
      'title' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'default' => '',
        'not null' => TRUE, 
        'description' => t('The title to use for this display.'),
      ),
      'header' => array(
        'type' => 'blob', 
        '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(
        'type' => 'int', 
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, hide the header when the view has no records to display.'),
      ),
      'footer' => array(
        'type' => 'blob', 
        '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(
        'type' => 'int', 
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, hide the footer when the view has no records to display.'),
      ),
      'empty' => array(
        'type' => 'blob', 
        '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(
        'type' => 'int', 
        'default' => 1,
        'size' => 'tiny',
        'description' => t('If true, this display will utilize the pager.'),
      ),
      'url' => array(
        'type' => 'varchar', 
        'length' => '255', 
        '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(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The order in which this display is loaded.'),
      ),
      'display_options' => array(
        'type' => 'blob', 
        '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(
        'type' => 'blob', 
        '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(
        'type' => 'blob', 
        'description' => t('A serialized array of options for this display\'s exposed filters.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
    ),
    '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(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'tablename' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The relationship this field belongs to.'),
      ),
      'type' => 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.'),
      ),
      'style' => 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.'),
      ),
      'default_action' => array(
        'type' => 'varchar', 
        'length' => '32', 
        'default' => '',
        'not null' => TRUE, 
        'description' => t('What to do if this argument is not present.'),
      ),
      'title' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'default' => '',
        'not null' => TRUE, 
        'description' => t('The title to use if this argument is present.'),
      ),
      'wildcard' => array(
        'type' => 'varchar', 
        'length' => '32', 
        'default' => '*',
        'description' => t('What to use for a wildcard in the URL for this argument.'),
      ),
      'wildcard_text' => array(
        'type' => 'varchar', 
        '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(
        'type' => 'blob', 
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
    ),
    '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(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'display_id' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The display for which these fields are valid.'),
      ),
      'tablename' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The relationship this field belongs to.'),
      ),
      'options' => array(
        'type' => 'blob', 
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
    ),
    '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(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'tablename' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The relationship this field belongs to.'),
      ),
      'order' => array(
        'type' => 'varchar', 
        'length' => '4', 
        'description' => t('Either ASC or DESC.'),
      ),
      'options' => array(
        'type' => 'blob', 
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
      'exposed' => array(
        'type' => 'int', 
        'default' => 0,
        'size' => 'tiny',
        'description' => t('True if this sort is exposed in the UI.'),
      ),
      'exposed_options' => array(
        'type' => 'blob', 
        'description' => t('A serialized array of options for exposed sorts.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
    ),
    '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(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'group' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('Which filter group this filter belongs to, so that AND and OR can be separated properly.'),
      ),
      'tablename' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the table this field is attached to.'),
      ),
      'field' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The name of the field.'),
      ),
      'relationship' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The relationship this field belongs to.'),
      ),
      'operator' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The operator for this filter. For example, == or > or <.'),
      ),
      'value' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The value being tested for this filter.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
      'options' => array(
        'type' => 'blob', 
        'description' => t('A serialized array of options for this field.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
      'exposed' => array(
        'type' => 'int', 
        'default' => 0,
        'size' => 'tiny',
        'description' => t('True if this filter is exposed in the UI.'),
      ),
      'exposed_options' => array(
        'type' => 'blob', 
        'description' => t('A serialized array of options for exposed filters.'),
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),      
    ),
    '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(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => TRUE, 
        'default' => 0,
        'description' => t('The view this display is attached to.'),
        'no export' => TRUE,
      ),
      'position' => array(
        'type' => 'int', 
        'default' => 0,
        'description' => t('The order in which this information is loaded.'),
      ),
      'relationship' => array(
        'type' => 'varchar', 
        'length' => '255', 
        'description' => t('The actual relationship used.'),
      ),
      'link' => array(
        'type' => 'varchar', 
        'length' => '255', 
        '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'),
  );

  return $schema;
}