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
|
'glue' => [
|
35
|
'type' => 'varchar',
|
36
|
'length' => 10,
|
37
|
'not null' => TRUE,
|
38
|
'description' => 'The string to concatenate name parts in the URL query string',
|
39
|
],
|
40
|
'category' => [
|
41
|
'type' => 'varchar',
|
42
|
'length' => 255,
|
43
|
'not null' => TRUE,
|
44
|
'description' => 'The link category',
|
45
|
],
|
46
|
'weight' => [
|
47
|
'type' => 'int',
|
48
|
'not null' => TRUE,
|
49
|
'default' => 0,
|
50
|
'description' => 'Weight of filter within format.',
|
51
|
],
|
52
|
'status' => [
|
53
|
'type' => 'int',
|
54
|
'not null' => TRUE,
|
55
|
'default' => 0,
|
56
|
'description' => 'External link enabled status. (1 = enabled, 0 = disabled)',
|
57
|
],
|
58
|
],
|
59
|
'primary key' => ['id'],
|
60
|
'indexes' => [
|
61
|
'list' => ['weight', 'id'],
|
62
|
],
|
63
|
];
|
64
|
|
65
|
return $schema;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* implements hook_install()
|
70
|
*/
|
71
|
function ext_links_install() {
|
72
|
$links_templates = migrate_old_ext_links();
|
73
|
foreach ($links_templates as $ext_link){
|
74
|
db_delete('variable')
|
75
|
->condition('name', "ext_links_" . $ext_link->id . '_%', 'LIKE')
|
76
|
->execute();
|
77
|
}
|
78
|
variable_set('ext_links_appearance_grouped', variable_get('ext_links_options', 0) != 1 ? 1 : 0 );
|
79
|
variable_del('ext_links_options');
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Implements hook_uninstall().
|
84
|
*/
|
85
|
function ext_links_uninstall() {
|
86
|
db_drop_table('ext_links');
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Update function to migrate previous versions
|
91
|
*/
|
92
|
function ext_links_update_7001(){
|
93
|
$connection_info = Database::parseConnectionInfo();
|
94
|
$db_prefix = $connection_info['default']['default']['prefix'];
|
95
|
foreach(ext_links_schema() as $table_name => $schema){
|
96
|
|
97
|
if(!db_table_exists($db_prefix . $table_name)){
|
98
|
db_create_table($db_prefix . $table_name, $schema);
|
99
|
}
|
100
|
}
|
101
|
ext_links_install();
|
102
|
return "ext_links table created and old settings migrated.";
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Update ext_link to cdm_tokens functionality
|
107
|
*/
|
108
|
function ext_links_update_7002(){
|
109
|
$tasks_performed = [];
|
110
|
$column_glue_exists = db_query("SHOW COLUMNS FROM {ext_links} LIKE 'glue';")->rowCount();
|
111
|
|
112
|
if($column_glue_exists){
|
113
|
db_query("ALTER TABLE {ext_links} DROP COLUMN glue;");
|
114
|
$tasks_performed[] = "ext_links table: Column glue removed.";
|
115
|
}
|
116
|
|
117
|
db_query("ALTER TABLE {ext_links} MODIFY COLUMN link varchar(2048) NOT NULL COMMENT 'The link url template';");
|
118
|
$tasks_performed[] = "ext_links.link modified to varchar 2048.";
|
119
|
ext_links_template_links_update();
|
120
|
$tasks_performed[] = "ext_link template links updated.";
|
121
|
|
122
|
return join("; \n", $tasks_performed);
|
123
|
}
|
124
|
|
125
|
|
126
|
/**
|
127
|
* Migrates old ext link templates from drupal vars to the ext_link table.
|
128
|
*/
|
129
|
function migrate_old_ext_links(){
|
130
|
$links_templates = ext_links_templates();
|
131
|
foreach ($links_templates as $ext_link){
|
132
|
$ext_link = _ext_links_merge_old_vars($ext_link);
|
133
|
ext_links_save($ext_link);
|
134
|
}
|
135
|
return $links_templates;
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Updates the ext_links.link column with new urls from the default templates.
|
140
|
*/
|
141
|
function ext_links_template_links_update(){
|
142
|
$template_default_arrays = ext_links_template_defaults();
|
143
|
foreach ($template_default_arrays as $template_array) {
|
144
|
$return = db_merge('ext_links')
|
145
|
->key(['id' => $template_array['id']])
|
146
|
->fields([
|
147
|
'link' => $template_array['link'],
|
148
|
])
|
149
|
->execute();
|
150
|
}
|
151
|
}
|
152
|
|
153
|
|
154
|
/**
|
155
|
* Merge the old settings stored in drupal vars into the ext_link template object
|
156
|
* @param $ext_link object
|
157
|
*
|
158
|
* @return object
|
159
|
* The ext link template
|
160
|
*/
|
161
|
function _ext_links_merge_old_vars($ext_link){
|
162
|
$ext_link_id = $ext_link->id;
|
163
|
$ext_link->status = variable_get("ext_links_${ext_link_id}_check", $ext_link->status);
|
164
|
$ext_link->link = variable_get("ext_links_${ext_link_id}_link", $ext_link->link);
|
165
|
$ext_link->glue = variable_get("ext_links_${ext_link_id}_concat", $ext_link->glue);
|
166
|
$ext_link->title = variable_get("ext_links_${ext_link_id}_text", $ext_link->title);
|
167
|
return $ext_link;
|
168
|
}
|