2 // $Id: views.install,v 1.46 2009/04/07 20:39:51 merlinofchaos Exp $
5 * Contains install and update functions for Views.
8 function views_install() {
9 drupal_install_schema('views');
10 db_query("UPDATE {system} SET weight = 10 WHERE name = 'views'");
13 function views_uninstall() {
14 drupal_uninstall_schema('views');
18 * Implementation of hook_schemea
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();
27 * Views 2's initial schema; separated for the purposes of updates.
29 function views_schema_1() {
30 $schema['views_view'] = array(
31 'description' => 'Stores the general data for a view.',
37 'description' => 'The view ID of the field, defined by the database.',
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.',
47 'description' => array(
51 'description' => 'A description of the view for the admin interface.',
57 'description' => 'A tag used to group/sort views in the admin interface',
61 'description' => 'A chunk of PHP code that can be used to provide modifications to the view prior to building.',
63 'base_table' => array(
68 'description' => 'What table this view is based on, such as node, user, comment, or term.',
70 'is_cacheable' => array(
74 'description' => 'A boolean to indicate whether or not this view may have its query cached.',
77 'primary key' => array('vid'),
78 'unique keys' => array('name' => array('name')),
81 $schema['views_display'] = array(
82 'description' => 'Stores information about each display attached to a view.',
89 'description' => 'The view this display is attached to.',
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.',
99 'display_title' => array(
104 'description' => 'The title of the display, viewable by the administrator.',
106 'display_plugin' => array(
111 'description' => 'The type of the display. Usually page, block or embed, but is pluggable so may be other things.',
116 'description' => 'The order in which this display is loaded.',
118 'display_options' => array(
120 'description' => 'A serialized array of options for this display; it contains options that are generally only pertinent to that display plugin type.',
122 'serialized default' => 'a:0:{}',
125 'indexes' => array('vid' => array('vid', 'position')),
128 $schema['cache_views'] = drupal_get_schema_unprocessed('system', 'cache');
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.',
136 'description' => 'The session ID this cache object belongs to.',
141 'description' => 'The name of the view this cache is attached to.',
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.',
153 'description' => 'The time this cache was created or updated.',
158 'description' => 'Serialized data being stored.',
163 'sid_obj_name' => array('sid', 'obj', 'name'),
164 'updated' => array('updated'),
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.
174 function views_update_6000() {
176 if (db_table_exists('views_view')) {
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');
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);
192 foreach ($schema as $name => $table) {
193 db_create_table($ret, $name, $table);
198 function views_update_6001() {
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) . "'");
209 // NOTE: Update 6002 removed because it did not always work.
211 * Add missing unique key.
213 function views_update_6003() {
216 db_add_unique_key($ret, 'views_view', 'name', array('name'));
222 * Enlarge the views_object_cache.data column to prevent truncation and JS
225 function views_update_6004() {
231 'description' => 'Serialized data being stored.',
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);