views.install 9.84 KB
Newer Older
1
<?php
2
  // $Id$
3 4

  function views_install() {
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    drupal_set_message('Installing views');
    switch ($GLOBALS['db_type']) {
      case 'mysqli':
      case 'mysql':
      db_query("CREATE TABLE if not exists {view_view} (
        vid int(10) unsigned NOT NULL default '0',
        name varchar(32) NOT NULL UNIQUE,
        description varchar(255),
        access varchar(255),
        -- page fields
        page int(1),
        page_title varchar(255),
        page_header longtext,
        page_header_format int(4) NOT NULL,
        page_empty longtext,
        page_empty_format int(4) NOT NULL,
merlinofchaos's avatar
merlinofchaos committed
21 22
        page_footer longtext,
        page_footer_format int(4) NOT NULL,
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
        page_type varchar(20),
        use_pager int(1),
        nodes_per_page int(2), -- yes, no more than 99
        url varchar(255),
        -- menu fields
        menu int(1),
        menu_tab int(1),
        menu_tab_default int(1),
        menu_tab_weight int(4),
        menu_title varchar(255),
        -- block fields
        block int(1),
        block_title varchar(255),
        block_use_page_header int(1),
        block_header longtext,
        block_header_format int(4) NOT NULL,
merlinofchaos's avatar
merlinofchaos committed
39 40 41
        block_use_page_footer int(1),
        block_footer longtext,
        block_footer_format int(4) NOT NULL,
42 43 44 45 46 47 48 49 50 51 52 53
        block_use_page_empty int(1),
        block_empty longtext,
        block_empty_format int(4) NOT NULL,
        block_type varchar(20),
        nodes_per_block int(5),
        block_more int(1),
        -- breadcrumb
        breadcrumb_no_home int(1), -- true means start breadcrumb trail from 'Home'.
        -- other
        changed int(11),
        query longtext,
        countquery longtext,
54
        view_args_php longtext,
55 56 57
        PRIMARY KEY (vid),
        KEY (name)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
58

59 60 61 62 63 64 65 66 67
      db_query("CREATE TABLE if not exists {view_sort} (
        vid int(10) unsigned NOT NULL default '0',
        position int(2),
        field varchar(255),
        sortorder varchar(5),
        options varchar(255),
        tablename varchar(255),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
68

69 70 71 72 73 74 75 76 77
      db_query("CREATE TABLE if not exists {view_argument} (
        vid int(10) unsigned NOT NULL default '0',
        type varchar(25),
        argdefault varchar(255),
        title varchar(255),
        options varchar(255),
        position int(2),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
78

79 80 81 82 83 84 85 86 87 88 89
      db_query("CREATE TABLE if not exists {view_tablefield} (
        vid int(10) unsigned NOT NULL default '0',
        tablename varchar(255),
        field varchar(255),
        label varchar(255),
        handler varchar(255),
        sortable int(1),
        defaultsort varchar(5),
        position int(2),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
90

91 92 93 94 95 96 97 98 99 100
      db_query("CREATE TABLE if not exists {view_filter} (
        vid int(10) unsigned NOT NULL default '0',
        tablename varchar(255),
        field varchar(255),
        value longtext,
        operator varchar(20),
        options varchar(255),
        position int(2),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
101

102
      db_query("CREATE TABLE if not exists {view_exposed_filter} (
103 104 105 106 107 108 109 110 111 112
        vid int(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional int(1),
        is_default int(1),
        operator int(1),
        single int(1),
        position int(2),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
113

114 115 116 117 118 119 120 121 122 123 124 125 126
      $success = TRUE;
      break;
    case 'pgsql':
      db_query("CREATE TABLE {view_view} (
        vid numeric(10) NOT NULL default '0',
        name varchar(32) NOT NULL UNIQUE,
        description varchar(255),
        access varchar(255),
        -- page fields
        page numeric(1),
        page_title varchar(255),
        page_header text,
        page_header_format numeric(4) NOT NULL,
127 128 129 130
        page_footer text,
        page_footer_format numeric(4) NOT NULL,
        page_empty text,
        page_empty_format numeric(4) NOT NULL,
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        page_type varchar(20),
        use_pager numeric(1),
        nodes_per_page numeric(2), -- yes, no more than 99
        url varchar(255),
        -- menu fields
        menu numeric(1),
        menu_tab numeric(1),
        menu_tab_default numeric(1),
        menu_tab_weight numeric(4),
        menu_title varchar(255),
        -- block fields
        block numeric(1),
        block_title varchar(255),
        block_use_page_header numeric(1),
        block_header text,
        block_header_format numeric(4) NOT NULL,
147 148 149 150 151 152
        block_use_page_footer numeric(1),
        block_footer text,
        block_footer_format numeric(4) NOT NULL,
        block_use_page_empty numeric(1),
        block_empty text,
        block_empty_format numeric(4) NOT NULL,
153 154 155 156 157 158 159 160 161
        block_type varchar(20),
        nodes_per_block numeric(5),
        block_more numeric(1),
        -- breadcrumb
        breadcrumb_no_home numeric(1), -- true means start breadcrumb trail from 'Home'.
        -- other
        changed numeric(11),
        query text,
        countquery text,
162
        view_args_php text,
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
        CONSTRAINT {view_view_pkey} PRIMARY KEY (vid)
      )");
      db_query("CREATE INDEX {view_view_name_idx} ON {view_view} (name)");

      db_query("CREATE TABLE {view_sort} (
        vid numeric(10) NOT NULL default '0',
        position numeric(2),
        field varchar(255),
        sortorder varchar(5),
        options varchar(255),
        tablename varchar(255)
      )");
      db_query("CREATE INDEX {view_sort_vid_idx} ON {view_sort} (vid)");

      db_query("CREATE TABLE {view_argument} (
        vid numeric(10) NOT NULL default '0',
        type varchar(25),
        argdefault varchar(255),
        title varchar(255),
        options varchar(255),
        position numeric(2)
      )");
      db_query("CREATE INDEX {view_argument_vid_idx} ON {view_argument} (vid)");

      db_query("CREATE TABLE {view_tablefield} (
        vid numeric(10) NOT NULL default '0',
        tablename varchar(255),
        field varchar(255),
        label varchar(255),
        handler varchar(255),
        sortable numeric(1),
        defaultsort varchar(5),
        position numeric(2)
      )");
      db_query("CREATE INDEX {view_tablefield_vid_idx} ON {view_tablefield} (vid)");

      db_query("CREATE TABLE {view_filter} (
        vid numeric(10) NOT NULL default '0',
        tablename varchar(255),
        field varchar(255),
        value text,
        operator varchar(20),
        options varchar(255),
        position numeric(2)
      )");
      db_query("CREATE INDEX {view_filter_vid_idx} ON {view_filter} (vid)");
      db_query("CREATE TABLE {view_exposed_filter} (
        vid numeric(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional numeric(1),
        is_default numeric(1),
        operator numeric(1),
        single numeric(1),
        position numeric(2),
      )");
      db_query("CREATE INDEX {view_exposed_filter_vid_idx} ON {view_exposed_filter} (vid)");
      break;
    default:
      break;
  } // End case

  if ($success) {
    drupal_set_message(t('Views module installed tables successfully.'));
  }
  else {
    drupal_set_message(t('The installation of views module was unsuccessful.'), 'error');
  }
}      
232

233 234 235 236 237 238 239
/*
 * update module for UTF.
 */
function views_update_1() {
  return _system_update_utf8(array('view_view', 'view_tablefield', 'view_filter', 'view_sort', 'view_argument'));
}
/*
merlinofchaos's avatar
merlinofchaos committed
240
 * update module for exposed filters.
241
 */
242 243
function views_update_3() {
  $ret = array();
244 245 246 247 248
//  db_add_column($ret, 'view_view', 'page_empty', 'longtext');
//  db_add_column($ret, 'view_view', 'page_empty_format', 'int(4)', array('not null' => TRUE));
//  db_add_column($ret, 'view_view', 'block_use_page_empty', 'int(1)');
//  db_add_column($ret, 'view_view', 'block_empty', 'longtext');
//  db_add_column($ret, 'view_view', 'block_empty_format', 'int(4)', array('not null' => TRUE));
249
  switch($GLOBALS['db_type']) {
250 251
    case 'mysql':
    case 'mysqli':
252
    $ret[] = update_sql("CREATE TABLE if not exists {view_exposed_filter} (
253 254 255 256 257 258 259 260 261 262 263 264
        vid int(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional int(1),
        is_default int(1),
        operator int(1),
        single int(1),
        position int(2),
        KEY (vid)
      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
265
      $ret[] = update_sql("CREATE TABLE {view_exposed_filter} (
266 267 268 269 270 271 272 273 274
        vid numeric(10) unsigned NOT NULL default '0',
        field varchar(255),
        label varchar(255),
        optional numeric(1),
        is_default numeric(1),
        operator numeric(1),
        single numeric(1),
        position numeric(2),
      )");
275
      $ret[] = update_sql("CREATE INDEX {view_exposed_filter_vid_idx} ON {view_exposed_filter} (vid)");
276 277
      break;
  }
278
  return $ret;
279
}
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

function views_update_4() {
  $ret = array();
  db_add_column($ret, 'view_view', 'page_footer', 'longtext');
  db_add_column($ret, 'view_view', 'page_footer_format', 'int(4)', array('default' => 0));
  db_add_column($ret, 'view_view', 'block_use_page_footer', 'int(1)');
  db_add_column($ret, 'view_view', 'block_footer', 'longtext');
  db_add_column($ret, 'view_view', 'block_footer_format', 'int(4)', array('default' => 0));
  db_add_column($ret, 'view_view', 'page_empty', 'longtext');
  db_add_column($ret, 'view_view', 'page_empty_format', 'int(4)', array('default' => 0));
  db_add_column($ret, 'view_view', 'block_use_page_empty', 'int(1)');
  db_add_column($ret, 'view_view', 'block_empty', 'longtext');
  db_add_column($ret, 'view_view', 'block_empty_format', 'int(4)', array('default' => 0));
  return $ret;
}
295 296 297 298 299 300

function views_update_5() {
  $ret = array();
  db_add_column($ret, 'view_view', 'view_args_php', 'longtext');
  return $ret;
}