-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicropublisher.install
179 lines (171 loc) · 4.89 KB
/
micropublisher.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
<?php
/**
* @file
* Install/Update/Uninstall functions for field_example module
*/
/**
* Implements hook_field_schema().
*
* This defines the actual database schema of the field, using the format
* used by the Schema API.
*
* The actual data we store here is just one 7-character element, even
* though the widget presents the three portions separately.
*
* @see hook_field_schema()
* @link schemaapi Schema API @endlink
*/
function micropublisher_field_schema($field) {
return array(
'columns' => array(
'sid' => array(
'description' => 'The {micropublisher_managed}.sid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'title' => array(
'description' => 'Title of the shared link.',
'type' => 'varchar',
'length' => 150,
'not null' => FALSE,
'default' => '',
),
'description' => array(
'description' => 'Description of the shared link.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE
),
'image' => array(
'description' => 'Image url of the shared link.',
'type' => 'varchar',
'length' => 150,
'not null' => FALSE,
'default' => '',
),
'provider' => array(
'description' => 'The service provider if there are any for this url.',
'type' => 'varchar',
'length' => 150,
'not null' => TRUE,
'default' => '',
),
'type' => array(
'description' => 'Type of the url content.',
'type' => 'varchar',
'length' => 150,
'not null' => TRUE,
'default' => '',
),
'html' => array(
'description' => 'HTML code for field to save embeded code.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE
),
),
'indexes' => array(
'sid' => array('sid'),
),
'foreign keys' => array(
'sid' => array(
'table' => 'micropublisher_managed',
'columns' => array('sid' => 'sid'),
),
),
);
}
/**
* Implements hook_field_schema().
*/
function micropublisher_schema() {
$schema['micropublisher_managed'] = array(
'description' => 'Stores information for fetched urls.',
'fields' => array(
'sid' => array(
'description' => 'Url source ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The {users}.uid of the user who is associated with the file.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uri' => array(
'description' => 'The URI to access the url (either local or remote).',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'timestamp' => array(
'description' => 'UNIX timestamp for when the file was added.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'uid' => array('uid'),
'status' => array('status'),
'timestamp' => array('timestamp'),
),
'primary key' => array('sid'),
'foreign keys' => array(
'file_owner' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
return $schema;
}
/**
* Drop unique index URI
*/
function micropublisher_update_7000(){
db_query("ALTER TABLE {micropublisher_managed} DROP INDEX uri");
}
/**
* Allow Null title & image columns
*/
function micropublisher_update_7001(){
//Must loop through all field instance tables here...
$fields = field_info_fields();
$tables = array();
foreach ($fields as $field_name => $field){
if ($field['type'] == 'micropublisher'){
$tables += $field['storage']['details']['sql'][FIELD_LOAD_CURRENT];
$tables += $field['storage']['details']['sql'][FIELD_LOAD_REVISION];
}
}
foreach ($tables as $table_name => $table){
db_change_field($table_name, $table['title'], $table['title'], array(
'description' => 'Title of the shared link.',
'type' => 'varchar',
'length' => 150,
'not null' => FALSE,
'default' => '',
));
db_change_field($table_name, $table['image'], $table['image'], array(
'description' => 'Image url of the shared link.',
'type' => 'varchar',
'length' => 150,
'not null' => FALSE,
'default' => '',
));
}
}