naught101: coding/comment style cleanup
[project/relation.git] / relation.install
CommitLineData
422452ff 1<?php
422452ff 2
3/**
4 * @file
5 * Installation functions for Relation module.
6 */
7
caefa4c9 8/**
9abc330f 9 * Implements hook_schema().
caefa4c9 10 */
9abc330f
KN
11function relation_schema() {
12 $schema['relation'] = array(
13 'description' => 'Keeps track of relation entities.',
14 'fields' => array(
6ee02379 15 'rid' => array(
9abc330f
KN
16 'type' => 'serial',
17 'unsigned' => TRUE,
caefa4c9 18 'not null' => TRUE,
38d17c2c 19 'description' => 'Unique relation id (entity id).',
caefa4c9 20 ),
eec23b0d 21 'relation_type' => array(
caefa4c9 22 'type' => 'varchar',
23 'length' => 255,
24 'not null' => TRUE,
25 'default' => '',
38d17c2c 26 'description' => 'Relation type (see relation_type table).',
caefa4c9 27 ),
7a1572cf 28 'vid' => array(
29 'description' => 'The current {relation_revision}.vid version identifier.',
30 'type' => 'int',
31 'unsigned' => TRUE,
32 'not null' => TRUE,
33 'default' => 0,
34 ),
35 'uid' => array(
36 'description' => 'The {users}.uid that owns this relation; initially, this is the user that created it.',
37 'type' => 'int',
38 'not null' => TRUE,
39 'default' => 0,
40 ),
41 'created' => array(
42 'description' => 'The Unix timestamp when the relation was created.',
43 'type' => 'int',
44 'not null' => TRUE,
45 'default' => 0,
46 ),
47 'changed' => array(
48 'description' => 'The Unix timestamp when the relation was most recently saved.',
49 'type' => 'int',
50 'not null' => TRUE,
51 'default' => 0,
52 ),
a382bec8 53 'arity' => array(
d10d15b5
KN
54 'type' => 'int',
55 'unsigned' => TRUE,
56 'not null' => TRUE,
57 'default' => 0,
38d17c2c 58 'description' => 'The number rows in this relation. Cannot exceed max_arity, or be less than min_arity in relation_type table.',
d10d15b5 59 ),
9abc330f 60 ),
6ee02379 61 'primary key' => array('rid'),
9abc330f 62 'indexes' => array(
eec23b0d 63 'relation_types' => array('relation_type', 'rid'),
9abc330f
KN
64 ),
65 );
a7955cc5 66 $schema['relation_revision'] = array(
67 'description' => 'Keeps track of relation entities.',
68 'fields' => array(
69 'rid' => array(
70 'type' => 'int',
71 'unsigned' => TRUE,
72 'not null' => TRUE,
73 'default' => 0,
74 'description' => 'Unique relation id (entity id).',
75 ),
eec23b0d 76 'relation_type' => array(
a7955cc5 77 'type' => 'varchar',
78 'length' => 255,
79 'not null' => TRUE,
80 'default' => '',
81 'description' => 'Relation type (see relation_type table).',
82 ),
83 'vid' => array(
84 'description' => 'The current {relation_revision}.vid version identifier.',
85 'type' => 'serial',
86 'unsigned' => TRUE,
87 'not null' => TRUE,
88 ),
89 'uid' => array(
90 'description' => 'The {users}.uid that owns this relation; initially, this is the user that created it.',
91 'type' => 'int',
92 'not null' => TRUE,
93 'default' => 0,
94 ),
95 'changed' => array(
96 'description' => 'The Unix timestamp when the relation was most recently saved.',
97 'type' => 'int',
98 'not null' => TRUE,
99 'default' => 0,
100 ),
101 'arity' => array(
102 'type' => 'int',
103 'unsigned' => TRUE,
104 'not null' => TRUE,
105 'default' => 0,
106 'description' => 'The number rows in this relation. Cannot exceed max_arity, or be less than min_arity in relation_type table.',
107 ),
108 ),
93655d55
KN
109 'primary key' => array('vid'),
110 'indexes' => array(
111 'rid_vid' => array('rid', 'vid'),
112 ),
a7955cc5 113 );
8f82a0d6 114 $schema['relation_type'] = array(
47d406dc 115 'description' => 'Relation settings.',
e53efde4 116 // Add exportability using ctools.
117 'export' => array(
118 'key' => 'relation_type',
119 'identifier' => 'relation_type',
120 'default hook' => 'relation_default_relation_types', // Function hook name.
121 'api' => array(
122 'owner' => 'relation',
123 'api' => 'relation_default', // Base name for api include files.
124 'minimum_version' => 1,
125 'current_version' => 1,
126 ),
127 // the callback to load the available bundles
128 'subrecords callback' => '_relation_get_types_bundles',
129 ),
47d406dc 130 'fields' => array(
eec23b0d 131 'relation_type' => array(
47d406dc
KN
132 'type' => 'varchar',
133 'length' => 255,
134 'not null' => TRUE,
135 'default' => '',
8f82a0d6 136 'description' => 'The machine-readable name of this type.',
8f82a0d6 137 ),
9fde2188 138 'label' => array(
8f82a0d6 139 'type' => 'varchar',
140 'length' => 255,
141 'not null' => TRUE,
142 'default' => '',
143 'description' => 'The human-readable name of this type.',
47d406dc 144 ),
02a73ef5 145 'reverse_label' => array(
146 'type' => 'varchar',
147 'length' => 255,
148 'not null' => TRUE,
149 'default' => '',
150 'description' => 'The reverse human-readable name of this type. Only used for directional relations.',
151 ),
47d406dc
KN
152 'directional' => array(
153 'type' => 'int',
154 'unsigned' => TRUE,
155 'not null' => TRUE,
156 'default' => 0,
38d17c2c 157 'description' => 'Whether this relation type is directional. If not, all indexes are ignored.',
8f82a0d6 158 ),
64505414 159 'transitive' => array(
160 'type' => 'int',
161 'unsigned' => TRUE,
162 'not null' => TRUE,
163 'default' => 0,
164 'description' => 'Whether this relation type is transitive.',
165 ),
d7f42449 166 'r_unique' => array(
167 'type' => 'int',
168 'unsigned' => TRUE,
169 'not null' => TRUE,
170 'default' => 0,
171 'description' => 'Whether relations of this type are unique.',
172 ),
38d17c2c 173 'min_arity' => array(
8f82a0d6 174 'type' => 'int',
175 'unsigned' => TRUE,
176 'not null' => TRUE,
177 'default' => 2,
38d17c2c 178 'description' => 'The minimum number of rows that can make up a relation of this type.',
179 ),
180 'max_arity' => array(
181 'type' => 'int',
182 'unsigned' => TRUE,
183 'not null' => TRUE,
184 'default' => 2,
185 'description' => 'The maximum number of rows that can make up a relation of this type. Similar to field cardinality.',
47d406dc
KN
186 ),
187 ),
eec23b0d 188 'primary key' => array('relation_type'),
47d406dc
KN
189 );
190 $schema['relation_bundles'] = array(
38d17c2c 191 'description' => 'Relation type available bundles',
47d406dc 192 'fields' => array(
eec23b0d 193 'relation_type' => array(
47d406dc
KN
194 'type' => 'varchar',
195 'length' => 255,
196 'not null' => TRUE,
197 'default' => '',
38d17c2c 198 'description' => 'The relation type.',
47d406dc
KN
199 ),
200 'entity_type' => array(
201 'type' => 'varchar',
202 'length' => 255,
203 'not null' => TRUE,
204 'default' => '',
38d17c2c 205 'description' => 'Entity type that is available to this relation.',
47d406dc
KN
206 ),
207 'bundle' => array(
208 'type' => 'varchar',
209 'length' => 255,
210 'not null' => TRUE,
211 'default' => '',
38d17c2c 212 'description' => 'Entity bundle that is available to this relation.',
213 ),
243670d7 214 'r_index' => array(
38d17c2c 215 'type' => 'int',
216 'not null' => TRUE,
217 'default' => 0,
218 'description' => 'Direction index for relations: 0=from, 1=to. The index is ignored if the directional column in the relation_type table is 0.',
47d406dc
KN
219 ),
220 ),
221 );
cab16c0c 222 return $schema;
caefa4c9 223}
8c89308c
KN
224
225/**
2cb4c39c 226 * Implements hook_uninstall().
8c89308c 227 */
2cb4c39c 228function relation_uninstall() {
229 // Remove fields attached to relation type bundles.
230 $types = db_query("SELECT relation_type FROM {relation_type}")->fetchCol();
231 foreach ($types as $type) {
232 field_attach_delete_bundle('relation', $type);
233 }
8c89308c 234}
247044b6 235
236/**
237 * Implements hook_update_N().
238 */
239function hook_update_7001() {
240 module_enable(array('relation_endpoints'));
241}