| 1 |
<?php
|
| 2 |
// $Id: reptag.install,v 1.15.2.12 2007/07/25 16:14:31 profix898 Exp $
|
| 3 |
|
| 4 |
require_once(drupal_get_path('module', 'reptag') .'/reptag_helper.inc');
|
| 5 |
require_once(drupal_get_path('module', 'reptag') .'/reptag_module.inc');
|
| 6 |
|
| 7 |
function reptag_schema() {
|
| 8 |
$schema = array();
|
| 9 |
$schema['reptag_vars'] = array(
|
| 10 |
'fields' => array(
|
| 11 |
'rtid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 12 |
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 13 |
'value' => array('type' => 'text', 'not null' => TRUE, 'default' => ''),
|
| 14 |
'uid' => array('type' => 'int', 'length' => 10, 'not null' => TRUE, 'default' => 0),
|
| 15 |
'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')
|
| 16 |
),
|
| 17 |
'primary key' => array('rtid'),
|
| 18 |
'indexes' => array(
|
| 19 |
'uid' => array('uid'),
|
| 20 |
'language' => array('language')
|
| 21 |
)
|
| 22 |
);
|
| 23 |
$schema['reptag_registry'] = array(
|
| 24 |
'fields' => array(
|
| 25 |
'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 26 |
'path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 27 |
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 28 |
'roles' => array('type' => 'text'),
|
| 29 |
'enabled' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 30 |
'static' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 31 |
'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
|
| 32 |
),
|
| 33 |
'indexes' => array(
|
| 34 |
'weight' => array('weight'),
|
| 35 |
'enabled' => array('enabled'),
|
| 36 |
'static' => array('static')
|
| 37 |
)
|
| 38 |
);
|
| 39 |
$schema['cache_reptag'] = array(
|
| 40 |
'fields' => array(
|
| 41 |
'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 42 |
'data' => array('type' => 'blob', 'size' => 'big'),
|
| 43 |
'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 44 |
'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 45 |
'headers' => array('type' => 'text'),
|
| 46 |
'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
|
| 47 |
),
|
| 48 |
'primary key' => array('cid'),
|
| 49 |
'indexes' => array(
|
| 50 |
'expire' => array('expire')
|
| 51 |
)
|
| 52 |
);
|
| 53 |
|
| 54 |
return $schema;
|
| 55 |
}
|
| 56 |
|
| 57 |
function reptag_install() {
|
| 58 |
// Create tables
|
| 59 |
drupal_install_schema('reptag');
|
| 60 |
// Insert default values (enabled modules, default roles, ...)
|
| 61 |
variable_set('reptag_plainrep_roles', serialize(array(DRUPAL_ANONYMOUS_RID)));
|
| 62 |
|
| 63 |
$modules = _reptag_module_list(TRUE);
|
| 64 |
foreach ($modules as $module => $details) {
|
| 65 |
if (in_array($module, array('format.tags', 'image.tags', 'links.tags', 'node.tags', 'system.tags'))) {
|
| 66 |
$modules[$module]['enabled'] = TRUE;
|
| 67 |
$modules[$module]['roles'] = array(DRUPAL_AUTHENTICATED_RID);
|
| 68 |
}
|
| 69 |
}
|
| 70 |
_reptag_module_register($modules, TRUE);
|
| 71 |
}
|
| 72 |
|
| 73 |
function reptag_uninstall() {
|
| 74 |
// Drop tables
|
| 75 |
drupal_uninstall_schema('reptag');
|
| 76 |
// Remove variables
|
| 77 |
db_query("DELETE FROM {variable} WHERE name LIKE 'reptag_%'");
|
| 78 |
cache_clear_all('variables', 'cache');
|
| 79 |
}
|
| 80 |
|
| 81 |
function reptag_update_1() {
|
| 82 |
return _system_update_utf8(array('reptag_vars', 'reptag_storage'));
|
| 83 |
}
|
| 84 |
|
| 85 |
function reptag_update_2() {
|
| 86 |
$ret = array();
|
| 87 |
switch ($GLOBALS['db_type']) {
|
| 88 |
case 'mysql':
|
| 89 |
case 'mysqli':
|
| 90 |
$ret[] = update_sql("CREATE TABLE {reptag_storage} (
|
| 91 |
nid int(10) unsigned NOT NULL,
|
| 92 |
vid int(10) unsigned NOT NULL,
|
| 93 |
body longtext NOT NULL default '',
|
| 94 |
teaser longtext NOT NULL default '',
|
| 95 |
PRIMARY KEY (vid),
|
| 96 |
KEY nid (nid)
|
| 97 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
|
| 98 |
break;
|
| 99 |
case 'pgsql':
|
| 100 |
$ret[] = update_sql("CREATE TABLE {reptag_storage} (
|
| 101 |
nid integer NOT NULL default '0',
|
| 102 |
vid integer NOT NULL default '0',
|
| 103 |
body text NOT NULL default '',
|
| 104 |
teaser text NOT NULL default '',
|
| 105 |
PRIMARY KEY (vid));");
|
| 106 |
$ret[] = update_sql("CREATE INDEX reptag_storage_nid_idx ON reptag_storage(nid);");
|
| 107 |
$ret[] = update_sql("CREATE SEQUENCE reptag_storage_vid_seq INCREMENT 1 START 1;");
|
| 108 |
break;
|
| 109 |
}
|
| 110 |
|
| 111 |
return $ret;
|
| 112 |
}
|
| 113 |
|
| 114 |
function reptag_update_3() {
|
| 115 |
$ret = array();
|
| 116 |
// Restore nodes from old cache table and drop the table
|
| 117 |
$result = db_query("SELECT * FROM {reptag_storage}");
|
| 118 |
while ($node = db_fetch_object($result)) {
|
| 119 |
$ret[] = update_sql("UPDATE {node_revisions} SET body = '%s', teaser = '%s' WHERE vid = %d", $node->body, $node->teaser, $node->vid);
|
| 120 |
}
|
| 121 |
$ret[] = update_sql("DROP TABLE {reptag_storage}");
|
| 122 |
// Create new cache table
|
| 123 |
switch ($GLOBALS['db_type']) {
|
| 124 |
case 'mysql':
|
| 125 |
case 'mysqli':
|
| 126 |
$ret[] = update_sql("CREATE TABLE {cache_reptag} (
|
| 127 |
cid varchar(255) NOT NULL default '',
|
| 128 |
data longblob,
|
| 129 |
expire int NOT NULL default '0',
|
| 130 |
created int NOT NULL default '0',
|
| 131 |
headers text,
|
| 132 |
PRIMARY KEY (cid),
|
| 133 |
INDEX expire (expire)
|
| 134 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 135 |
break;
|
| 136 |
case 'pgsql':
|
| 137 |
$ret[] = update_sql("CREATE TABLE {cache_reptag} (
|
| 138 |
cid varchar(255) NOT NULL default '',
|
| 139 |
data bytea,
|
| 140 |
expire int NOT NULL default '0',
|
| 141 |
created int NOT NULL default '0',
|
| 142 |
headers text,
|
| 143 |
PRIMARY KEY (cid))");
|
| 144 |
$ret[] = update_sql("CREATE INDEX {cache_reptag}_expire_idx ON {cache_reptag} (expire)");
|
| 145 |
break;
|
| 146 |
}
|
| 147 |
|
| 148 |
return $ret;
|
| 149 |
}
|
| 150 |
|
| 151 |
function reptag_update_4() {
|
| 152 |
$ret = array();
|
| 153 |
switch ($GLOBALS['db_type']) {
|
| 154 |
case 'mysql':
|
| 155 |
case 'mysqli':
|
| 156 |
$ret[] = update_sql("CREATE TABLE {reptag_registry} (
|
| 157 |
module varchar(255) NOT NULL default '',
|
| 158 |
path varchar(255) NOT NULL default '',
|
| 159 |
weight int NOT NULL default '0',
|
| 160 |
roles longtext,
|
| 161 |
enabled int NOT NULL default '0',
|
| 162 |
static int NOT NULL default '0',
|
| 163 |
description varchar(255) NOT NULL default '',
|
| 164 |
PRIMARY KEY (module)
|
| 165 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
|
| 166 |
break;
|
| 167 |
case 'pgsql':
|
| 168 |
$ret[] = update_sql("CREATE TABLE {reptag_registry} (
|
| 169 |
module varchar(255) NOT NULL default '',
|
| 170 |
path varchar(255) NOT NULL default '',
|
| 171 |
weight int NOT NULL default '0',
|
| 172 |
roles text NOT NULL,
|
| 173 |
enabled int NOT NULL default '0',
|
| 174 |
static int NOT NULL default '0',
|
| 175 |
description varchar(255) NOT NULL default '',
|
| 176 |
PRIMARY KEY (module));");
|
| 177 |
break;
|
| 178 |
}
|
| 179 |
// Migrate existing module settings
|
| 180 |
$modules = _reptag_module_list(TRUE);
|
| 181 |
foreach ($modules as $module => $details) {
|
| 182 |
$modules[$module]['enabled'] = variable_get('reptag_module_'. $module, 0);
|
| 183 |
$modules[$module]['roles'] = unserialize(variable_get('reptag_module_'. $module .'_roles', serialize(array())));
|
| 184 |
}
|
| 185 |
_reptag_module_register($modules, TRUE);
|
| 186 |
// Plaintext replacement roles
|
| 187 |
variable_set('reptag_plainrep_roles', variable_get('reptag_module_plainrep_roles', serialize(array())));
|
| 188 |
|
| 189 |
// Remove obsolete variables
|
| 190 |
$ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'reptag_module_%'");
|
| 191 |
cache_clear_all('variables', 'cache');
|
| 192 |
|
| 193 |
return $ret;
|
| 194 |
}
|
| 195 |
|
| 196 |
function reptag_update_5() {
|
| 197 |
return array(array('success' => (count(_reptag_module_list(TRUE)) > 0), 'query' => 'Rebuild module list ...'));
|
| 198 |
}
|
| 199 |
|
| 200 |
function reptag_update_6() {
|
| 201 |
$ret = array();
|
| 202 |
switch ($GLOBALS['db_type']) {
|
| 203 |
case 'mysql':
|
| 204 |
case 'mysqli':
|
| 205 |
$ret[] = update_sql('ALTER TABLE {reptag_vars} ADD language varchar(12) NOT NULL default \'\'');
|
| 206 |
break;
|
| 207 |
case 'pgsql':
|
| 208 |
db_add_column($ret, 'reptag_vars', 'language', 'varchar(12)', array('not null' => TRUE, 'default' => NULL));
|
| 209 |
break;
|
| 210 |
}
|
| 211 |
|
| 212 |
return $ret;
|
| 213 |
}
|
| 214 |
|
| 215 |
function reptag_update_7() {
|
| 216 |
$ret = array();
|
| 217 |
// Migrate existing table tags to new table schema
|
| 218 |
// Step 1: Rename 'reptag_vars' to transitional 'reptag_vars_tmp'
|
| 219 |
db_rename_table($ret, 'reptag_vars', 'reptag_vars_tmp');
|
| 220 |
// Step 2: Create new 'reptag_vars' table (using the new schema)
|
| 221 |
$schema = array();
|
| 222 |
$schema['reptag_vars'] = array(
|
| 223 |
'fields' => array(
|
| 224 |
'rtid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 225 |
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 226 |
'value' => array('type' => 'text', 'not null' => TRUE, 'default' => ''),
|
| 227 |
'uid' => array('type' => 'int', 'length' => 10, 'not null' => TRUE, 'default' => 0),
|
| 228 |
'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')
|
| 229 |
),
|
| 230 |
'primary key' => array('rtid'),
|
| 231 |
'indexes' => array(
|
| 232 |
'uid' => array('uid'),
|
| 233 |
'language' => array('language')
|
| 234 |
)
|
| 235 |
);
|
| 236 |
db_create_table($ret, 'reptag_vars', $schema['reptag_vars']);
|
| 237 |
// Step 3: Move items to new table (generates a serial rtid)
|
| 238 |
$result = db_query('SELECT * FROM {reptag_vars_tmp}');
|
| 239 |
while ($var = db_fetch_object($result)) {
|
| 240 |
$ret[] = array(
|
| 241 |
'success' => db_query("INSERT INTO {reptag_vars} (name, value, uid, language) VALUES ('%s', '%s', %d, '%s')",
|
| 242 |
$var->name, unserialize($var->value), $var->uid, empty($var->language) ? 'en' : $var->language),
|
| 243 |
'query' => 'Migrating existing table tags (SELECT -> INSERT): \''. check_plain($var->name) .'\''
|
| 244 |
);
|
| 245 |
}
|
| 246 |
// Step 4: Remove 'reptag_vars_tmp'
|
| 247 |
db_drop_table($ret, 'reptag_vars_tmp');
|
| 248 |
|
| 249 |
// Add indices to reptag_registry (weight, enabled, static)
|
| 250 |
db_add_index($ret, 'reptag_registry', 'weight', array('weight'));
|
| 251 |
db_add_index($ret, 'reptag_registry', 'enabled', array('enabled'));
|
| 252 |
db_add_index($ret, 'reptag_registry', 'static', array('static'));
|
| 253 |
// Remove primary key (module) from reptag_registry
|
| 254 |
db_drop_primary_key($ret, 'reptag_registry');
|
| 255 |
|
| 256 |
// Add 'serialized' column to cache_reptag
|
| 257 |
db_add_field($ret, 'cache_reptag', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
|
| 258 |
|
| 259 |
// Rename i18n settings (i18n module to core's locale)
|
| 260 |
variable_set('reptag_locale_enable', variable_get('reptag_i18n_enable', 0));
|
| 261 |
variable_set('reptag_locale_mode', variable_get('reptag_i18n_mode', 0));
|
| 262 |
|
| 263 |
// Remove obsolete variables
|
| 264 |
variable_del('reptag_enable');
|
| 265 |
variable_del('reptag_add_sample');
|
| 266 |
variable_del('reptag_i18n_enable');
|
| 267 |
variable_del('reptag_i18n_mode');
|
| 268 |
|
| 269 |
return $ret;
|
| 270 |
}
|