-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp_link.install
143 lines (132 loc) · 3.66 KB
/
app_link.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
<?php
/**
* @file
* Install implementation file.
*/
/**
* Implements hook_schema().
*/
function app_link_schema() {
$schema['applink'] = array(
'description' => 'Table that holds information about links to Mobile Apps',
'export' => array(
'key' => 'path',
'key name' => 'Site path',
'primary key' => 'lid',
// Exports will be defined as $applink.
'identifier' => 'applink',
// Function hook name.
'default hook' => 'default_applink',
'api' => array(
'owner' => 'app_link',
// Base name for api include files.
'api' => 'default_applink',
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'lid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
// Do not export database-only keys.
'no export' => TRUE,
),
'path' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'Unique name to refer to App.',
),
'platform_data' => array(
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'URLs and related metadata per platform.',
),
),
'primary key' => array('lid'),
'unique keys' => array(
'path' => array('path'),
),
);
return $schema;
}
/**
* Update platform signatures.
*/
function app_link_update_7101() {
$links = db_query("SELECT * FROM {applink}");
foreach ($links as $link) {
$changed = FALSE;
$platform_data = unserialize($link->platform_data);
foreach ($platform_data as $key => $data) {
if (strpos($key, 'app_link_platform_') !== 0) {
$platform_data['app_link_platform_' . $key] = $data;
unset($platform_data[$key]);
$changed = TRUE;
}
}
if ($changed) {
db_update('applink')
->fields(array('platform_data' => serialize($platform_data)))
->condition('lid', $link->lid)
->execute();
}
}
}
/**
* Update platform signatures.
*/
function app_link_update_7102() {
$links = db_query("SELECT * FROM {applink}");
foreach ($links as $link) {
$changed = FALSE;
$platform_data = unserialize($link->platform_data);
foreach ($platform_data as $key => $data) {
if (strpos($key, 'app_link_platform_ios') !== 0) {
$platform_data['app_link_platform_iphone'] = $data;
$platform_data['app_link_platform_ipad'] = $data;
unset($platform_data[$key]);
$changed = TRUE;
}
}
if ($changed) {
db_update('applink')
->fields(array('platform_data' => serialize($platform_data)))
->condition('lid', $link->lid)
->execute();
}
}
}
/**
* Move all the web_url data in the DB column to the corresponding platform.
*/
function app_link_update_7103() {
$links = db_query("SELECT * FROM {applink}");
foreach ($links as $link) {
$platform_data = unserialize($link->platform_data);
if (empty($link->web_url)) {
continue;
}
$web_url = app_link_parse_url($link->web_url);
$platform_data['app_link_platform_fallback'] = array(
'fallback_url' => $web_url,
'supports_qs' => TRUE,
'supports_path' => TRUE,
'path_whitelist' => '',
);
$link->platform_data = $platform_data;
drupal_write_record('applink', $link, 'lid');
}
}
/**
* Drop hardcoded fallback URL in favor of fallback platforms.
*/
function app_link_update_7104() {
db_drop_field('applink', 'web_url');
}