forked from cschwirz/d2daddon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d2daddon.install
179 lines (176 loc) · 5.32 KB
/
d2daddon.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* @file
* Installation file for D2D Add-On.
*/
require_once 'includes/d2daddon.constants.inc';
require_once 'includes/d2daddon.create_statistics.inc';
/**
* Implements hook_install()
*/
function d2daddon_install() {
variable_set('d2daddon_remote_control_code', 'return strval(2 * 21);');
variable_set('d2daddon_remote_control_last_id', null);
d2daddon_statistics_create_users();
d2daddon_statistics_add_papers();
d2daddon_statistics_add_news();
$schema_name = 'd2daddon_statistics_query_whitelist';
/*
SELECT COUNT(*) as count FROM {d2daddon_statistics_papers}
SELECT author, title, rating, votes, created FROM {d2daddon_statistics_news} ORDER BY created DESC
SELECT COUNT(id) as count, AVG(posts) as posts, AVG(votes) as votes FROM {d2daddon_statistics_user}
SELECT author, title, rating, votes, created FROM {d2daddon_statistics_news} ORDER BY created DESC LIMIT 1
SELECT author, title, rating, votes, created FROM {d2daddon_statistics_news} ORDER BY rating DESC LIMIT 1
SELECT author, title, rating, votes FROM {d2daddon_statistics_papers} ORDER BY rating DESC LIMIT 1
*/
$whitelist = array(
'/^SELECT COUNT\(\*\) as count FROM \{d2daddon_statistics_papers\}$/',
'/^SELECT author, title, rating, votes, created FROM \{d2daddon_statistics_news\} ORDER BY created DESC$/',
'/^SELECT COUNT\(id\) as count, AVG\(posts\) as posts, AVG\(votes\) as votes FROM \{d2daddon_statistics_user\}$/',
'/^SELECT author, title, rating, votes FROM \{d2daddon_statistics_papers\} ORDER BY rating DESC LIMIT 1$/',
'/^SELECT author, title, rating, votes, created FROM \{d2daddon_statistics_news\} ORDER BY (rating|created) DESC LIMIT 1$/',
);
foreach ($whitelist as $allowed) {
$id = db_insert($schema_name)
->fields(array(
'query' => $allowed,
'description' => 'N/A'
))
->execute();
}
}
/**
* Implements hook_uninstall()
*/
function d2daddon_uninstall() {
variable_del('d2daddon_remote_control_code');
variable_del('d2daddon_remote_control_last_id');
variable_del('d2daddon_publish_groups');
variable_del('d2daddon_auto_publish');
variable_del('d2daddon_statistics_author');
variable_del('d2daddon_statistics_news_set');
variable_del('d2daddon_statistics_community');
variable_del('d2daddon_statistics_user_count');
variable_del('d2daddon_statistics_show_own_instance');
}
/**
* Implements hook_schema()
*/
function d2daddon_schema() {
$schema = array();
$schema['d2daddon_statistics_query_whitelist'] = array(
'description' => 'Stores allowed queries.',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => 'true',
'not null' => TRUE,
'description' => 'primary identifier',
),
'query' => array(
'type' => 'varchar',
'length' => 1024,
'not null' => TRUE,
'description' => 'query that may be called via a RPC',
),
'description' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
);
$schema['d2daddon_statistics_papers'] = array(
'description' => 'Stores papers and their ratings.',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => 'true',
'not null' => TRUE,
'description' => 'primary identifier',
),
'author' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
),
'rating' => array(
'type' => 'float',
'not null' => TRUE,
),
'votes' => array(
'type' => 'int',
'not null' => TRUE,
),
),
'primary key' => array('id'),
);
$schema['d2daddon_statistics_news'] = array(
'description' => 'Stores news and their ratings.',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => 'true',
'not null' => TRUE,
'description' => 'primary identifier',
),
'author' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
),
'rating' => array(
'type' => 'float',
'not null' => TRUE,
),
'votes' => array(
'type' => 'int',
'not null' => TRUE,
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
);
$schema['d2daddon_statistics_user'] = array(
'description' => 'Stores users.',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => 'true',
'not null' => TRUE,
'description' => 'primary identifier',
),
'name' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
),
'posts' => array(
'type' => 'int',
'not null' => TRUE,
),
'votes' => array(
'type' => 'int',
'not null' => TRUE,
),
),
'primary key' => array('id'),
);
return $schema;
}