forked from vincent-gao/recline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecline.install
145 lines (137 loc) · 3.95 KB
/
recline.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
<?php
/**
* @file
* Installation file of the Recline module.
*/
/**
* Implements hook_requirement().
*/
function recline_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$library_path = _recline_library_path();
if (_recline_requirements_installed($library_path)) {
$requirements['recline'] = array(
'title' => t('Recline library'),
'value' => t('Installed'),
'severity' => REQUIREMENT_OK,
);
}
else{
$requirements['recline'] = array(
'title' => t('Recline library'),
'value' => t('Not Found'),
'severity' => REQUIREMENT_ERROR,
'description' => t('You need to download this zip file: !recline and extract the entire contents of the archive into the %path folder of your server.', array('!recline' => l(t('Recline.js'), 'https://github.com/acouch/recline/zipball/master'), '%path' => 'sites/all/libraries/recline')),
);
}
}
return $requirements;
}
/**
* Implements hook_field_schema().
*/
function recline_field_schema() {
$columns = array(
'fid' => array(
'description' => 'The {file_managed}.fid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'service_id' => array(
'description' => "Service ID for parsed file.",
'type' => 'varchar',
'length' => 1024,
'not null' => FALSE,
),
'delimiter' => array(
'description' => "Delimiter to use for the file preview.",
'type' => 'text',
'not null' => FALSE,
),
);
module_load_include('inc', 'recline', 'recline.field');
recline_add_field_columns($columns);
foreach (recline_view_options() as $view => $label) {
$columns[$view] = array(
'type' => 'int',
'not null' => FALSE,
);
}
$columns['embed'] = array(
'type' => 'int',
'not null' => FALSE,
);
$indexes = array(
'fid' => array('fid'),
);
$foreign_keys = array(
'fid' => array(
'table' => 'file_managed',
'columns' => array('fid' => 'fid'),
),
);
return array(
'columns' => $columns,
'indexes' => $indexes,
'foreign_keys' => $foreign_keys,
);
}
/**
* Checks wether Recline.js library exists or not.
*/
function _recline_requirements_installed($path) {
if (file_exists($path . '/dist/recline.js')) {
return TRUE;
}
return FALSE;
}
/**
* Add 'delimiter' to recline field storage.
*/
function recline_update_7001(&$sandbox) {
$ret = array();
$fields = field_info_fields();
foreach ($fields as $field_name => $field) {
if ($field['type'] == 'recline_field' && $field['storage']['type'] == 'field_sql_storage') {
if (!array_key_exists('delimiter', $field['columns'])) {
$schema = recline_field_schema($field);
foreach ($field['storage']['details']['sql'] as $type => $table_info) {
foreach ($table_info as $table_name => $columns) {
$column_name = _field_sql_storage_columnname($field_name, 'delimiter');
db_add_field($table_name, $column_name, $schema['columns']['delimiter']);
}
}
field_cache_clear();
}
}
}
return $ret;
}
/**
* Add 'embed' to recline field storage.
*/
function recline_update_7002(&$sandbox) {
$ret = array();
$fields = field_info_fields();
foreach ($fields as $field_name => $field) {
if ($field['type'] == 'recline_field' && $field['storage']['type'] == 'field_sql_storage') {
$schema = recline_field_schema($field);
foreach ($field['storage']['details']['sql'] as $type => $table_info) {
foreach ($table_info as $table_name => $columns) {
$column_name = _field_sql_storage_columnname($field_name, 'embed');
db_add_field($table_name, $column_name, $schema['columns']['embed']);
}
}
field_cache_clear();
}
}
return $ret;
}
/**
* Delete no longer required variable.
*/
function recline_update_7003(&$sandbox) {
variable_del('recline_ajax_call_timeout');
}