Changed the default sort configuration for views
[project/activity.git] / activity.install
1 <?php
2
3 function activity_install() {
4 drupal_install_schema('activity');
5 // Set Trigger's weight to 2 so that it will fire AFTER pathauto. This makes
6 // pathauto alias' work.
7 if (activity_bad_trigger_weight()) {
8 drupal_set_message(t('In order for proper Pathauto behavior with Activity module, the Trigger module\'s weight needs to be fixed up. !clickhere', array('!clickhere' => l(t('Click here to fix Trigger\'s weight'), 'admin/activity/weight', array('query' => drupal_get_destination())))), 'error');
9 }
10 }
11
12 function activity_schema() {
13 $schema['activity'] = array(
14 'description' => 'Provides a place to record activity messages for display.',
15 'fields' => array(
16 'aid' => array(
17 'description' => 'The primary identifier for any activity',
18 'type' => 'serial',
19 'not null' => TRUE,
20 'unsigned' => TRUE,
21 ),
22 'uid' => array(
23 'description' => 'The user id of whomever performed the activity being recorded.',
24 'type' => 'int',
25 'not null' => TRUE,
26 'unsigned' => TRUE,
27 ),
28 'op' => array(
29 'description' => 'The operation being performed (update, insert, etc.)',
30 'type' => 'varchar',
31 'length' => '50',
32 'not null' => TRUE,
33 ),
34 'type' => array(
35 'description' => 'The type of object being acted upon (node, user, etc.)',
36 'type' => 'varchar',
37 'length' => '50',
38 'not null' => TRUE,
39 ),
40 'nid' => array(
41 'description' => 'A foreign key used with node_access table. Can be NULL for all non-node, comment activities',
42 'type' => 'int',
43 'unsigned' => TRUE,
44 ),
45 'eid' => array(
46 'description' => 'Entity ID used to maintain the relationship between activity and the entity that created the activity',
47 'type' => 'int',
48 'default value' => NULL,
49 'unsigned' => TRUE,
50 ),
51 'created' => array(
52 'description' => 'When the activity was recorded',
53 'type' => 'int',
54 'not null' => TRUE,
55 'unsigned' => TRUE,
56 ),
57 'actions_id' => array(
58 'description' => 'Foreign key to the actions table.',
59 'type' => 'varchar',
60 'length' => 255,
61 'not null' => TRUE,
62 'default' => '0',
63 ),
64 'status' => array(
65 'description' => 'Whether or not this Activity is published',
66 'type' => 'int',
67 'size' => 'tiny',
68 'default' => 1,
69 ),
70 ),
71 'primary key' => array('aid'),
72 'indexes' => array(
73 'nid' => array('nid'),
74 'eid' => array('eid'),
75 'created' => array('created'), // Probably not at all useful.
76 'actions_id' => array('actions_id'),
77 ),
78 );
79
80 $schema['activity_targets'] = array(
81 'fields' => array(
82 'aid' => array(
83 'description' => 'Foreign key to the activity table',
84 'type' => 'int',
85 'not null' => TRUE,
86 'unsigned' => TRUE,
87 ),
88 'uid' => array(
89 'description' => "The uid for which this message is for",
90 'type' => 'int',
91 'not null' => TRUE,
92 'unsigned' => TRUE,
93 'default' => 0,
94 ),
95 'amid' => array(
96 'description' => "The message id for this uid/aid combination",
97 'type' => 'int',
98 'not null' => TRUE,
99 'unsigned' => TRUE,
100 'default' => 0,
101 ),
102 'language' => array(
103 'description' => "The IS0-3166 name of the langauge for the associated message.",
104 'type' => 'varchar',
105 'not null' => TRUE,
106 'length' => '12',
107 ),
108 ),
109 'primary key' => array('aid', 'uid', 'language'),
110 'unique keys' => array(
111 'amid' => array('amid'),
112 ),
113 );
114
115 $schema['activity_messages'] = array(
116 'fields' => array(
117 'amid' => array(
118 'type' => 'serial',
119 'unsigned' => TRUE,
120 'not null' => TRUE,
121 'description' => 'The Unique id of the message',
122 ),
123 'message' => array(
124 'descripiton' => 'The full plaintext message',
125 'type' => 'text',
126 'size' => 'big',
127 'not null' => TRUE,
128 ),
129 ),
130 'primary key' => array('amid'),
131 );
132
133 $schema['activity_access'] = array(
134 'description' => 'Provides access control on a very granular level to activity items',
135 'fields' => array(
136 'aid' => array(
137 'description' => 'The primary identifier for an activity',
138 'type' => 'int',
139 'not null' => TRUE,
140 'unsigned' => TRUE,
141 ),
142 'realm' => array(
143 'description' => 'The module providing the access control',
144 'type' => 'varchar',
145 'length' => 255,
146 'not null' => TRUE,
147 ),
148 'value' => array(
149 'description' => 'The provided value from the implementing module. E.g a uid, nid or a tid',
150 'type' => 'int',
151 'not null' => TRUE,
152 'default' => 0,
153 'unsigned' => TRUE,
154 ),
155 ),
156 // UGG!!!
157 'primary key' => array('aid', 'realm', 'value'),
158 );
159 return $schema;
160 }
161
162 function activity_uninstall() {
163 drupal_uninstall_schema('activity');
164
165 // clean up actions and triggers
166 db_query("DELETE FROM {trigger_assignments} WHERE aid IN (SELECT aid FROM {actions} WHERE callback = 'activity_record')");
167 db_query("DELETE FROM {actions} WHERE callback = 'activity_record'");
168
169 // clean variable table
170 db_query("DELETE FROM {variable} WHERE name = 'activity_expire' OR name = 'activity_count_expire' OR name = 'activity_access_realms'");
171 }
172
173 /**
174 * Implementation of hook_requirements().
175 */
176 function activity_requirements($phase) {
177 $requirements = array();
178 $t = get_t();
179 $views_schema_version = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'views'"));
180 if (intval($views_schema_version) < 6006) {
181 $requirements['activity_views'] = array(
182 'title' => $t('Activity Views'),
183 'description' => $t('Activity2 requires Views >= 6.2. It can be downloaded !release. The change that is required by Activity2 is !issue', array('!release' => l('here', 'http://drupal.org/node/488082'), '!issue' => l('#419270', 'http://drupal.org/node/419270'))),
184 // set the severity to warning on install because we don't want to stop the install...
185 'severity' => ($phase == 'install') ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
186 );
187 }
188
189 if (activity_bad_trigger_weight()) {
190 $requirements['activity_trigger_weight'] = array(
191 'title' => $t('Activity Trigger Weight'),
192 'description' => $t('Activity2 requires Trigger\'s weight be greater then Pathauto\'s in order to produce proper aliased paths. !clickhere to fix that', array('!clickhere' => l(t('Click here'), 'admin/activity/weight', array('query' => drupal_get_destination())))),
193 'severity' => REQUIREMENT_WARNING,
194 );
195 }
196 return $requirements;
197 }
198
199 /**
200 * Sets Trigger modules weight to be higher then pathauto.
201 */
202 function activity_fix_trigger_weight() {
203 db_query("UPDATE {system} SET weight = 2 WHERE name = 'trigger'");
204 drupal_goto();
205 }
206
207 /**
208 * Check to see if we need to fix the Trigger weight.
209 */
210 function activity_bad_trigger_weight() {
211 // Verify Triggers weight.
212 $pathauto_weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'pathauto'"));
213 if ($pathauto_weight !== FALSE) {
214 $trigger_weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'trigger'"));
215 return $trigger_weight <= $pathauto_weight;
216 }
217 return FALSE;
218 }
219
220 /**
221 * Update the Activity Messages.amid field to be not null.
222 * @see: http://drupal.org/node/778662
223 */
224 function activity_update_6201() {
225 $ret = array();
226 db_change_field($ret, 'activity_messages', 'amid', 'amid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE));
227 return $ret;
228 }
229
230 /**
231 * Update {activity} table to have the actions_id field.
232 * @see: http://drupal.org/node/463854
233 */
234 function activity_update_6202() {
235 $ret = array();
236
237 db_add_field($ret, 'activity', 'actions_id', array(
238 'description' => 'Foreign key to the actions table.',
239 'type' => 'varchar',
240 'length' => 255,
241 'not null' => TRUE,
242 'default' => '0',
243 ),
244 array('indexes' => array('actions_id' => array('actions_id'))));
245
246 return $ret;
247 }
248
249 /**
250 * Update {activity} table to have a status field
251 * @see: http://drupal.org/node/582230
252 */
253 function activity_update_6203() {
254 $ret = array();
255
256 db_add_field ($ret, 'activity', 'status', array(
257 'description' => 'Whether or not this Activity is published',
258 'type' => 'int',
259 'size' => 'tiny',
260 'default' => 1,
261 )
262 );
263
264 return $ret;
265 }