1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Installation file for VotingAPI module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
function votingapi_schema() {
|
9 |
|
|
$schema['votingapi_vote'] = array(
|
10 |
|
|
'fields' => array(
|
11 |
|
|
'vote_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
12 |
|
|
'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
|
13 |
|
|
'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
14 |
|
|
'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
|
15 |
|
|
'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
|
16 |
|
|
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
|
17 |
|
|
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
18 |
|
|
'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
19 |
|
|
'vote_source' => array('type' => 'varchar', 'length' => 255),
|
20 |
|
|
),
|
21 |
|
|
'primary key' => array('vote_id'),
|
22 |
|
|
'indexes' => array(
|
23 |
|
|
'content_uid' => array('entity_type', 'entity_id', 'uid'),
|
24 |
|
|
'content_uid_2' => array('entity_type', 'uid'),
|
25 |
|
|
'content_source' => array('entity_type', 'entity_id', 'vote_source'),
|
26 |
|
|
'content_value_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
|
27 |
|
|
),
|
28 |
|
|
);
|
29 |
|
|
$schema['votingapi_cache'] = array(
|
30 |
|
|
'fields' => array(
|
31 |
|
|
'vote_cache_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
32 |
|
|
'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
|
33 |
|
|
'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
34 |
|
|
'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
|
35 |
|
|
'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
|
36 |
|
|
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
|
37 |
|
|
'function' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),
|
38 |
|
|
'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
39 |
|
|
),
|
40 |
|
|
'primary key' => array('vote_cache_id'),
|
41 |
|
|
'indexes' => array(
|
42 |
|
|
'content' => array('entity_type', 'entity_id'),
|
43 |
|
|
'content_function' => array('entity_type', 'entity_id', 'function'),
|
44 |
|
|
'content_tag_func' => array('entity_type', 'entity_id', 'tag', 'function'),
|
45 |
|
|
'content_vtype_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
|
46 |
|
|
'content_vtype_tag_func' => array('entity_type', 'entity_id', 'value_type', 'tag', 'function'),
|
47 |
|
|
),
|
48 |
|
|
);
|
49 |
|
|
return $schema;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
|
|
* The most recent update removed for version-to-version compatibility.
|
54 |
|
|
*/
|
55 |
|
|
function votingapi_update_last_removed() {
|
56 |
|
|
return 6101;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Fix default values for entity_type columns
|
61 |
|
|
*/
|
62 |
|
|
function votingapi_update_7203() {
|
63 |
|
|
db_change_field('votingapi_vote', 'entity_type', 'entity_type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'));
|
64 |
|
|
db_change_field('votingapi_cache', 'entity_type', 'entity_type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'));
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
/**
|
68 |
|
|
* Queue orphaned votes for deletion (nodes and comments)
|
69 |
|
|
*/
|
70 |
|
|
function votingapi_update_7202() {
|
71 |
|
|
$tables[] = 'votingapi_vote';
|
72 |
|
|
$tables[] = 'votingapi_cache';
|
73 |
|
|
|
74 |
|
|
$types[] = array('node', 'node', 'nid');
|
75 |
|
|
$types[] = array('comment', 'comment', 'cid');
|
76 |
|
|
|
77 |
|
|
$queue = DrupalQueue::get('VotingAPIOrphaned', TRUE);
|
78 |
|
|
|
79 |
|
|
foreach ($types as $w) {
|
80 |
|
|
list($type, $type_table, $type_key) = $w;
|
81 |
|
|
if (!db_table_exists($type_table)) {
|
82 |
|
|
continue;
|
83 |
|
|
}
|
84 |
|
|
foreach ($tables as $table) {
|
85 |
|
|
$sql = "SELECT v.entity_type, v.entity_id FROM {{$table}} v
|
86 |
|
|
LEFT OUTER JOIN {{$type_table}} e ON v.entity_id=e.$type_key
|
87 |
|
|
WHERE v.entity_type='$type' AND e.$type_key IS NULL
|
88 |
|
|
GROUP BY v.entity_type, v.entity_id";
|
89 |
|
|
$result = db_query($sql);
|
90 |
|
|
foreach ($result as $row) {
|
91 |
|
|
$queue->createItem((array) $row);
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Renaming the 'content_type' and 'content_id' columns to entity_type and entity_id.
|
99 |
|
|
* Reduces confusion about 'content types' versus 'node types'.
|
100 |
|
|
*/
|
101 |
|
|
function votingapi_update_7201() {
|
102 |
|
|
$index['votingapi_vote'] = array(
|
103 |
|
|
'content_uid' => array('entity_type', 'entity_id', 'uid'),
|
104 |
|
|
'content_uid_2' => array('entity_type', 'uid'),
|
105 |
|
|
'content_source' => array('entity_type', 'entity_id', 'vote_source'),
|
106 |
|
|
'content_value_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
|
107 |
|
|
);
|
108 |
|
|
$index['votingapi_cache'] = array(
|
109 |
|
|
'content' => array('entity_type', 'entity_id'),
|
110 |
|
|
'content_function' => array('entity_type', 'entity_id', 'function'),
|
111 |
|
|
'content_tag_func' => array('entity_type', 'entity_id', 'tag', 'function'),
|
112 |
|
|
'content_vtype_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
|
113 |
|
|
'content_vtype_tag_func' => array('entity_type', 'entity_id', 'value_type', 'tag', 'function'),
|
114 |
|
|
);
|
115 |
|
|
// Remove all existing indexes.
|
116 |
|
|
foreach ($index as $table => $data) {
|
117 |
|
|
foreach ($data as $index_name => $columns) {
|
118 |
|
|
if (db_index_exists($table, $index_name)) {
|
119 |
|
|
db_drop_index($table, $index_name);
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
// Change fields
|
125 |
|
|
foreach (array('votingapi_vote', 'votingapi_cache') as $table) {
|
126 |
|
|
db_change_field($table, 'content_type', 'entity_type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'));
|
127 |
|
|
db_change_field($table, 'content_id', 'entity_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
128 |
|
|
db_change_field($table, 'value_type', 'value_type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'));
|
129 |
|
|
db_change_field($table, 'tag', 'tag', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'));
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
// Recreate the indexes.
|
133 |
|
|
foreach ($index as $table => $data) {
|
134 |
|
|
foreach ($data as $index_name => $columns) {
|
135 |
|
|
db_add_index($table, $index_name, $columns);
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
return t('Updated VotingAPI table structure.');
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
/**
|
144 |
|
|
* Implements hook_uninstall().
|
145 |
|
|
*/
|
146 |
|
|
function votingapi_uninstall() {
|
147 |
|
|
// Delete variables created by voteapi module.
|
148 |
|
|
$variables = array(
|
149 |
|
|
'votingapi_last_cron',
|
150 |
|
|
'votingapi_anonymous_window',
|
151 |
|
|
'votingapi_user_window',
|
152 |
|
|
'votingapi_calculation_schedule',
|
153 |
|
|
);
|
154 |
|
|
foreach ($variables as $variable) {
|
155 |
|
|
variable_del($variable);
|
156 |
|
|
}
|
157 |
|
|
} |