| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Implementation of hook_install().
|
| 5 |
*/
|
| 6 |
function oi_install () {
|
| 7 |
drupal_install_schema('oi');
|
| 8 |
}
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_uninstall().
|
| 12 |
*/
|
| 13 |
function oi_uninstall() {
|
| 14 |
drupal_uninstall_schema('oi');
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implementation of hook_schema().
|
| 19 |
*/
|
| 20 |
function oi_schema () {
|
| 21 |
$schema = array(
|
| 22 |
'oi_entity_types' => array(
|
| 23 |
'description' => 'Possible entity types',
|
| 24 |
'fields' => array(
|
| 25 |
'etid' => array(
|
| 26 |
'description' => 'Entity type ID',
|
| 27 |
'type' => 'serial',
|
| 28 |
'not null' => TRUE,
|
| 29 |
'unsigned' => TRUE,
|
| 30 |
),
|
| 31 |
'etname' => array(
|
| 32 |
'description' => 'Name for this entity type',
|
| 33 |
'type' => 'varchar',
|
| 34 |
'not null' => TRUE,
|
| 35 |
'length' => 255,
|
| 36 |
),
|
| 37 |
'parent_etid' => array(
|
| 38 |
'description' => 'etid for parent entity type',
|
| 39 |
'type' => 'int',
|
| 40 |
'not null' => TRUE,
|
| 41 |
'unsigned' => TRUE,
|
| 42 |
'default' => 0,
|
| 43 |
),
|
| 44 |
'etweight' => array(
|
| 45 |
'description' => 'Weight of the entity type',
|
| 46 |
'type' => 'int',
|
| 47 |
'default' => 0,
|
| 48 |
),
|
| 49 |
),
|
| 50 |
'primary key' => array('etid'),
|
| 51 |
'unique keys' => array(
|
| 52 |
'oi_entity_types_etname' => array('etname'),
|
| 53 |
),
|
| 54 |
),
|
| 55 |
'oi_entity_type_roles' => array(
|
| 56 |
'description' => 'Roles available for an entity type',
|
| 57 |
'fields' => array(
|
| 58 |
'rtid' => array(
|
| 59 |
'description' => 'Role ID',
|
| 60 |
'type' => 'serial',
|
| 61 |
'not null' => TRUE,
|
| 62 |
'unsigned' => TRUE,
|
| 63 |
),
|
| 64 |
'etid' => array(
|
| 65 |
'description' => 'Entity type ID from {oi_entity_types}',
|
| 66 |
'type' => 'int',
|
| 67 |
'not null' => TRUE,
|
| 68 |
'unsigned' => TRUE,
|
| 69 |
),
|
| 70 |
'rtname' => array(
|
| 71 |
'description' => 'Internal role name (lower case, no spaces, underscores)',
|
| 72 |
'type' => 'varchar',
|
| 73 |
'not null' => TRUE,
|
| 74 |
'length' => 255,
|
| 75 |
),
|
| 76 |
'rtdisplay' => array(
|
| 77 |
'description' => 'Display role name',
|
| 78 |
'type' => 'varchar',
|
| 79 |
'not null' => TRUE,
|
| 80 |
'length' => 255,
|
| 81 |
),
|
| 82 |
'rtweight' => array(
|
| 83 |
'description' => 'Role weight',
|
| 84 |
'type' => 'int',
|
| 85 |
'not null' => TRUE,
|
| 86 |
'default' => 0,
|
| 87 |
),
|
| 88 |
),
|
| 89 |
'primary key' => array('rtid'),
|
| 90 |
'unique keys' => array(
|
| 91 |
'oi_entity_type_roles_rtname' => array('rtname'),
|
| 92 |
),
|
| 93 |
),
|
| 94 |
'oi_entity_type_fields' => array(
|
| 95 |
'description' => 'Fields available for an entity type',
|
| 96 |
'fields' => array(
|
| 97 |
'ftid' => array(
|
| 98 |
'description' => 'Field ID',
|
| 99 |
'type' => 'serial',
|
| 100 |
'not null' => TRUE,
|
| 101 |
'unsigned' => TRUE,
|
| 102 |
),
|
| 103 |
'etid' => array(
|
| 104 |
'description' => 'Entity type ID from {oi_entity_types}',
|
| 105 |
'type' => 'int',
|
| 106 |
'not null' => TRUE,
|
| 107 |
'unsigned' => TRUE,
|
| 108 |
),
|
| 109 |
'ftname' => array(
|
| 110 |
'description' => 'Internal field name (lower case, no spaces, underscores)',
|
| 111 |
'type' => 'varchar',
|
| 112 |
'not null' => TRUE,
|
| 113 |
'length' => 255,
|
| 114 |
),
|
| 115 |
'ftdisplay' => array(
|
| 116 |
'description' => 'Display field name',
|
| 117 |
'type' => 'varchar',
|
| 118 |
'not null' => TRUE,
|
| 119 |
'length' => 255,
|
| 120 |
),
|
| 121 |
'fttype' => array(
|
| 122 |
'description' => 'Type of field data (url, text, email, etc...)',
|
| 123 |
'type' => 'varchar',
|
| 124 |
'not null' => TRUE,
|
| 125 |
'length' => 30,
|
| 126 |
),
|
| 127 |
'ftparameters' => array(
|
| 128 |
'description' => 'Extra information, if needed, for the field type',
|
| 129 |
'type' => 'varchar',
|
| 130 |
'length' => 2000,
|
| 131 |
),
|
| 132 |
'ftweight' => array(
|
| 133 |
'description' => 'Field weight',
|
| 134 |
'type' => 'int',
|
| 135 |
'not null' => TRUE,
|
| 136 |
'default' => 0,
|
| 137 |
),
|
| 138 |
),
|
| 139 |
'primary key' => array('ftid'),
|
| 140 |
'unique keys' => array(
|
| 141 |
'oi_entity_type_fields_ftname' => array('ftname'),
|
| 142 |
),
|
| 143 |
),
|
| 144 |
'oi_entities' => array(
|
| 145 |
'description' => 'List of entities',
|
| 146 |
'fields' => array(
|
| 147 |
'eid' => array(
|
| 148 |
'description' => 'Entity ID',
|
| 149 |
'type' => 'serial',
|
| 150 |
'not null' => TRUE,
|
| 151 |
'unsigned' => TRUE,
|
| 152 |
),
|
| 153 |
'etid' => array(
|
| 154 |
'description' => 'Entity type ID from {oi_entity_types}',
|
| 155 |
'type' => 'int',
|
| 156 |
'not null' => TRUE,
|
| 157 |
'unsigned' => TRUE,
|
| 158 |
),
|
| 159 |
'name' => array(
|
| 160 |
'description' => 'Internal entity name (lower case, no spaces, underscores)',
|
| 161 |
'type' => 'varchar',
|
| 162 |
'not null' => TRUE,
|
| 163 |
'length' => 100,
|
| 164 |
),
|
| 165 |
'display' => array(
|
| 166 |
'description' => 'Display entity name',
|
| 167 |
'type' => 'varchar',
|
| 168 |
'not null' => TRUE,
|
| 169 |
'length' => 255,
|
| 170 |
),
|
| 171 |
'parent_eid' => array(
|
| 172 |
'description' => 'eid for parent entity',
|
| 173 |
'type' => 'int',
|
| 174 |
'not null' => TRUE,
|
| 175 |
'unsigned' => TRUE,
|
| 176 |
'default' => 0,
|
| 177 |
),
|
| 178 |
'propagate_membership' => array(
|
| 179 |
'description' => 'Does membership in this entity automatically go up the tree',
|
| 180 |
'type' => 'int',
|
| 181 |
'default' => 1,
|
| 182 |
),
|
| 183 |
'weight' => array(
|
| 184 |
'description' => 'Weight of the entity',
|
| 185 |
'type' => 'int',
|
| 186 |
'default' => 0,
|
| 187 |
),
|
| 188 |
),
|
| 189 |
'primary key' => array('eid'),
|
| 190 |
'unique keys' => array(
|
| 191 |
'oi_entities_name' => array('name'),
|
| 192 |
),
|
| 193 |
),
|
| 194 |
'oi_entity_roles' => array(
|
| 195 |
'description' => 'Members of a role for a particular entity',
|
| 196 |
'fields' => array(
|
| 197 |
'eid' => array(
|
| 198 |
'description' => 'Entity ID from {oi_entities}',
|
| 199 |
'type' => 'int',
|
| 200 |
'not null' => TRUE,
|
| 201 |
'unsigned' => TRUE,
|
| 202 |
),
|
| 203 |
'rtid' => array(
|
| 204 |
'description' => 'Role ID from {oi_entity_type_roles}',
|
| 205 |
'type' => 'int',
|
| 206 |
'not null' => TRUE,
|
| 207 |
'unsigned' => TRUE,
|
| 208 |
),
|
| 209 |
'uid' => array(
|
| 210 |
'description' => 'User ID from {user}',
|
| 211 |
'type' => 'int',
|
| 212 |
'not null' => TRUE,
|
| 213 |
'unsigned' => TRUE,
|
| 214 |
),
|
| 215 |
'weight' => array(
|
| 216 |
'description' => 'Member weight',
|
| 217 |
'type' => 'int',
|
| 218 |
'not null' => TRUE,
|
| 219 |
'default' => 0,
|
| 220 |
),
|
| 221 |
),
|
| 222 |
'primary key' => array('eid', 'rtid', 'uid'),
|
| 223 |
),
|
| 224 |
'oi_entity_fields' => array(
|
| 225 |
'description' => 'Value of fields for a particular entity',
|
| 226 |
'fields' => array(
|
| 227 |
'eid' => array(
|
| 228 |
'description' => 'Entity ID from {oi_entities}',
|
| 229 |
'type' => 'int',
|
| 230 |
'not null' => TRUE,
|
| 231 |
'unsigned' => TRUE,
|
| 232 |
),
|
| 233 |
'ftid' => array(
|
| 234 |
'description' => 'Field ID from {oi_entity_fields}',
|
| 235 |
'type' => 'int',
|
| 236 |
'not null' => TRUE,
|
| 237 |
'unsigned' => TRUE,
|
| 238 |
),
|
| 239 |
'fvalue' => array(
|
| 240 |
'description' => 'Field value for this entity',
|
| 241 |
'type' => 'varchar',
|
| 242 |
'length' => 255,
|
| 243 |
),
|
| 244 |
),
|
| 245 |
'primary key' => array('eid', 'ftid'),
|
| 246 |
),
|
| 247 |
'oi_entity_members' => array(
|
| 248 |
'description' => 'Members of an entity',
|
| 249 |
'fields' => array(
|
| 250 |
'eid' => array(
|
| 251 |
'description' => 'Entity ID from {oi_entities}',
|
| 252 |
'type' => 'int',
|
| 253 |
'not null' => TRUE,
|
| 254 |
'unsigned' => TRUE,
|
| 255 |
),
|
| 256 |
'uid' => array(
|
| 257 |
'description' => 'User ID from {user}',
|
| 258 |
'type' => 'int',
|
| 259 |
'not null' => TRUE,
|
| 260 |
'unsigned' => TRUE,
|
| 261 |
),
|
| 262 |
'membership_type' => array(
|
| 263 |
'description' => 'What kind of access is allowed for this user',
|
| 264 |
'type' => 'int',
|
| 265 |
'not null' => TRUE,
|
| 266 |
'default' => 0,
|
| 267 |
),
|
| 268 |
),
|
| 269 |
'primary key' => array('eid', 'uid'),
|
| 270 |
),
|
| 271 |
'oi_node_restrictions' => array(
|
| 272 |
'description' => 'Node access information',
|
| 273 |
'fields' => array(
|
| 274 |
'nid' => array(
|
| 275 |
'description' => 'Node ID from {node}',
|
| 276 |
'type' => 'int',
|
| 277 |
'not null' => TRUE,
|
| 278 |
'unsigned' => TRUE,
|
| 279 |
),
|
| 280 |
'eid' => array(
|
| 281 |
'description' => 'Entity ID from {oi_entities}',
|
| 282 |
'type' => 'int',
|
| 283 |
'not null' => TRUE,
|
| 284 |
'unsigned' => TRUE,
|
| 285 |
),
|
| 286 |
),
|
| 287 |
'primary key' => array('nid', 'eid'),
|
| 288 |
),
|
| 289 |
);
|
| 290 |
|
| 291 |
return $schema;
|
| 292 |
}
|
| 293 |
|
| 294 |
|
| 295 |
/**
|
| 296 |
* Will need to add update function.
|
| 297 |
*
|
| 298 |
* This function should pick the maximum ids for each of the serial tables,
|
| 299 |
* run a fake insert up to that id, then delete non-existant ids, then
|
| 300 |
* copy from the old table.
|
| 301 |
*/
|