1 |
2a3a2a4f
|
Andreas Kohlbecker
|
<?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' => 255,
|
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 |
0e38f1bf
|
Andreas Kohlbecker
|
'category' => [
|
41 |
|
|
'type' => 'varchar',
|
42 |
|
|
'length' => 255,
|
43 |
|
|
'not null' => TRUE,
|
44 |
|
|
'description' => 'The link category',
|
45 |
|
|
],
|
46 |
2a3a2a4f
|
Andreas Kohlbecker
|
'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 |
0e38f1bf
|
Andreas Kohlbecker
|
}
|
67 |
|
|
|
68 |
a14257fa
|
Andreas Kohlbecker
|
/**
|
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 |
019d69fa
|
Andreas Kohlbecker
|
variable_set('ext_links_appearance_grouped', variable_get('ext_links_options', 0) != 1 ? 1 : 0 );
|
79 |
|
|
variable_del('ext_links_options');
|
80 |
a14257fa
|
Andreas Kohlbecker
|
}
|
81 |
|
|
|
82 |
0e38f1bf
|
Andreas Kohlbecker
|
/**
|
83 |
|
|
* Implements hook_uninstall().
|
84 |
|
|
*/
|
85 |
|
|
function hook_uninstall() {
|
86 |
|
|
db_drop_table('ext_links');
|
87 |
c03b5f5d
|
Andreas Kohlbecker
|
}
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
a14257fa
|
Andreas Kohlbecker
|
* Migrates old ext link templates from drupal vars to the ext_link table.
|
91 |
c03b5f5d
|
Andreas Kohlbecker
|
*/
|
92 |
|
|
function migrate_old_ext_links(){
|
93 |
a14257fa
|
Andreas Kohlbecker
|
$links_templates = ext_links_templates();
|
94 |
|
|
foreach ($links_templates as $ext_link){
|
95 |
|
|
$ext_link = _ext_links_merge_old_vars($ext_link);
|
96 |
|
|
ext_links_save($ext_link);
|
97 |
|
|
}
|
98 |
|
|
return $links_templates;
|
99 |
c03b5f5d
|
Andreas Kohlbecker
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Merge the old settings stored in drupal vars into the ext_link template object
|
103 |
|
|
* @param $ext_link object
|
104 |
|
|
*
|
105 |
|
|
* @return object
|
106 |
|
|
* The ext link template
|
107 |
|
|
*/
|
108 |
|
|
function _ext_links_merge_old_vars($ext_link){
|
109 |
|
|
$ext_link_id = $ext_link->id;
|
110 |
fc1b00e2
|
Andreas Kohlbecker
|
$ext_link->status = variable_get("ext_links_${ext_link_id}_check", $ext_link->status);
|
111 |
a14257fa
|
Andreas Kohlbecker
|
$ext_link->link = variable_get("ext_links_${ext_link_id}_link", $ext_link->link);
|
112 |
|
|
$ext_link->glue = variable_get("ext_links_${ext_link_id}_concat", $ext_link->glue);
|
113 |
|
|
$ext_link->title = variable_get("ext_links_${ext_link_id}_text", $ext_link->title);
|
114 |
c03b5f5d
|
Andreas Kohlbecker
|
return $ext_link;
|
115 |
2a3a2a4f
|
Andreas Kohlbecker
|
}
|