| 1 |
<?php
|
| 2 |
// $Id: bio.install,v 1.2 2009/04/11 01:32:10 vauxia Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installation file for Bio module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function bio_install() {
|
| 13 |
switch ($GLOBALS['db_type']) {
|
| 14 |
case 'mysql':
|
| 15 |
case 'mysqli':
|
| 16 |
db_query("CREATE TABLE {bio} (
|
| 17 |
nid int unsigned NOT NULL default '0',
|
| 18 |
uid int unsigned NOT NULL default '0',
|
| 19 |
PRIMARY KEY (nid, uid)
|
| 20 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 21 |
break;
|
| 22 |
case 'pgsql':
|
| 23 |
db_query("CREATE TABLE {bio} (
|
| 24 |
nid int_unsigned NOT NULL default '0',
|
| 25 |
uid int_unsigned NOT NULL default '0',
|
| 26 |
PRIMARY KEY (nid, uid)
|
| 27 |
)");
|
| 28 |
break;
|
| 29 |
}
|
| 30 |
drupal_set_message(t('You can configure the bio module on the <a href="@url">bio settings page</a>.', array('@url' => url('admin/user/bio'))));
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* @defgroup bio-updates-legacy Bio updates for versions prior to 5.x-1.x
|
| 35 |
* @{
|
| 36 |
*/
|
| 37 |
|
| 38 |
/**
|
| 39 |
* 4.7.x -> 5.x upgrade.
|
| 40 |
*/
|
| 41 |
function bio_update_1() {
|
| 42 |
$ret = array();
|
| 43 |
|
| 44 |
// Copy per-node type link settings into different format.
|
| 45 |
$bio_link = array();
|
| 46 |
foreach (node_get_types() as $key => $type) {
|
| 47 |
$bio_link[$key] = variable_get('bio_'. $key, 0) ? $key : 0;
|
| 48 |
}
|
| 49 |
variable_set('bio_link', $bio_link);
|
| 50 |
|
| 51 |
// Keep permissions while using a node type handled by the node module.
|
| 52 |
$ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'bio%%'");
|
| 53 |
|
| 54 |
// Purge old settings.
|
| 55 |
$ret[] = update_sql("UPDATE {permission} SET perm = REPLACE(perm, 'create biography', 'add bio, edit own bio')");
|
| 56 |
|
| 57 |
return $ret;
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* @} End of "defgroup bio-updates-legacy"
|
| 62 |
*/
|
| 63 |
|
| 64 |
/**
|
| 65 |
* @defgroup bio-updates-5.x-1.x Bio updates for 5.x-1.x
|
| 66 |
* @{
|
| 67 |
*/
|
| 68 |
|
| 69 |
/**
|
| 70 |
* Creates and populates a table to hold uid/nid combination.
|
| 71 |
*
|
| 72 |
* Workaround for node_user's annoying behaviour of anonymizing bio nodes
|
| 73 |
* which prevents us from deleting them.
|
| 74 |
*/
|
| 75 |
function bio_update_5100() {
|
| 76 |
$ret = array();
|
| 77 |
|
| 78 |
// Create bio table.
|
| 79 |
switch ($GLOBALS['db_type']) {
|
| 80 |
case 'mysql':
|
| 81 |
case 'mysqli':
|
| 82 |
$ret[] = update_sql("CREATE TABLE {bio} (
|
| 83 |
nid int unsigned NOT NULL default '0',
|
| 84 |
uid int unsigned NOT NULL default '0',
|
| 85 |
PRIMARY KEY (nid, uid)
|
| 86 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 87 |
$ret[] = update_sql("ALTER TABLE {bio} ADD INDEX (uid)");
|
| 88 |
break;
|
| 89 |
case 'pgsql':
|
| 90 |
$ret[] = update_sql("CREATE TABLE {bio} (
|
| 91 |
nid int_unsigned NOT NULL default '0',
|
| 92 |
uid int_unsigned NOT NULL default '0',
|
| 93 |
PRIMARY KEY (nid, uid)
|
| 94 |
)");
|
| 95 |
$ret[] = update_sql("CREATE INDEX uid_idx ON {bio} (uid)");
|
| 96 |
break;
|
| 97 |
}
|
| 98 |
|
| 99 |
// Populate table.
|
| 100 |
$type = db_escape_string(variable_get('bio_nodetype', 'bio'));
|
| 101 |
$ret[] = update_sql("INSERT INTO {bio} SELECT nid, uid FROM {node} WHERE type = '$type' AND uid != 0");
|
| 102 |
|
| 103 |
return $ret;
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Creates an index on the uid column of the bio table
|
| 108 |
**/
|
| 109 |
function bio_update_5101() {
|
| 110 |
$ret = array();
|
| 111 |
|
| 112 |
switch ($GLOBALS['db_type']) {
|
| 113 |
case 'mysql':
|
| 114 |
case 'mysqli':
|
| 115 |
$ret[] = update_sql("ALTER TABLE {bio} ADD INDEX (uid)");
|
| 116 |
break;
|
| 117 |
case 'pgsql':
|
| 118 |
$ret[] = update_sql("CREATE INDEX uid_idx ON {bio} (uid)");
|
| 119 |
break;
|
| 120 |
}
|
| 121 |
|
| 122 |
return $ret;
|
| 123 |
}
|
| 124 |
|
| 125 |
|
| 126 |
/**
|
| 127 |
* @} End of "defgroup bio-updates-5.x-1.x"
|
| 128 |
*/
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Implementation of hook_uninstall().
|
| 132 |
*/
|
| 133 |
function bio_uninstall() {
|
| 134 |
db_query('DROP TABLE {bio}');
|
| 135 |
variable_del('bio_nodetype');
|
| 136 |
variable_del('bio_link');
|
| 137 |
variable_del('bio_profile');
|
| 138 |
variable_del('bio_profile_takeover');
|
| 139 |
variable_del('bio_regstration_form');
|
| 140 |
variable_del('bio_regstration_form_fields');
|
| 141 |
}
|