| 1 |
<?php |
<?php |
| 2 |
// $Id: subscriptions_og.install,v 1.1.2.8 2008/03/16 06:08:46 delius Exp $ |
// $Id: subscriptions_og.install,v 1.1.2.9 2008/04/29 22:02:01 develCuy Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_install(). |
* Implementation of hook_install(). |
| 15 |
$subscriptions = db_table_exists('subscriptions'); |
$subscriptions = db_table_exists('subscriptions'); |
| 16 |
if ($og_uid_global && $og_uid && $subscriptions) { |
if ($og_uid_global && $og_uid && $subscriptions) { |
| 17 |
// It performs a look-up of notification settings by user |
// It performs a look-up of notification settings by user |
| 18 |
$notifications = db_query("SELECT * FROM {og_uid_global} WHERE og_email >= %d", 1); |
$notifications = db_query('SELECT * FROM {og_uid_global} WHERE og_email >= %d', 1); |
| 19 |
if (db_num_rows($notifications)) { |
if (db_num_rows($notifications)) { |
| 20 |
// Load available groups |
// Load available groups |
| 21 |
include_once "subscriptions_og.module"; |
include_once 'subscriptions_og.module'; |
| 22 |
|
subscriptions_og_init(); |
| 23 |
$groups_by_types = subscriptions_og_get_groups_by_types(); |
$groups_by_types = subscriptions_og_get_groups_by_types(); |
| 24 |
|
|
| 25 |
// Extract group IDs |
if (count($groups_by_types)) { |
| 26 |
$group_nids = array(); |
// Extract group IDs |
| 27 |
foreach ($groups_by_types as $group_type => $groups) { |
$group_nids = array(); |
| 28 |
$group_nids = array_merge($group_nids, array_keys($groups)); |
foreach ($groups_by_types as $group_type => $groups) { |
| 29 |
} |
$group_nids = array_merge($group_nids, array_keys($groups)); |
|
// Generate subscriptions |
|
|
$defaults = (object)array( |
|
|
'send_interval' => 1, |
|
|
'send_updates' => 0, |
|
|
'send_comments' => 1, |
|
|
); |
|
|
while ($account = db_fetch_object($notifications)) { |
|
|
if ($account->og_email == 1) { |
|
|
// Activate subscriptions in all groups |
|
|
foreach ($group_nids as $group_nid) { |
|
|
subscriptions_write_subscription( |
|
|
'node', 'group_nid', $group_nid, -1, $account->uid, |
|
|
$defaults->send_interval, $defaults->send_updates, |
|
|
$defaults->send_comments); |
|
|
} |
|
| 30 |
} |
} |
| 31 |
elseif ($account->og_email == 2) { |
// Generate subscriptions |
| 32 |
// Activate subscriptions according to table og_uid |
$defaults = (object)array( |
| 33 |
$settings = db_query("SELECT nid group_nid FROM {og_uid} WHERE uid = %d AND mail_type > 0", $account->uid); |
'send_interval' => 1, |
| 34 |
while ($subscription = db_fetch_object($settings)) { |
'send_updates' => 0, |
| 35 |
subscriptions_write_subscription( |
'send_comments' => 1, |
| 36 |
'node', 'group_nid', $subscription->group_nid, -1, $account->uid, |
); |
| 37 |
$defaults->send_interval, $defaults->send_updates, |
while ($account = db_fetch_object($notifications)) { |
| 38 |
$defaults->send_comments); |
if ($account->og_email == 1) { |
| 39 |
|
// Activate subscriptions in all groups |
| 40 |
|
foreach ($group_nids as $group_nid) { |
| 41 |
|
subscriptions_write_subscription( |
| 42 |
|
'node', 'group_nid', $group_nid, -1, $account->uid, |
| 43 |
|
$defaults->send_interval, $defaults->send_updates, |
| 44 |
|
$defaults->send_comments); |
| 45 |
|
} |
| 46 |
|
} |
| 47 |
|
elseif ($account->og_email == 2) { |
| 48 |
|
// Activate subscriptions according to table og_uid |
| 49 |
|
$settings = db_query('SELECT nid group_nid FROM {og_uid} WHERE uid = %d AND mail_type > 0', $account->uid); |
| 50 |
|
while ($subscription = db_fetch_object($settings)) { |
| 51 |
|
subscriptions_write_subscription( |
| 52 |
|
'node', 'group_nid', $subscription->group_nid, -1, $account->uid, |
| 53 |
|
$defaults->send_interval, $defaults->send_updates, |
| 54 |
|
$defaults->send_comments); |
| 55 |
|
} |
| 56 |
} |
} |
| 57 |
} |
} |
| 58 |
|
drupal_set_message($t('Organic Groups user\'s notification settings successfully migrated to Subscriptions.')); |
| 59 |
} |
} |
|
drupal_set_message($t("Organic Groups user's notification settings successfully migrated to Subscriptions.")); |
|
| 60 |
} |
} |
| 61 |
} |
} |
| 62 |
else { |
else { |
| 63 |
drupal_set_message($t("Current version of OG module is not supported for migration from group notifications to subscriptions. Please update OG module to avoid checking user account's settings manually."), 'warning'); |
drupal_set_message($t('Current version of OG module is not supported for migration from group notifications to subscriptions. Please update OG module to avoid checking user account\'s settings manually.'), 'warning'); |
| 64 |
} |
} |
| 65 |
} |
} |
| 66 |
|
|
| 71 |
*/ |
*/ |
| 72 |
function subscriptions_og_uninstall() { |
function subscriptions_og_uninstall() { |
| 73 |
if (db_table_exists('subscriptions')) { |
if (db_table_exists('subscriptions')) { |
| 74 |
db_query("DELETE FROM {subscriptions} WHERE field = 'group_nid'"); |
db_query('DELETE FROM {subscriptions} WHERE field = "group_nid"'); |
| 75 |
} |
} |
| 76 |
|
|
| 77 |
|
db_query("DELETE FROM {variable} WHERE name like 'node_media%'"); |
| 78 |
} |
} |