-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshurly_integration.install
145 lines (127 loc) · 4.04 KB
/
shurly_integration.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 // $Id: shurly_integration.install $
/**
* @file
* shurly_integration install.
**/
/**
* Implementation of hook_schema().
*/
function shurly_integration_schema() {
$schema['oxfam_shurl_user'] = array(
'fields' => array(
'uid' => array(
'description' => t("The Drupal ID of the user account associated with the Twitter account."),
'type' => 'int',
'not null' => TRUE,
),
'api_key' => array(
'description' => t("The API key for the Oxf.am account."),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('uid', 'api_key'),
'indexes' => array('api_key' => array('api_key'), 'uid' => array('uid')),
);
$schema['oxfam_shurl'] = array(
'fields' => array(
'nid' => array(
'description' => t('Node ID'),
'type' => 'int',
'not null' => TRUE,
),
'short_url' => array(
'description' => t('Oxf.am short URL'),
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'long_url' => array(
'description' => t('Original long URL'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('nid'),
'indexes' => array('nid_short_url' => array('nid', 'short_url'), 'short_url' => array('short_url'), 'long_url' => array('long_url')),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function shurly_integration_install() {
// Create tables.
drupal_install_schema('shurly_integration');
// Shurly Integration must have heavier weight than pathauto so a node alias can be used in the oxf.am service call in hook_nodeapi().
if (module_exists('pathauto')){
// Get system weight of pathauto module.
$weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'pathauto'"));
// Make weight of shurly_integration module 1 heavier.
$result = db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight + 1, 'shurly_integration');
}
}
/**
* Implementation of hook_uninstall().
*/
function shurly_integration_uninstall() {
// Delete tables.
drupal_uninstall_schema('shurly_integration');
}
/**
* Shurly Integration must have heavier weight than pathauto so a node alias can be used in the oxf.am service call in hook_nodeapi().
*/
function shurly_integration_update_6001() {
$ret = array();
if (module_exists('pathauto')){
// Get system weight of pathauto module.
$weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'pathauto'"));
// Make weight of shurly_integration module 1 heavier.
$sql = "UPDATE {system} SET weight = %d WHERE name = '%s'";
$result = db_query($sql, $weight + 1, 'shurly_integration');
$ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql .' ('. $weight + 1 .', shurly_integration)'));
}
return $ret;
}
/**
* Add the {oxfam_shurl} table.
*/
function shurly_integration_update_6002() {
$module = 'shurly_integration';
$schema = drupal_get_schema_unprocessed($module);
_drupal_initialize_schema($module, $schema);
$ret = array();
db_create_table($ret, 'oxfam_shurl', $schema['oxfam_shurl']);
return $ret;
}
/**
* Add the {oxfam_shurl}.long_url field.
*/
function shurly_integration_update_6003() {
$ret = array();
// Add the 'referer' column.
db_add_field($ret, 'oxfam_shurl', 'long_url', array(
'description' => t('Original long URL'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
return $ret;
}
/**
* Change unique keys to indexes in {oxfam_shurl}.
*/
function shurly_integration_update_6004() {
$ret = array();
db_drop_unique_key($ret, 'oxfam_shurl', 'short_url');
db_drop_unique_key($ret, 'oxfam_shurl', 'long_url');
db_add_index($ret, 'oxfam_shurl', 'short_url', array('short_url'));
db_add_index($ret, 'oxfam_shurl', 'long_url', array('long_url'));
return $ret;
}