~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/views/views.install

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: views.install,v 1.46 2009/04/07 20:39:51 merlinofchaos Exp $
 
3
/**
 
4
 * @file views.install
 
5
 * Contains install and update functions for Views.
 
6
 */
 
7
 
 
8
function views_install() {
 
9
  drupal_install_schema('views');
 
10
  db_query("UPDATE {system} SET weight = 10 WHERE name = 'views'");
 
11
}
 
12
 
 
13
function views_uninstall() {
 
14
  drupal_uninstall_schema('views');
 
15
}
 
16
 
 
17
/**
 
18
 * Implementation of hook_schemea
 
19
 */
 
20
function views_schema() {
 
21
  // Currently, schema 1 is the only schema we have. As we make updates,
 
22
  // we might either create a new schema 2 or make adjustments here.
 
23
  return views_schema_1();
 
24
}
 
25
 
 
26
/**
 
27
 * Views 2's initial schema; separated for the purposes of updates.
 
28
 */
 
29
function views_schema_1() {
 
30
  $schema['views_view'] = array(
 
31
    'description' => 'Stores the general data for a view.',
 
32
    'fields' => array(
 
33
      'vid' => array(
 
34
        'type' => 'serial',
 
35
        'unsigned' => TRUE,
 
36
        'not null' => TRUE,
 
37
        'description' => 'The view ID of the field, defined by the database.',
 
38
        'no export' => TRUE,
 
39
      ),
 
40
      'name' => array(
 
41
        'type' => 'varchar',
 
42
        'length' => '32',
 
43
        'default' => '',
 
44
        'not null' => TRUE,
 
45
        'description' => '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.',
 
46
      ),
 
47
      'description' => array(
 
48
        'type' => 'varchar',
 
49
        'length' => '255',
 
50
        'default' => '',
 
51
        'description' => 'A description of the view for the admin interface.',
 
52
      ),
 
53
      'tag' => array(
 
54
        'type' => 'varchar',
 
55
        'length' => '255',
 
56
        'default' => '',
 
57
        'description' => 'A tag used to group/sort views in the admin interface',
 
58
      ),
 
59
      'view_php' => array(
 
60
        'type' => 'blob',
 
61
        'description' => 'A chunk of PHP code that can be used to provide modifications to the view prior to building.',
 
62
      ),
 
63
      'base_table' => array(
 
64
        'type' => 'varchar',
 
65
        'length' => '32',
 
66
        'default' => '',
 
67
        'not null' => TRUE,
 
68
        'description' => 'What table this view is based on, such as node, user, comment, or term.',
 
69
      ),
 
70
      'is_cacheable' => array(
 
71
        'type' => 'int',
 
72
        'default' => 0,
 
73
        'size' => 'tiny',
 
74
        'description' => 'A boolean to indicate whether or not this view may have its query cached.',
 
75
      ),
 
76
    ),
 
77
    'primary key' => array('vid'),
 
78
    'unique keys' => array('name' => array('name')),
 
79
  );
 
80
 
 
81
  $schema['views_display'] = array(
 
82
    'description' => 'Stores information about each display attached to a view.',
 
83
    'fields' => array(
 
84
      'vid' => array(
 
85
        'type' => 'int',
 
86
        'unsigned' => TRUE,
 
87
        'not null' => TRUE,
 
88
        'default' => 0,
 
89
        'description' => 'The view this display is attached to.',
 
90
        'no export' => TRUE,
 
91
      ),
 
92
      'id' => array(
 
93
        'type' => 'varchar',
 
94
        'length' => '64',
 
95
        'default' => '',
 
96
        'not null' => TRUE,
 
97
        'description' => 'An identifier for this display; usually generated from the display_plugin, so should be something like page or page_1 or block_2, etc.',
 
98
      ),
 
99
      'display_title' => array(
 
100
        'type' => 'varchar',
 
101
        'length' => '64',
 
102
        'default' => '',
 
103
        'not null' => TRUE,
 
104
        'description' => 'The title of the display, viewable by the administrator.',
 
105
      ),
 
106
      'display_plugin' => array(
 
107
        'type' => 'varchar',
 
108
        'length' => '64',
 
109
        'default' => '',
 
110
        'not null' => TRUE,
 
111
        'description' => 'The type of the display. Usually page, block or embed, but is pluggable so may be other things.',
 
112
      ),
 
113
      'position' => array(
 
114
        'type' => 'int',
 
115
        'default' => 0,
 
116
        'description' => 'The order in which this display is loaded.',
 
117
      ),
 
118
      'display_options' => array(
 
119
        'type' => 'blob',
 
120
        'description' => 'A serialized array of options for this display; it contains options that are generally only pertinent to that display plugin type.',
 
121
        'serialize' => TRUE,
 
122
        'serialized default' => 'a:0:{}',
 
123
      ),
 
124
    ),
 
125
    'indexes' => array('vid' => array('vid', 'position')),
 
126
  );
 
127
 
 
128
  $schema['cache_views'] = drupal_get_schema_unprocessed('system', 'cache');
 
129
 
 
130
  $schema['views_object_cache'] = array(
 
131
    'description' => 'A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.',
 
132
    'fields' => array(
 
133
      'sid' => array(
 
134
        'type' => 'varchar',
 
135
        'length' => '64',
 
136
        'description' => 'The session ID this cache object belongs to.',
 
137
      ),
 
138
      'name' => array(
 
139
        'type' => 'varchar',
 
140
        'length' => '32',
 
141
        'description' => 'The name of the view this cache is attached to.',
 
142
      ),
 
143
      'obj' => array(
 
144
        'type' => 'varchar',
 
145
        'length' => '32',
 
146
        'description' => 'The name of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.',
 
147
      ),
 
148
      'updated' => array(
 
149
        'type' => 'int',
 
150
        'unsigned' => TRUE,
 
151
        'not null' => TRUE,
 
152
        'default' => 0,
 
153
        'description' => 'The time this cache was created or updated.',
 
154
      ),
 
155
      'data' => array(
 
156
        'type' => 'text',
 
157
        'size' => 'big',
 
158
        'description' => 'Serialized data being stored.',
 
159
        'serialize' => TRUE,
 
160
      ),
 
161
    ),
 
162
    'indexes' => array(
 
163
      'sid_obj_name' => array('sid', 'obj', 'name'),
 
164
      'updated' => array('updated'),
 
165
    ),
 
166
  );
 
167
  return $schema;
 
168
}
 
