| 1 |
<?php
|
| 2 |
// $Id: checkout.install,v 1.1.2.2 2007/12/02 03:39:19 smk Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function checkout_install() {
|
| 8 |
switch ($GLOBALS['db_type']) {
|
| 9 |
case 'mysql':
|
| 10 |
case 'mysqli':
|
| 11 |
db_query("
|
| 12 |
CREATE TABLE {checkout} (
|
| 13 |
nid int(10) unsigned NOT NULL default '0',
|
| 14 |
uid int(10) unsigned NOT NULL default '0',
|
| 15 |
persistent tinyint(1) unsigned NOT NULL default '0',
|
| 16 |
timestamp int(10) unsigned NOT NULL default '0',
|
| 17 |
PRIMARY KEY (nid),
|
| 18 |
KEY (uid)
|
| 19 |
) /*!40100 DEFAULT CHARACTER SET utf8 */"
|
| 20 |
);
|
| 21 |
break;
|
| 22 |
|
| 23 |
case 'pgsql':
|
| 24 |
db_query("
|
| 25 |
CREATE TABLE {checkout} (
|
| 26 |
nid INTEGER NOT NULL DEFAULT 0,
|
| 27 |
uid INTEGER NOT NULL DEFAULT 0,
|
| 28 |
persistent SMALLINT NOT NULL DEFAULT 0,
|
| 29 |
timestamp INTEGER NOT NULL DEFAULT 0,
|
| 30 |
PRIMARY KEY (nid)
|
| 31 |
)"
|
| 32 |
);
|
| 33 |
db_query("CREATE INDEX {checkout}_uid_idx ON {checkout}(uid)");
|
| 34 |
break;
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_uninstall().
|
| 40 |
*/
|
| 41 |
function checkout_uninstall() {
|
| 42 |
db_query("DROP TABLE {checkout}");
|
| 43 |
variable_del('checkout_clear');
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Helper function to add a permission to a role.
|
| 48 |
*/
|
| 49 |
function _checkout_add_permission($rid, $permission) {
|
| 50 |
if ($permission) {
|
| 51 |
$current_perm = db_result(db_query("SELECT perm FROM {permission} WHERE rid = %d", $rid));
|
| 52 |
if ($current_perm != '') {
|
| 53 |
$current_perm .= ', ';
|
| 54 |
}
|
| 55 |
$current_perm .= $permission;
|
| 56 |
db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $current_perm, $rid);
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Update schema from Drupal 4.7.x to 5.x.
|
| 62 |
*/
|
| 63 |
function checkout_update_1() {
|
| 64 |
$ret = array();
|
| 65 |
switch ($GLOBALS['db_type']) {
|
| 66 |
case 'mysql':
|
| 67 |
case 'mysqli':
|
| 68 |
$ret[] = update_sql("ALTER TABLE {checkout} CHANGE checkedout persistent tinyint(1) unsigned NOT NULL default '0'");
|
| 69 |
$ret[] = update_sql("ALTER TABLE {checkout} CHANGE date timestamp int(10) unsigned NOT NULL default '0'");
|
| 70 |
$ret[] = update_sql("ALTER TABLE {checkout} ADD KEY uid (uid)");
|
| 71 |
break;
|
| 72 |
|
| 73 |
case 'pgsql':
|
| 74 |
db_change_column($ret, 'checkout', 'checkedout', 'persistent', 'smallint', array('not null' => TRUE, 'default' => 0));
|
| 75 |
db_change_column($ret, 'checkout', 'date', 'timestamp', 'integer', array('not null' => TRUE, 'default' => 0));
|
| 76 |
$ret[] = update_sql("CREATE INDEX {checkout}_uid_idx ON {checkout}(uid)");
|
| 77 |
break;
|
| 78 |
}
|
| 79 |
return $ret;
|
| 80 |
}
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Move the persistent check-out setting to the permissions table.
|
| 84 |
*/
|
| 85 |
function checkout_update_2() {
|
| 86 |
$ret = array();
|
| 87 |
|
| 88 |
// When persistent check-out was enabled, add a permission to every role
|
| 89 |
// that has the "check out documents" permission.
|
| 90 |
if (variable_get('checkout_long', 0)) {
|
| 91 |
foreach (user_roles(0, 'check out documents') as $rid => $role) {
|
| 92 |
_checkout_add_permission($rid, 'keep documents checked out');
|
| 93 |
}
|
| 94 |
}
|
| 95 |
variable_del('checkout_long');
|
| 96 |
|
| 97 |
$ret[] = array(
|
| 98 |
'query' => 'The access permissions have been updated by the checkout module.',
|
| 99 |
'success' => TRUE
|
| 100 |
);
|
| 101 |
return $ret;
|
| 102 |
}
|
| 103 |
|