Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
word varchar(50) NOT NULL default '',
count float default NULL,
PRIMARY KEY word (word)
)");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {search_dataset} (
sid integer NOT NULL default '0',
type varchar(16) default NULL,
data text NOT NULL default '')");
$ret[] = update_sql("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset}(sid, type)");
$ret[] = update_sql("CREATE TABLE {search_index} (
word varchar(50) NOT NULL default '',
sid integer NOT NULL default '0',
type varchar(16) default NULL,
fromsid integer NOT NULL default '0',
fromtype varchar(16) default NULL,
score float default NULL)");
$ret[] = update_sql("CREATE INDEX {search_index}_sid_type_idx ON {search_index}(sid, type)");
$ret[] = update_sql("CREATE INDEX {search_index}_fromsid_fromtype_idx ON {search_index}(fromsid, fromtype)");
$ret[] = update_sql("CREATE INDEX {search_index}_word_idx ON {search_index}(word)");
$ret[] = update_sql("CREATE TABLE {search_total} (
word varchar(50) NOT NULL default '',
count float default NULL,
PRIMARY KEY(word))");
break;
default:
break;
}
return $ret;
}
function update_151() {
$ret = array();
$ts = variable_get('theme_settings', null);
// set up data array so we can loop over both sets of links
$menus = array(0 => array('links_var' => 'primary_links',
'toggle_var' => 'toggle_primary_links',
'more_var' => 'primary_links_more',
'menu_name' => t('Primary links'),
'menu_var' => 'menu_primary_menu',
'pid' => 0),
1 => array('links_var' => 'secondary_links',
'toggle_var' => 'toggle_secondary_links',
'more_var' => 'secondary_links_more',
'menu_name' => t('Secondary links'),
'menu_var' => 'menu_secondary_menu',
'pid' => 0));
for ($loop = 0; $loop <= 1 ; $loop ++) {
// create new Primary and Secondary links menus
$menus[$loop]['pid'] = db_next_id('{menu}_mid');
$ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
"VALUES ({$menus[$loop]['pid']}, 0, '', '{$menus[$loop]['menu_name']}', '', 0, 115)");
// insert all entries from theme links into new menus
$num_inserted = 0;
if (is_array($ts) && is_array($ts[$menus[$loop]['links_var']])) {
$links = $ts[$menus[$loop]['links_var']];
for ($i = 0; $i < count($links['text']); $i++) {
if ($links['text'][$i] != "" && $links['link'][$i] != "") {
$num_inserted ++;
$node_unalias = db_fetch_array(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $links['link'][$i]));
if (is_array($node_unalias)) {
$link_path = $node_unalias['src'];
}
else {
$link_path = $links['link'][$i];
}
$mid = db_next_id('{menu}_mid');
$ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
"VALUES ($mid, {$menus[$loop]['pid']}, '" . db_escape_string($link_path) .
"', '" . db_escape_string($links['text'][$i]) .
"', '" . db_escape_string($links['description'][$i]) . "', 0, 118)");
}
}
// delete Secondary links if not populated.
if ($loop == 1 && $num_inserted == 0) {
db_query("DELETE FROM {menu} WHERE mid={$menus[$loop]['pid']}");
}
}
// set menu_primary_menu variable appropriately
if (!$ts[$menus[$loop]['toggle_var']] || $num_inserted == 0) {
variable_set($menus[$loop]['menu_var'], 0);
}
else {
variable_set($menus[$loop]['menu_var'], $menus[$loop]['pid']);
}
variable_del($menus[$loop]['toggle_var']);
unset($ts[$menus[$loop]['toggle_var']]);
variable_del($menus[$loop]['links_var']);
unset($ts[$menus[$loop]['links_var']]);
variable_del($menus[$loop]['more_var']);
unset($ts[$menus[$loop]['more_var']]);
}
if (is_array($ts)) {
variable_set('theme_settings', $ts);
}
$ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'menu'");
return $ret;
}
function update_152() {
$ret = array();
// Postgresql only update
switch ($GLOBALS['db_type']) {
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {forum} RENAME shadow TO shadow_old");
break;
case 'mysql':
case 'mysqli':
break;
}
return $ret;
}
function update_153(){
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey");
$ret[] = update_sql("CREATE SEQUENCE {contact}_cid_seq");
db_add_column($ret, 'contact', 'cid', 'int', array('not null' => TRUE, 'default' => "nextval('{contact}_cid_seq')"));
$ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (cid)");
$ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT {contact}_category_key UNIQUE (category)");
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int(11) NOT NULL PRIMARY KEY auto_increment");
$ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)");
break;
}
return $ret;
}
function update_154() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0));
db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0));
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN weight tinyint(3) NOT NULL DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN selected tinyint(1) NOT NULL DEFAULT 0");
break;
}
return $ret;
}
function update_155() {
$ret = array();
// Postgresql only update
switch ($GLOBALS['db_type']) {
case 'pgsql':
$ret[] = update_sql("DROP TABLE {cache}");
$ret[] = update_sql("CREATE TABLE {cache} (
cid varchar(255) NOT NULL default '',
data bytea default '',
expire integer NOT NULL default '0',
created integer NOT NULL default '0',
headers text default '',
PRIMARY KEY (cid)
)");
$ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache}(expire)");
break;
case 'mysql':
case 'mysqli':
break;
}
return $ret;
}
/**
* Adds a column to a database. Uses syntax appropriate for PostgreSQL.
* Saves result of SQL commands in $ret array.
*
* Note: when you add a column with NOT NULL and you are not sure if there are rows in table already,
* you MUST also add DEFAULT. Otherwise PostgreSQL won't work if the table is not empty. If NOT NULL and
* DEFAULT is set the Postgresql version will set values of the added column in old rows to the DEFAULT value.
*
* @param $ret
* Array to which results will be added.
* @param $table
* Name of the table, without {}
* @param $column
* Name of the column
* @param $type
* Type of column
* @param $attributes
* Additional optional attributes. Recognized atributes:
* - not null => TRUE/FALSE
* - default => NULL/FALSE/value (with or without '', it wont' be added)
* @return
* nothing, but modifies $ret parametr.
*/
function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
if (array_key_exists('not null', $attributes) and $attributes['not null']) {
$not_null = 'NOT NULL';
}
if (array_key_exists('default', $attributes)) {
if (is_null($attributes['default'])) {
$default_val = 'NULL';
$default = 'default NULL';
}
elseif ($attributes['default'] === FALSE) {
$default = '';
}
else {
$default_val = "$attributes[default]";
$default = "default $attributes[default]";
}
}
$ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type");
if ($default) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default"); }
if ($not_null) {
if ($default) { $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val"); }
$ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL");
}
}
/**
* Changes a column definition. Uses syntax appropriate for PostgreSQL.
* Saves result of SQL commands in $ret array.
*
* @param $ret
* Array to which results will be added.
* @param $table
* Name of the table, without {}
* @param $column
* Name of the column to change
* @param $column_new
* New name for the column (set to the same as $column if you don't want to change the name)
* @param $type
* Type of column
* @param $attributes
* Additional optional attributes. Recognized atributes:
* - not null => TRUE/FALSE
* - default => NULL/FALSE/value (with or without '', it wont' be added)
* @return
* nothing, but modifies $ret parametr.
*/
function db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array()) {
if (array_key_exists('not null', $attributes) and $attributes['not null']) {
$not_null = 'NOT NULL';
}
if (array_key_exists('default', $attributes)) {
if (is_null($attributes['default'])) {
$default_val = 'NULL';
$default = 'default NULL';
}
elseif ($attributes['default'] === FALSE) {
$default = '';
}
else {
$default_val = "$attributes[default]";
$default = "default $attributes[default]";
}
}
$ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old");
$ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column_new $type");
$ret[] = update_sql("UPDATE {". $table ."} SET $column_new = ". $column ."_old");
if ($default) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET $default"); }
if ($not_null) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET NOT NULL"); }
// We don't drop columns for now
// $ret[] = update_sql("ALTER TABLE {". $table ."} DROP ". $column ."_old");
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
if ($result) {
return array('1', check_plain($sql) ."\n<span class=\"success\">OK</span>\n");
}
else {
return array('0', check_plain($sql) ."\n<span class=\"failure\">FAILED</span>\n");
}
}
?>