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
|
<?php
// $Id: og_notifications.install,v 1.9 2008/11/04 12:12:13 karthik Exp $
/**
* Implementation of hook_install().
*/
function og_notifications_install() {
drupal_install_schema('og_notifications');
if (variable_get('og_notifications_update_required', FALSE)) {
og_notifications_og_upgrade();
}
drupal_set_message(t('Organic groups notifications module installation script complete.'));
}
/**
* Definition of hook_schema().
*/
function og_notifications_schema() {
$schema = array();
$schema['og_notifications'] = array(
'description' => t('Stores autosubscription preferences for each user.'),
'fields' => array(
'uid' => array(
'description' => t("The user's {user}.uid."),
'type' => 'int',
'size' => 'normal',
'not null' => TRUE
),
'autosubscribe' => array(
'description' => t(''),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => -1
)
),
'primary key' => array('uid')
);
return $schema;
}
/**
* Implementation of hook_enable().
*/
function og_notifications_enable() {
_og_notifications_populate();
}
/**
* Notifications upgrade: Based on the upgrade flag, move existing subscriptions
* to the notifications module.
*/
function og_notifications_og_upgrade() {
$ret = array();
// Load notifications and dependencies.
drupal_load('module', 'og_notifications');
drupal_load('module', 'notifications');
drupal_load('module', 'token');
drupal_load('module', 'messaging');
// Save notification subscription for each group based on og_uid.mail_type.
$result = db_query("SELECT nid, uid FROM {og_uid} WHERE mail_type = 1");
while ($subscription = db_fetch_object($result)) {
// Resort to subterfuge to avoid repeat calls to user_load.
$account = (object) array('uid' => $subscription->uid);
og_notifications_user_subscribe($account, $subscription->nid);
}
// Drop field notification.
db_query("ALTER TABLE {og} DROP notification");
// Drop field mail_type.
db_query("ALTER TABLE {og_uid} DROP mail_type");
// og_email is now effectively only a boolean. Users with
// OG_NOTIFICATION_SELECTIVE are equivalent to those with autosubscribe turned
// off.
$autosubscribe = variable_get('og_notification', 1) == 1 ? 1 : 0;
variable_set('og_notifications_autosubscribe', $autosubscribe);
variable_del('og_notification');
db_query("INSERT INTO {og_notifications} (uid, autosubscribe) SELECT oug.uid, oug.og_email FROM {og_uid_global} oug");
db_query("UPDATE {og_notifications} SET autosubscribe = 0 WHERE autosubscribe = 2");
db_query('DROP TABLE {og_uid_global}');
variable_del('og_notifications_update_required');
return $ret;
}
/**
* Implementation of hook_uninstall().
*/
function og_notifications_uninstall() {
drupal_uninstall_schema('og_notifications');
variable_del('og_notifications_autosubscribe');
variable_del('og_notifications_content_types');
// @TODO: Clear any queued messages in notifications?
drupal_set_message(t('Organic groups notifications module uninstallation script complete.'));
}
/**
* Populate the og_notifications_table with any uids added prior to installation
* or when disabled.
*/
function _og_notifications_populate() {
$sql = 'SELECT u.uid FROM {users} u LEFT JOIN {og_notifications} ogn ON u.uid = ogn.uid WHERE u.uid > 0 AND ogn.uid IS NULL';
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
// autosubscribe is set to the column default.
db_query("INSERT INTO {og_notifications} (uid) VALUES (%d)", $row->uid);
}
}
|