You are here

function pm_email_notify_update_7200 in Privatemsg 7.2

Convert the old table to privatemsg settings API.

File

pm_email_notify/pm_email_notify.install, line 59
This file contains installation and update hooks for pm_email_notify.

Code

function pm_email_notify_update_7200() {

  // If the table was already deleted, this is a upgrade from 6-x.2.x. Nothing to do, then.
  if (!db_table_exists('pm_email_notify')) {
    return;
  }

  // Update the site-wide default setting.
  if (variable_get('pm_email_notify_default', TRUE)) {
    variable_set('privatemsg_setting_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_ALL);
  }
  else {
    variable_set('privatemsg_setting_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_DISABLED);
  }
  variable_del('pm_email_notify_default');

  // Convert user saved settings.
  $result = db_query('SELECT * FROM {pm_email_notify}');
  foreach ($result as $row) {
    privatemsg_set_setting('user', $row->user_id, 'email_notify_level', $row->email_notify_is_enabled ? PM_EMAIL_NOTIFY_LEVEL_DEFAULT : PM_EMAIL_NOTIFY_LEVEL_DISABLED);
  }
  db_drop_table('pm_email_notify');
}