| 1 |
<?php |
<?php |
| 2 |
// $Id: false_account.install,v 1.2 2008/03/08 14:59:31 introfini Exp $ |
// $Id: false_account.install,v 1.2 2008/03/08 14:59:31 introfini Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_install() |
* Implementation of hook_install() |
| 6 |
* just give a message |
* just give a message |
| 7 |
*/ |
*/ |
| 8 |
function false_account_install() { |
function false_account_install() { |
| 9 |
switch ($GLOBALS['db_type']) { |
switch ($GLOBALS['db_type']) { |
| 10 |
case 'mysql': |
case 'mysql': |
| 11 |
case 'mysqli': |
case 'mysqli': |
| 12 |
$created = db_query(" |
$created = db_query(" |
| 13 |
CREATE TABLE IF NOT EXISTS {false_accounts} ( |
CREATE TABLE IF NOT EXISTS {false_accounts} ( |
| 14 |
cid varchar(64) NOT NULL, |
cid varchar(64) NOT NULL, |
| 15 |
uid int(10) NOT NULL, |
uid int(10) NOT NULL, |
| 16 |
created int(11) unsigned NOT NULL default '0', |
created int(11) unsigned NOT NULL default '0', |
| 17 |
status tinyint(3) unsigned NOT NULL default '0', |
status tinyint(3) unsigned NOT NULL default '0', |
| 18 |
PRIMARY KEY (cid, uid) |
PRIMARY KEY (cid, uid) |
| 19 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
| 20 |
break; |
break; |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
if ($created) { |
if ($created) { |
| 24 |
drupal_set_message(t('False Account module installed successfully.')); |
drupal_set_message(t('False Account module installed successfully.')); |
| 25 |
} |
} |
| 26 |
else { |
else { |
| 27 |
drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error'); |
drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error'); |
| 28 |
} |
} |
| 29 |
} |
} |
| 30 |
|
|
| 31 |
|
|
| 32 |
/** |
/** |
| 33 |
* Implementation of hook_update_N() |
* Implementation of hook_update_N() |
| 34 |
* new DB structure |
* new DB structure |
| 35 |
*/ |
*/ |
| 36 |
function false_account_update_1() { |
function false_account_update_1() { |
| 37 |
|
|
| 38 |
$return = array(); |
$return = array(); |
| 39 |
$done = array(); |
$done = array(); |
| 40 |
|
|
| 41 |
// replicate table |
// replicate table |
| 42 |
$result = db_query(' |
$result = db_query(' |
| 43 |
CREATE TABLE IF NOT EXISTS {false_accounts_old} |
CREATE TABLE IF NOT EXISTS {false_accounts_old} |
| 44 |
LIKE {false_accounts}' |
LIKE {false_accounts}' |
| 45 |
); |
); |
| 46 |
$done[] = $result; |
$done[] = $result; |
| 47 |
|
|
| 48 |
$result = db_query(' |
$result = db_query(' |
| 49 |
INSERT {false_accounts_old} |
INSERT {false_accounts_old} |
| 50 |
SELECT * |
SELECT * |
| 51 |
FROM {false_accounts}' |
FROM {false_accounts}' |
| 52 |
); |
); |
| 53 |
$done[] = $result; |
$done[] = $result; |
| 54 |
|
|
| 55 |
// avoid data destruction if copy actions haven't succeed |
// avoid data destruction if copy actions haven't succeed |
| 56 |
if (! in_array(false, $done)) { |
if (! in_array(false, $done)) { |
| 57 |
$done = array(); |
$done = array(); |
| 58 |
|
|
| 59 |
$result = db_query('DROP TABLE {false_accounts}'); |
$result = db_query('DROP TABLE {false_accounts}'); |
| 60 |
$done[] = $result; |
$done[] = $result; |
| 61 |
|
|
| 62 |
$created = db_query(" |
$created = db_query(" |
| 63 |
CREATE TABLE IF NOT EXISTS {false_accounts} ( |
CREATE TABLE IF NOT EXISTS {false_accounts} ( |
| 64 |
cid varchar(64) NOT NULL, |
cid varchar(64) NOT NULL, |
| 65 |
uid int(10) NOT NULL, |
uid int(10) NOT NULL, |
| 66 |
created int(11) unsigned NOT NULL default '0', |
created int(11) unsigned NOT NULL default '0', |
| 67 |
status tinyint(3) unsigned NOT NULL default '0', |
status tinyint(3) unsigned NOT NULL default '0', |
| 68 |
PRIMARY KEY (cid, uid) |
PRIMARY KEY (cid, uid) |
| 69 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
| 70 |
$done[] = $result; |
$done[] = $result; |
| 71 |
|
|
| 72 |
$result = db_query(' |
$result = db_query(' |
| 73 |
SELECT * |
SELECT * |
| 74 |
FROM {false_accounts_old}' |
FROM {false_accounts_old}' |
| 75 |
); |
); |
| 76 |
|
|
| 77 |
// handle old data to fit into new table and instert |
// handle old data to fit into new table and instert |
| 78 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 79 |
if ($row->cid != '' && $row->uids != '' && $row->status >= 0) { |
if ($row->cid != '' && $row->uids != '' && $row->status >= 0) { |
| 80 |
$uids = explode(',', $row->uids); |
$uids = explode(',', $row->uids); |
| 81 |
|
|
| 82 |
for ($i = 0 ; $i < sizeof($uids) ; $i++) { |
for ($i = 0 ; $i < sizeof($uids) ; $i++) { |
| 83 |
$res = db_query(' |
$res = db_query(' |
| 84 |
INSERT INTO {false_accounts} (cid, uid, created, status) |
INSERT INTO {false_accounts} (cid, uid, created, status) |
| 85 |
VALUES ("%s", %d, %d, %d)', |
VALUES ("%s", %d, %d, %d)', |
| 86 |
$row->cid, $uids[$i], $row->updated, $row->status |
$row->cid, $uids[$i], $row->updated, $row->status |
| 87 |
); |
); |
| 88 |
$done[] = $res; |
$done[] = $res; |
| 89 |
} |
} |
| 90 |
} |
} |
| 91 |
} |
} |
| 92 |
if (! in_array(false, $done)) { |
if (! in_array(false, $done)) { |
| 93 |
drupal_set_message(t('False Account module upgraded successfully.')); |
drupal_set_message(t('False Account module upgraded successfully.')); |
| 94 |
} |
} |
| 95 |
else { |
else { |
| 96 |
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), |
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), |
| 97 |
'error'); |
'error'); |
| 98 |
} |
} |
| 99 |
} |
} |
| 100 |
else { |
else { |
| 101 |
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), 'error'); |
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), 'error'); |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
return $return; |
return $return; |
| 105 |
} |
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
function false_account_update_2() { |
| 109 |
|
|
| 110 |
|
$return = array(); |
| 111 |
|
$done = array(); |
| 112 |
|
|
| 113 |
|
$result = db_query(' |
| 114 |
|
SELECT cid, created |
| 115 |
|
FROM {false_accounts} |
| 116 |
|
GROUP BY cid |
| 117 |
|
ORDER BY created DESC' |
| 118 |
|
); |
| 119 |
|
|
| 120 |
|
while ($cookie = db_fetch_object($result)) { |
| 121 |
|
$done[] = db_query(' |
| 122 |
|
UPDATE {false_accounts} |
| 123 |
|
SET created = %d |
| 124 |
|
WHERE cid = "%s"', |
| 125 |
|
$cookie->created, $cookie->cid |
| 126 |
|
); |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
if (! in_array(false, $done)) { |
| 130 |
|
drupal_set_message(t('False Account module upgraded successfully.')); |
| 131 |
|
} |
| 132 |
|
else { |
| 133 |
|
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), |
| 134 |
|
'error'); |
| 135 |
|
} |
| 136 |
|
return $return; |
| 137 |
|
} |
| 138 |
|
|