| 1 |
<?php
|
| 2 |
// $Id: actions.install,v 1.12 2008/09/21 01:50:22 jvandyk Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function actions_install() {
|
| 8 |
|
| 9 |
switch ($GLOBALS['db_type']) {
|
| 10 |
case 'mysql':
|
| 11 |
case 'mysqli':
|
| 12 |
// Stores action information.
|
| 13 |
db_query("CREATE TABLE {actions} (
|
| 14 |
aid varchar (255) not null default '0',
|
| 15 |
type varchar(255) not null default '',
|
| 16 |
callback varchar(255) not null default '',
|
| 17 |
parameters longtext not null,
|
| 18 |
description varchar(255) not null default '0',
|
| 19 |
PRIMARY KEY (aid)
|
| 20 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 21 |
|
| 22 |
// Stores action IDs for non-default actions.
|
| 23 |
db_query("CREATE TABLE {actions_aid} (
|
| 24 |
aid bigint unsigned not null auto_increment,
|
| 25 |
PRIMARY KEY (aid)
|
| 26 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 27 |
|
| 28 |
// Maps action to hook and operation assignments from actions.module.
|
| 29 |
db_query("CREATE TABLE {actions_assignments} (
|
| 30 |
hook varchar(32) not null default '',
|
| 31 |
op varchar(46) not null default '',
|
| 32 |
aid varchar(255) not null default '',
|
| 33 |
weight int not null default '0',
|
| 34 |
PRIMARY KEY (hook, op, aid)
|
| 35 |
) ENGINE=INNODB /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 36 |
break;
|
| 37 |
|
| 38 |
case 'pgsql':
|
| 39 |
// Stores action information.
|
| 40 |
db_query("CREATE TABLE {actions} (
|
| 41 |
aid varchar (255) not null default '0',
|
| 42 |
type varchar(255) not null default '',
|
| 43 |
callback varchar(255) not null default '',
|
| 44 |
parameters text not null,
|
| 45 |
description varchar(255) not null default '0',
|
| 46 |
PRIMARY KEY (aid)
|
| 47 |
)");
|
| 48 |
|
| 49 |
// Stores action IDs for non-default actions.
|
| 50 |
db_query("CREATE TABLE {actions_aid} (
|
| 51 |
aid serial,
|
| 52 |
PRIMARY KEY (aid)
|
| 53 |
)");
|
| 54 |
|
| 55 |
// Maps action to hook and operation assignments from actions.module.
|
| 56 |
db_query("CREATE TABLE {actions_assignments} (
|
| 57 |
hook varchar(32) not null default '',
|
| 58 |
op varchar(40) not null default '',
|
| 59 |
aid varchar(255) not null default '',
|
| 60 |
weight int not null default '0' CHECK (weight >= 0),
|
| 61 |
PRIMARY KEY (hook, op, aid)
|
| 62 |
)");
|
| 63 |
break;
|
| 64 |
|
| 65 |
case 'mssql':
|
| 66 |
// Stores action information.
|
| 67 |
db_query("CREATE TABLE {actions} (
|
| 68 |
aid varchar(255) not null default '0',
|
| 69 |
type varchar(255) not null default '',
|
| 70 |
callback varchar(255) not null default '',
|
| 71 |
parameters varchar(8000) not null,
|
| 72 |
description varchar(255) not null default '0',
|
| 73 |
PRIMARY KEY (aid)
|
| 74 |
)");
|
| 75 |
|
| 76 |
// Stores action IDs for non-default actions.
|
| 77 |
db_query("CREATE TABLE {actions_aid} (
|
| 78 |
aid bigint not null unique identity(1,1),
|
| 79 |
PRIMARY KEY (aid)
|
| 80 |
)");
|
| 81 |
|
| 82 |
// Allow identity inserts.
|
| 83 |
db_query("SET IDENTITY_INSERT {actions_aid} ON");
|
| 84 |
|
| 85 |
// Maps action to hook and operation assignments from actions.module.
|
| 86 |
db_query("CREATE TABLE {actions_assignments} (
|
| 87 |
hook varchar(32) not null default '',
|
| 88 |
op varchar(46) not null default '',
|
| 89 |
aid varchar(255) not null default '',
|
| 90 |
weight int not null default '0',
|
| 91 |
PRIMARY KEY (hook, op, aid)
|
| 92 |
)");
|
| 93 |
break;
|
| 94 |
|
| 95 |
}
|
| 96 |
|
| 97 |
// Do initial synchronization of actions in code and the database.
|
| 98 |
include_once(drupal_get_path('module', 'actions') .'/actions.module');
|
| 99 |
actions_synchronize(actions_list());
|
| 100 |
}
|
| 101 |
|
| 102 |
/**
|
| 103 |
* Implementation of hook_uninstall().
|
| 104 |
*/
|
| 105 |
function actions_uninstall() {
|
| 106 |
// Remove tables.
|
| 107 |
db_query('DROP TABLE {actions}');
|
| 108 |
db_query('DROP TABLE {actions_aid}');
|
| 109 |
db_query('DROP TABLE {actions_assignments}');
|
| 110 |
if (db_table_exists('actions_old')) {
|
| 111 |
db_query('DROP TABLE {actions_old}');
|
| 112 |
}
|
| 113 |
if (db_table_exists('actions_registry')) {
|
| 114 |
db_query('DROP TABLE {actions_registry}');
|
| 115 |
}
|
| 116 |
}
|
| 117 |
|
| 118 |
function actions_update_10() {
|
| 119 |
|
| 120 |
$ret = array();
|
| 121 |
switch ($GLOBALS['db_type']) {
|
| 122 |
case 'mysql':
|
| 123 |
case 'mysqli':
|
| 124 |
// Stash the user's data for safekeeping.
|
| 125 |
$ret[] = update_sql("ALTER TABLE {actions} RENAME TO {actions_old}");
|
| 126 |
|
| 127 |
// Stores action information.
|
| 128 |
$ret[] = update_sql("CREATE TABLE {actions} (
|
| 129 |
aid varchar (255) not null default '0',
|
| 130 |
type varchar(255) not null default '',
|
| 131 |
callback varchar(255) not null default '',
|
| 132 |
parameters longtext not null,
|
| 133 |
description varchar(255) not null default '0',
|
| 134 |
PRIMARY KEY (aid)
|
| 135 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 136 |
|
| 137 |
// Stores action IDs for non-default actions.
|
| 138 |
$ret[] = update_sql("CREATE TABLE {actions_aid} (
|
| 139 |
aid bigint unsigned not null auto_increment unique,
|
| 140 |
PRIMARY KEY (aid)
|
| 141 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 142 |
|
| 143 |
// Maps action to hook and operation assignments from actions.module.
|
| 144 |
$ret[] = update_sql("CREATE TABLE {actions_assignments} (
|
| 145 |
hook varchar(32) not null default '',
|
| 146 |
op varchar(32) not null default '',
|
| 147 |
aid varchar(255) not null default '',
|
| 148 |
weight int not null default '0',
|
| 149 |
PRIMARY KEY (hook, op, aid)
|
| 150 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 151 |
break;
|
| 152 |
|
| 153 |
case 'pgsql':
|
| 154 |
// Stash the user's data for safekeeping.
|
| 155 |
$ret[] = update_sql("ALTER TABLE {actions} RENAME TO {actions_old}");
|
| 156 |
|
| 157 |
// Stores action information.
|
| 158 |
$ret[] = update_sql("CREATE TABLE {actions} (
|
| 159 |
aid varchar (255) not null default '0',
|
| 160 |
type varchar(255) not null default '',
|
| 161 |
callback varchar(255) not null default '',
|
| 162 |
parameters text not null,
|
| 163 |
description varchar(255) not null default '0',
|
| 164 |
PRIMARY KEY (aid)
|
| 165 |
)");
|
| 166 |
|
| 167 |
// Stores action IDs for non-default actions.
|
| 168 |
$ret[] = update_sql("CREATE TABLE {actions_aid} (
|
| 169 |
aid serial,
|
| 170 |
PRIMARY KEY (aid)
|
| 171 |
)");
|
| 172 |
|
| 173 |
// Maps action to hook and operation assignments from actions.module.
|
| 174 |
$ret[] = update_sql("CREATE TABLE {actions_assignments} (
|
| 175 |
hook varchar(32) not null default '',
|
| 176 |
op varchar(32) not null default '',
|
| 177 |
aid varchar(255) not null default '',
|
| 178 |
weight int not null default '0' CHECK (weight >= 0),
|
| 179 |
PRIMARY KEY (hook, op, aid)
|
| 180 |
)");
|
| 181 |
break;
|
| 182 |
}
|
| 183 |
return $ret;
|
| 184 |
|
| 185 |
// Do initial synchronization of actions in code and the database.
|
| 186 |
include_once(drupal_get_path('module', 'actions') .'/actions.module');
|
| 187 |
actions_synchronize(actions_list());
|
| 188 |
}
|
| 189 |
|
| 190 |
// 32 chars is a little small for op. Use 40 instead.
|
| 191 |
function actions_update_5200() {
|
| 192 |
$ret = array();
|
| 193 |
switch ($GLOBALS['db_type']) {
|
| 194 |
case 'mysql':
|
| 195 |
case 'mysqli':
|
| 196 |
$ret[] = update_sql("ALTER TABLE {actions_assignments} CHANGE op op VARCHAR(40)");
|
| 197 |
break;
|
| 198 |
|
| 199 |
case 'pgsql':
|
| 200 |
$ret[] = update_sql("BEGIN;
|
| 201 |
ALTER TABLE {actions_assignments} ADD COLUMN op_temp VARCHAR(40);
|
| 202 |
UPDATE op_temp SET new_col = CAST(op AS VARCHAR(40));
|
| 203 |
ALTER TABLE {actions_assignments} DROP COLUMN op;
|
| 204 |
RENAME op_temp TO op;
|
| 205 |
COMMIT;");
|
| 206 |
break;
|
| 207 |
}
|
| 208 |
return $ret;
|
| 209 |
}
|
| 210 |
|
| 211 |
/**
|
| 212 |
* Remove the underscores from the administer actions permission
|
| 213 |
* on existing permission assignments.
|
| 214 |
*
|
| 215 |
* @return array
|
| 216 |
*/
|
| 217 |
function actions_update_5201() {
|
| 218 |
$ret = array();
|
| 219 |
$ret[] = update_sql("UPDATE {permission} SET perm = REPLACE(perm, 'administer_actions', 'administer actions') WHERE perm LIKE '%administer_actions%'");
|
| 220 |
return $ret;
|
| 221 |
}
|
| 222 |
|
| 223 |
// 40 chars is still a little small for op. Use 46 instead.
|
| 224 |
// Can't use more because compound key becomes larger than
|
| 225 |
// MySQL's 1000-byte limit. See http://drupal.org/node/309919
|
| 226 |
function actions_update_5202() {
|
| 227 |
$ret = array();
|
| 228 |
switch ($GLOBALS['db_type']) {
|
| 229 |
case 'mysql':
|
| 230 |
case 'mysqli':
|
| 231 |
$ret[] = update_sql("ALTER TABLE {actions_assignments} CHANGE op op VARCHAR(46)");
|
| 232 |
break;
|
| 233 |
|
| 234 |
case 'pgsql':
|
| 235 |
$ret[] = update_sql("BEGIN;
|
| 236 |
ALTER TABLE {actions_assignments} ADD COLUMN op_temp VARCHAR(46);
|
| 237 |
UPDATE op_temp SET new_col = CAST(op AS VARCHAR(46));
|
| 238 |
ALTER TABLE {actions_assignments} DROP COLUMN op;
|
| 239 |
RENAME op_temp TO op;
|
| 240 |
COMMIT;");
|
| 241 |
break;
|
| 242 |
}
|
| 243 |
return $ret;
|
| 244 |
}
|