You are here

function mailhandler_update_6204 in Mailhandler 6.2

Move human-readable mailbox name into separate field.

File

./mailhandler.install, line 306
Install, update and uninstall functions for the Mailhandler module.

Code

function mailhandler_update_6204() {
  $ret = array();
  $table = 'mailhandler_mailbox';
  $field = 'admin_title';
  $field_def = array(
    'type' => 'varchar',
    'length' => '255',
    'description' => 'Human-readable name (email address) of this mailbox.',
  );
  if (!db_column_exists($table, $field)) {
    db_add_field($ret, $table, $field, $field_def);
    $result = db_query('SELECT * FROM {mailhandler_mailbox}');
    while ($row = db_fetch_array($result)) {
      $row['settings'] = unserialize($row['settings']);
      $row['admin_title'] = $row['settings']['mail'];
      unset($row['settings']['mail']);
      db_query("UPDATE {mailhandler_mailbox} SET admin_title = '%s', settings = '%s' WHERE mid = %d", $row['admin_title'], serialize($row['settings']), $row['mid']);
    }
    cache_clear_all('plugins:feeds:plugins', 'cache');
  }
  return $ret;
}