1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Install, update, and uninstall functions for the ext_links module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_schema().
|
10
|
*/
|
11
|
function ext_links_schema() {
|
12
|
$schema['ext_links'] = [
|
13
|
'description' => 'Table external link templates.',
|
14
|
'fields' => [
|
15
|
'id' => [
|
16
|
'type' => 'varchar',
|
17
|
'length' => 32,
|
18
|
'not null' => TRUE,
|
19
|
'default' => '',
|
20
|
'description' => 'Name of the ext_link being referenced.',
|
21
|
],
|
22
|
'title' => [
|
23
|
'type' => 'varchar',
|
24
|
'length' => 255,
|
25
|
'not null' => TRUE,
|
26
|
'description' => 'The link title',
|
27
|
],
|
28
|
'link' => [
|
29
|
'type' => 'varchar',
|
30
|
'length' => 2048,
|
31
|
'not null' => TRUE,
|
32
|
'description' => 'The link url template',
|
33
|
],
|
34
|
'category' => [
|
35
|
'type' => 'varchar',
|
36
|
'length' => 255,
|
37
|
'description' => 'The link category',
|
38
|
],
|
39
|
'weight' => [
|
40
|
'type' => 'int',
|
41
|
'not null' => TRUE,
|
42
|
'default' => 0,
|
43
|
'description' => 'Weight of filter within format.',
|
44
|
],
|
45
|
'status' => [
|
46
|
'type' => 'int',
|
47
|
'not null' => TRUE,
|
48
|
'default' => 0,
|
49
|
'description' => 'External link enabled status. (1 = enabled, 0 = disabled)',
|
50
|
],
|
51
|
],
|
52
|
'primary key' => ['id'],
|
53
|
'indexes' => [
|
54
|
'list' => ['weight', 'id'],
|
55
|
],
|
56
|
];
|
57
|
|
58
|
return $schema;
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* implements hook_install()
|
63
|
*/
|
64
|
function ext_links_install() {
|
65
|
$links_templates = migrate_old_ext_links();
|
66
|
foreach ($links_templates as $ext_link){
|
67
|
db_delete('variable')
|
68
|
->condition('name', "ext_links_" . $ext_link->id . '_%', 'LIKE')
|
69
|
->execute();
|
70
|
}
|
71
|
variable_set('ext_links_appearance_grouped', variable_get('ext_links_options', 0) != 1 ? 1 : 0 );
|
72
|
variable_del('ext_links_options');
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Implements hook_uninstall().
|
77
|
*/
|
78
|
function ext_links_uninstall() {
|
79
|
db_drop_table('ext_links');
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Update function to migrate previous versions
|
84
|
*/
|
85
|
function ext_links_update_7001(){
|
86
|
$connection_info = Database::parseConnectionInfo();
|
87
|
$db_prefix = $connection_info['default']['default']['prefix'];
|
88
|
foreach(ext_links_schema() as $table_name => $schema){
|
89
|
|
90
|
if(!db_table_exists($db_prefix . $table_name)){
|
91
|
db_create_table($db_prefix . $table_name, $schema);
|
92
|
}
|
93
|
}
|
94
|
ext_links_install();
|
95
|
return "ext_links table created and old settings migrated.";
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Update ext_link to cdm_tokens functionality
|
100
|
*/
|
101
|
function ext_links_update_7002(){
|
102
|
|
103
|
$tasks_performed = [];
|
104
|
module_enable(['cdm_tokens'], TRUE);
|
105
|
$tasks_performed[] = "cdm_tokens module enabled.";
|
106
|
$column_glue_exists = db_query("SHOW COLUMNS FROM {ext_links} LIKE 'glue';")->rowCount();
|
107
|
|
108
|
if($column_glue_exists){
|
109
|
db_query("ALTER TABLE {ext_links} DROP COLUMN glue;");
|
110
|
$tasks_performed[] = "ext_links table: Column glue removed.";
|
111
|
}
|
112
|
|
113
|
db_query("ALTER TABLE {ext_links} MODIFY COLUMN link varchar(2048) NOT NULL COMMENT 'The link url template';");
|
114
|
$tasks_performed[] = "ext_links.link modified to varchar 2048.";
|
115
|
ext_links_template_links_update();
|
116
|
$tasks_performed[] = "ext_link template links updated.";
|
117
|
|
118
|
$block_info = ext_links_block_info();
|
119
|
db_update("block")
|
120
|
->fields([
|
121
|
'pages' => $block_info['0']['pages'],
|
122
|
'visibility' => 1
|
123
|
])
|
124
|
->condition('module', 'ext_links')
|
125
|
->execute();
|
126
|
$tasks_performed[] = "ext_links block configuration updated.";
|
127
|
return join("; \n", $tasks_performed);
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* - remove link to ePIC
|
132
|
* - set improved ulr for the wfo link
|
133
|
*/
|
134
|
function ext_links_update_7003() {
|
135
|
|
136
|
$tasks_performed = [];
|
137
|
$links_templates = ext_links_templates();
|
138
|
if(array_key_exists('epic', $links_templates)) {
|
139
|
db_delete('ext_links')->condition('id', 'epic')->execute();
|
140
|
$tasks_performed[] = "ext_link for ePIC removed";
|
141
|
}
|
142
|
if(array_key_exists('wfo', $links_templates)) {
|
143
|
$defaults = ext_links_template_defaults();
|
144
|
db_update('ext_links')->fields(array(
|
145
|
'link' => $defaults['wfo']['link']
|
146
|
))->condition('id', 'wfo')
|
147
|
->execute();
|
148
|
$tasks_performed[] = "set improved URL for the wfo external link";
|
149
|
}
|
150
|
return join("; \n", $tasks_performed);
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Migrates old ext link templates from drupal vars to the ext_link table.
|
155
|
*/
|
156
|
function migrate_old_ext_links(){
|
157
|
$links_templates = ext_links_templates();
|
158
|
foreach ($links_templates as $ext_link){
|
159
|
$ext_link = _ext_links_merge_old_vars($ext_link);
|
160
|
ext_links_save($ext_link);
|
161
|
}
|
162
|
return $links_templates;
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
* Updates the ext_links.link column with new urls from the default templates.
|
167
|
*/
|
168
|
function ext_links_template_links_update(){
|
169
|
$template_default_arrays = ext_links_template_defaults();
|
170
|
foreach ($template_default_arrays as $template_array) {
|
171
|
$return = db_merge('ext_links')
|
172
|
->key(['id' => $template_array['id']])
|
173
|
->fields([
|
174
|
'link' => $template_array['link'],
|
175
|
'title' => $template_array['title'],
|
176
|
])
|
177
|
->execute();
|
178
|
}
|
179
|
}
|
180
|
|
181
|
|
182
|
/**
|
183
|
* Merge the old settings stored in drupal vars into the ext_link template object
|
184
|
* @param $ext_link object
|
185
|
*
|
186
|
* @return object
|
187
|
* The ext link template
|
188
|
*/
|
189
|
function _ext_links_merge_old_vars($ext_link){
|
190
|
$ext_link_id = $ext_link->id;
|
191
|
$ext_link->status = variable_get("ext_links_${ext_link_id}_check", $ext_link->status);
|
192
|
$ext_link->link = variable_get("ext_links_${ext_link_id}_link", $ext_link->link);
|
193
|
$ext_link->title = variable_get("ext_links_${ext_link_id}_text", $ext_link->title);
|
194
|
return $ext_link;
|
195
|
}
|