| 1 |
<?php |
<?php |
| 2 |
// $Id: invite.install,v 1.12 2008/08/20 13:26:11 smk Exp $ |
// $Id: invite.install,v 1.13 2008/09/02 17:02:14 smk Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Installation file for invite module. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
* Install the initial schema. |
* Install the initial schema. |
| 169 |
} |
} |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
|
/** |
| 173 |
|
* Helper function to update a variable name using role name to role id. |
| 174 |
|
*/ |
| 175 |
|
function _invite_update_role_name_to_id($variable) { |
| 176 |
|
$result = db_query("SELECT * FROM {role} ORDER BY name ASC"); |
| 177 |
|
while ($role = db_fetch_object($result)) { |
| 178 |
|
// Look for both a translated (D6) and untranslated (D5) variables. |
| 179 |
|
// A translated one is newer and has therefore precendence. |
| 180 |
|
$translated_role = str_replace(' ', '_', t($role->name)); |
| 181 |
|
$value = variable_get($variable .'_'. $translated_role, NULL); |
| 182 |
|
if (is_null($value)) { |
| 183 |
|
$untranslated_role = str_replace(' ', '_', $role->name); |
| 184 |
|
$value = variable_get($variable .'_'. $untranslated_role, NULL); |
| 185 |
|
} |
| 186 |
|
if (!is_null($value)) { |
| 187 |
|
variable_set($variable .'_'. $role->rid, $value); |
| 188 |
|
db_query("DELETE FROM {variable} WHERE name IN('%s', '%s')", $variable .'_'. $translated_role, $variable .'_'. $untranslated_role); |
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
|
| 193 |
/** |
/** |
| 194 |
* Switch to token.module. |
* Switch to token.module. |
| 216 |
// Convert existing messages |
// Convert existing messages |
| 217 |
$result = db_query("SELECT reg_code, data FROM {invite} WHERE data <> ''"); |
$result = db_query("SELECT reg_code, data FROM {invite} WHERE data <> ''"); |
| 218 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 219 |
if (substr($row->message, 0, 2) == 'a:') { |
if (drupal_substr($row->message, 0, 2) == 'a:') { |
| 220 |
// Already serialized |
// Already serialized |
| 221 |
continue; |
continue; |
| 222 |
} |
} |
| 250 |
} |
} |
| 251 |
_invite_add_permission($rid, implode(', ', $perms)); |
_invite_add_permission($rid, implode(', ', $perms)); |
| 252 |
} |
} |
| 253 |
db_query("DELETE from {variable} WHERE name LIKE 'invite_maxmultiple_%%'"); |
$ret[] = update_sql("DELETE from {variable} WHERE name LIKE 'invite_maxmultiple_%%'"); |
| 254 |
|
|
| 255 |
// Expiry periods changed |
// Expiry periods changed |
| 256 |
$expiry = variable_get('invite_expiry', 30); |
$expiry = variable_get('invite_expiry', 30); |
| 333 |
db_change_field($ret, 'invite', 'mid', 'invitee', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
db_change_field($ret, 'invite', 'mid', 'invitee', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
| 334 |
db_change_field($ret, 'invite', 'timestamp', 'joined', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
db_change_field($ret, 'invite', 'timestamp', 'joined', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
| 335 |
db_add_field($ret, 'invite', 'created', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
db_add_field($ret, 'invite', 'created', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
| 336 |
db_add_field($ret, 'invite', 'cancelled', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
db_add_field($ret, 'invite', 'canceled', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
| 337 |
db_add_field($ret, 'invite', 'resent', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
db_add_field($ret, 'invite', 'resent', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); |
| 338 |
return $ret; |
return $ret; |
| 339 |
} |
} |
| 366 |
) |
) |
| 367 |
)); |
)); |
| 368 |
// Convert old data |
// Convert old data |
| 369 |
db_query("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, invitee FROM {invite} WHERE joined <> 0 AND received = 0"); |
$ret[] = update_sql("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, invitee FROM {invite} WHERE joined <> 0 AND received = 0"); |
| 370 |
// Drop old column |
// Drop old column |
| 371 |
db_drop_field($ret, 'invite', 'received'); |
db_drop_field($ret, 'invite', 'received'); |
| 372 |
return $ret; |
return $ret; |
| 382 |
return $ret; |
return $ret; |
| 383 |
} |
} |
| 384 |
|
|
| 385 |
|
/** |
| 386 |
|
* Update variable names to use role id instead of translated role name. |
| 387 |
|
* @see #322748 |
| 388 |
|
*/ |
| 389 |
|
function invite_update_203() { |
| 390 |
|
$ret = array(); |
| 391 |
|
_invite_update_role_name_to_id('invite_maxnum'); |
| 392 |
|
_invite_update_role_name_to_id('invite_target_role'); |
| 393 |
|
return $ret; |
| 394 |
|
} |
| 395 |
|
|