function subscriptions_update_7 in Subscriptions 6
Same name and namespace in other branches
- 5.2 subscriptions.install \subscriptions_update_7()
Database update function 7 for 5.x-2.0 rewrite.
File
- ./
subscriptions.install, line 341 - Subscriptions module installation.
Code
function subscriptions_update_7() {
// Multi-part update to move subscriptions_auto and subscriptions_sendself from {users} to {subscriptions_user}
if (!isset($_SESSION['subscriptions_update_7'])) {
$_SESSION['subscriptions_update_7'] = 0;
$_SESSION['subscriptions_update_7_max'] = db_result(db_query('SELECT MAX(uid) FROM {users}'));
}
include_once './' . drupal_get_path('module', 'user') . '/user.module';
$limit = 50;
$result = db_query_range("SELECT uid FROM {users} WHERE uid > %d ORDER BY uid ASC", $_SESSION['subscriptions_update_7'], 0, $limit);
while ($usr = db_fetch_object($result)) {
$account = user_load(array(
'uid' => $usr->uid,
));
$settings = array();
if (isset($account->subscriptions_auto)) {
$settings['autosub_on_post = %d'] = $account->subscriptions_auto;
$settings['autosub_on_update = %d'] = $account->subscriptions_auto;
$settings['autosub_on_comment = %d'] = $account->subscriptions_auto;
}
if (isset($account->subscriptions_sendself)) {
$settings['send_self = %d'] = $account->subscriptions_sendself;
}
if (!empty($settings)) {
$sql = "UPDATE {subscriptions_user} SET " . implode(', ', array_keys($settings)) . " WHERE uid = %d";
$settings[] = $account->uid;
db_query($sql, array_values($settings));
user_save($account, array(
'subscriptions_auto' => NULL,
'subscriptions_sendself' => NULL,
));
}
$_SESSION['subscriptions_update_7'] = $usr->uid;
}
if ($_SESSION['subscriptions_update_7'] == $_SESSION['subscriptions_update_7_max']) {
variable_del('subscriptions_sendself');
variable_del('subscriptions_autoset');
unset($_SESSION['subscriptions_update_7']);
unset($_SESSION['subscriptions_update_7_max']);
return array();
}
return array(
'#finished' => $_SESSION['subscriptions_update_7'] / $_SESSION['subscriptions_update_7_max'],
);
}