| 1 |
<?php |
<?php |
| 2 |
// $Id: false_account.install,v 1.2 2008/03/08 14:59:31 introfini Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_install() |
* @file |
| 6 |
* just give a message |
* Schema installation for false account module |
| 7 |
*/ |
*/ |
| 8 |
function false_account_install() { |
|
| 9 |
switch ($GLOBALS['db_type']) { |
/** |
| 10 |
case 'mysql': |
* Implementation of hook_install() |
| 11 |
case 'mysqli': |
*/ |
| 12 |
$created = db_query(" |
function false_account_install() { |
| 13 |
CREATE TABLE IF NOT EXISTS {false_accounts} ( |
$created = drupal_install_schema('false_account'); |
| 14 |
cid varchar(64) NOT NULL, |
|
| 15 |
uid int(10) NOT NULL, |
if ($created['success']) { |
| 16 |
created int(11) unsigned NOT NULL default '0', |
drupal_set_message(t('False Account module installed successfully.')); |
| 17 |
status tinyint(3) unsigned NOT NULL default '0', |
} |
| 18 |
PRIMARY KEY (cid, uid) |
else { |
| 19 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error'); |
| 20 |
break; |
} |
| 21 |
} |
|
| 22 |
|
} |
| 23 |
if ($created) { |
|
| 24 |
drupal_set_message(t('False Account module installed successfully.')); |
|
| 25 |
} |
/** |
| 26 |
else { |
* Implementation of hook_update_N() |
| 27 |
drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error'); |
* new DB structure |
| 28 |
} |
*/ |
| 29 |
} |
function false_account_update_1() { |
| 30 |
|
|
| 31 |
|
$return = array(); |
| 32 |
/** |
$done = array(); |
| 33 |
* Implementation of hook_update_N() |
|
| 34 |
* new DB structure |
$result = db_query(' |
| 35 |
*/ |
SELECT cid, created |
| 36 |
function false_account_update_1() { |
FROM {false_accounts} |
| 37 |
|
GROUP BY cid |
| 38 |
$return = array(); |
ORDER BY created DESC' |
| 39 |
$done = array(); |
); |
| 40 |
|
|
| 41 |
// replicate table |
while ($cookie = db_fetch_object($result)) { |
| 42 |
$result = db_query(' |
$done[] = db_query(' |
| 43 |
CREATE TABLE IF NOT EXISTS {false_accounts_old} |
UPDATE {false_accounts} |
| 44 |
LIKE {false_accounts}' |
SET created = %d |
| 45 |
); |
WHERE cid = "%s"', |
| 46 |
$done[] = $result; |
$cookie->created, $cookie->cid |
| 47 |
|
); |
| 48 |
$result = db_query(' |
} |
| 49 |
INSERT {false_accounts_old} |
|
| 50 |
SELECT * |
if (! in_array(false, $done)) { |
| 51 |
FROM {false_accounts}' |
drupal_set_message(t('False Account module upgraded successfully.')); |
| 52 |
); |
} |
| 53 |
$done[] = $result; |
else { |
| 54 |
|
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), |
| 55 |
// avoid data destruction if copy actions haven't succeed |
'error'); |
| 56 |
if (! in_array(false, $done)) { |
} |
| 57 |
$done = array(); |
return $return; |
| 58 |
|
} |
| 59 |
$result = db_query('DROP TABLE {false_accounts}'); |
|
| 60 |
$done[] = $result; |
|
| 61 |
|
/** |
| 62 |
$created = db_query(" |
* Implementation of hook_schema() |
| 63 |
CREATE TABLE IF NOT EXISTS {false_accounts} ( |
*/ |
| 64 |
cid varchar(64) NOT NULL, |
function false_account_schema() { |
| 65 |
uid int(10) NOT NULL, |
$schema['false_accounts'] = array( |
| 66 |
created int(11) unsigned NOT NULL default '0', |
'fields' => array( |
| 67 |
status tinyint(3) unsigned NOT NULL default '0', |
'cid' => array('type' => 'varchar', 'length' => '64', 'not null' => TRUE), |
| 68 |
PRIMARY KEY (cid, uid) |
'uid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10'), |
| 69 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, |
| 70 |
$done[] = $result; |
'disp-width' => '11'), |
| 71 |
|
'status' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, |
| 72 |
$result = db_query(' |
'default' => 0, 'disp-width' => '3') |
| 73 |
SELECT * |
), |
| 74 |
FROM {false_accounts_old}' |
'primary key' => array('cid', 'uid'), |
| 75 |
); |
); |
| 76 |
|
|
| 77 |
// handle old data to fit into new table and instert |
return $schema; |
| 78 |
while ($row = db_fetch_object($result)) { |
} |
| 79 |
if ($row->cid != '' && $row->uids != '' && $row->status >= 0) { |
|
| 80 |
$uids = explode(',', $row->uids); |
|
|
|
|
|
for ($i = 0 ; $i < sizeof($uids) ; $i++) { |
|
|
$res = db_query(' |
|
|
INSERT INTO {false_accounts} (cid, uid, created, status) |
|
|
VALUES ("%s", %d, %d, %d)', |
|
|
$row->cid, $uids[$i], $row->updated, $row->status |
|
|
); |
|
|
$done[] = $res; |
|
|
} |
|
|
} |
|
|
} |
|
|
if (! in_array(false, $done)) { |
|
|
drupal_set_message(t('False Account module upgraded successfully.')); |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), |
|
|
'error'); |
|
|
} |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), 'error'); |
|
|
} |
|
|
|
|
|
return $return; |
|
|
} |
|
|
|
|