function og_notifications_og_upgrade in Organic groups 5.3
Same name and namespace in other branches
- 5.8 og_notifications/og_notifications.install \og_notifications_og_upgrade()
- 6.2 modules/og_notifications/og_notifications.install \og_notifications_og_upgrade()
- 6 modules/og_notifications/og_notifications.install \og_notifications_og_upgrade()
Notifications upgrade: Based on the upgrade flag, move existing subscriptions to the notifications module.
1 call to og_notifications_og_upgrade()
- og_notifications_install in og_notifications/
og_notifications.install - Implementation of hook_install().
File
- og_notifications/
og_notifications.install, line 72
Code
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;
}