169
 
 
170
/**
 
171
 * Update a site to Drupal 6! Contains a bit of special code to detect
 
172
 * if you've been running a beta version or something.
 
173
 */
 
174
function views_update_6000() {
 
175
  $ret = array();
 
176
  if (db_table_exists('views_view')) {
 
177
    return $ret;
 
178
  }
 
179
 
 
180
  // This has the beneficial effect of wiping out any Views 1 cache at the
 
181
  // same time; not wiping that cache could easily cause problems with Views 2.
 
182
  if (db_table_exists('cache_views')) {
 
183
    db_drop_table($ret, 'cache_views');
 
184
  }
 
185
 
 
186
  // This is mostly the same as drupal_install_schema, but it forces
 
187
  // views_schema_1 rather than the default schema. This will be important
 
188
  // if we have table updates.
 
189
  $schema = views_schema_1();
 
190
  _drupal_initialize_schema('views', $schema);
 
191
 
 
192
  foreach ($schema as $name => $table) {
 
193
    db_create_table($ret, $name, $table);
 
194
  }
 
195
  return $ret;
 
196
}
 
197
 
 
198
function views_update_6001() {
 
199
  $ret = array();
 
200
  $result = db_query("SELECT * FROM {blocks} WHERE module = 'views' AND delta LIKE '\$exp%'");
 
201
  while ($block = db_fetch_object($result)) {
 
202
    $new = strtr($block->delta, '$', '-');
 
203
    $ret[] = update_sql("UPDATE {blocks} SET delta = '" . db_escape_string($new) . "' WHERE module = 'views' AND delta = '" . db_escape_string($block->delta) . "'");
 
204
  }
 
205
 
 
206
  return $ret;
 
207
}
 
208
 
 
209
// NOTE: Update 6002 removed because it did not always work.
 
210
/**
 
211
 * Add missing unique key.
 
212
 */
 
213
function views_update_6003() {
 
214
  $ret = array();
 
215
 
 
216
  db_add_unique_key($ret, 'views_view', 'name', array('name'));
 
217
 
 
218
  return $ret;
 
219
}
 
220
 
 
221
/**
 
222
 * Enlarge the views_object_cache.data column to prevent truncation and JS
 
223
 * errors.
 
224
 */
 
225
function views_update_6004() {
 
226
  $ret = array();
 
227
 
 
228
  $new_field = array(
 
229
    'type' => 'text',
 
230
    'size' => 'big',
 
231
    'description' => 'Serialized data being stored.',
 
232
    'serialize' => TRUE,
 
233
  );
 
234
 
 
235
  // Drop and re-add this field because there is a bug in
 
236
  // db_change_field that causes this to fail when trying to cast the data.
 
237
  db_drop_field($ret, 'views_object_cache', 'data');
 
238
  db_add_field($ret, 'views_object_cache', 'data', $new_field);
 
239
 
 
240
  return $ret;
 
241
}