-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileshare.install
211 lines (203 loc) · 5.59 KB
/
fileshare.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* @file
* Install, update, and uninstall functions for the fileshare module.
*
* @todo Implement hook_uninstall().
*/
/**
* Implements hook_schema().
*/
function fileshare_schema() {
$schema = array();
$schema['fileshare'] = array(
'description' => 'The base table for fileshare entities.',
'fields' => array(
'fileshare_id' => array(
'description' => 'The primary identifier for a fileshare entity.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The {fileshare_type}.type of this fileshare entity.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'sender' => array(
'description' => 'The {users}.uid that created this fileshare entity.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'recipient' => array(
'description' => 'The {users}.uid to whom this fileshare is being sent.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'subject' => array(
'description' => 'The name of the fileshare - a human-readable identifier.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'A value indicating the send status of the bundle: 0 = sent, 1 = read.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'date_sent' => array(
'description' => 'The Unix timestamp when the bundle was sent.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'date_read' => array(
'description' => 'The Unix timestamp when the bundle was read.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'data' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional data.',
),
),
'primary key' => array('fileshare_id'),
'indexes' => array(
'type' => array('type'),
),
'foreign keys' => array(
'sender' => array(
'table' => 'users',
'columns' => array('sender' => 'uid'),
),
'recipient' => array(
'table' => 'users',
'columns' => array('recipient' => 'uid'),
),
)
);
$schema['fileshare_type'] = array(
'description' => 'Stores information about defined fileshare types.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'The primary identifier of the fileshare type entity.',
),
'type' => array(
'description' => 'The machine-readable name of this fileshare type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable name of this fileshare type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The weight of this fileshare type in relation to others.',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional data related to this fileshare type.',
),
) + entity_exportable_schema_fields(),
'primary key' => array('id'),
'unique keys' => array(
'type' => array('type'),
),
);
return $schema;
}
/**
* Implements hook_install().
*
* Creates default fields and assigns them appropriately.
*/
function fileshare_install() {
$fields = array();
$fields['fileshare_body'] = array(
'field_name' => 'fileshare_body',
'type' => 'text',
'entity_types' => array('fileshare'),
'translatable' => TRUE,
);
$fields['fileshare_attachment'] = array(
'field_name' => 'fileshare_attachment',
'type' => 'file',
'entity_types' => array('fileshare'),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
);
// Create each field
foreach ($fields as $field) {
field_create_field($field);
}
$instances = array();
$instances['fileshare_body'] = array(
'entity_type' => 'fileshare',
'field_name' => 'fileshare_body',
'bundle' => 'secure_message',
'label' => 'Body',
'widget' => array(
'type' => 'text_textarea',
'weight' => 5,
),
'settings' => array(),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_hidden',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_hidden',
),
),
);
$instances['fileshare_attachment'] = array(
'entity_type' => 'fileshare',
'field_name' => 'fileshare_attachment',
'bundle' => 'secure_message',
'label' => 'Attachments',
'widget' => array(
'type' => 'file_generic',
'weight' => 10,
),
'settings' => array(),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'file_default',
),
'teaser' => array(
'label' => 'above',
'type' => 'file_default',
),
),
);
// Create individual field instances
foreach ($instances as $instance) {
field_create_instance($instance);
}
}