| 2 |
// $Id$ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
|
* @file |
| 6 |
|
* Install script for a simple donation module. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
/** |
| 10 |
* Implementation of hook_install(). |
* Implementation of hook_install(). |
| 11 |
*/ |
*/ |
|
function donation_install() { |
|
|
switch ($GLOBALS['db_type']) { |
|
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
db_query("CREATE TABLE {donations} ( |
|
|
did INT(10) NOT NULL AUTO_INCREMENT, |
|
|
status INT(2) NOT NULL DEFAULT '1', |
|
|
name VARCHAR(128) DEFAULT NULL, |
|
|
mail VARCHAR(128) DEFAULT NULL, |
|
|
timestamp INT(11) NOT NULL DEFAULT '0', |
|
|
amount FLOAT DEFAULT NULL, |
|
|
currency VARCHAR(5) DEFAULT 'USD', |
|
|
uid INT(11) DEFAULT NULL, |
|
|
donor_name VARCHAR(255) DEFAULT NULL, |
|
|
donor_url VARCHAR(255) DEFAULT NULL, |
|
|
donor_memo VARCHAR(255) DEFAULT NULL, |
|
|
paypal_txn_id VARCHAR(255) DEFAULT NULL, |
|
|
donor_comment VARCHAR(255) DEFAULT NULL, |
|
|
PRIMARY KEY (did), |
|
|
KEY {donations}_uid_idx (uid), |
|
|
KEY {donations}_mail_idx (mail), |
|
|
KEY {donations}_timestamp_idx (timestamp) |
|
|
) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); |
|
| 12 |
|
|
| 13 |
break; |
function donation_install() { |
| 14 |
} |
drupal_install_schema('donation'); |
| 15 |
} |
} |
| 16 |
|
|
| 17 |
/** |
/** |
| 18 |
* Implementation of hook_uninstall(). |
* Implementation of hook_schema(). |
| 19 |
*/ |
*/ |
| 20 |
function donation_uninstall() { |
function donation_schema() { |
| 21 |
db_query('DROP TABLE {donations}'); |
$schema['donation'] = array( |
| 22 |
|
'fields' => array( |
| 23 |
|
'did' => array('type' => 'serial', 'not null' => TRUE, 'disp-width' => '10'), |
| 24 |
|
'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 1, 'disp-width' => '2'), |
| 25 |
|
'name' => array('type' => 'varchar', 'length' => '128', 'not null' => FALSE), |
| 26 |
|
'mail' => array('type' => 'varchar', 'length' => '128', 'not null' => FALSE), |
| 27 |
|
'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 28 |
|
'amount' => array('type' => 'float', 'not null' => FALSE), |
| 29 |
|
'currency' => array('type' => 'varchar', 'length' => '5', 'not null' => FALSE, 'default' => 'USD'), |
| 30 |
|
'uid' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'), |
| 31 |
|
'donor_name' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), |
| 32 |
|
'donor_url' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), |
| 33 |
|
'donor_memo' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), |
| 34 |
|
'paypal_txn_id' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE), |
| 35 |
|
'donor_comment' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE)), |
| 36 |
|
'primary key' => array('did'), |
| 37 |
|
'indexes' => array( |
| 38 |
|
'donation_mail_idx' => array('mail'), |
| 39 |
|
'donation_timestamp_idx' => array('timestamp'), |
| 40 |
|
'donation_uid_idx' => array('uid')), |
| 41 |
|
); |
| 42 |
|
return $schema; |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
function donation_update_1() { |
|
| 46 |
switch ($GLOBALS['db_type']) { |
|
| 47 |
case 'mysql': |
/** |
| 48 |
case 'mysqli': |
* Implementation of hook_uninstall(). |
| 49 |
// Update the existing data to derive the user id from the email address |
*/ |
| 50 |
$ret[] = update_sql("UPDATE {donations} d INNER JOIN {users} u USING(mail) SET d.uid = u.uid WHERE d.uid = 0"); |
function donation_uninstall() { |
| 51 |
return $ret; |
drupal_uninstall_schema('donation'); |
|
} |
|
| 52 |
} |
} |