You are here

function mailhandler_update_7206 in Mailhandler 7.2

Updates mailbox type to new format.

Between 2.0-rc1 and 2.0, the keys for mailbox type (IMAP/POP) changed, but the existing mailboxes were not updated. Additionally, between 2.0 and 2.1, this option was changed to avoid further confusion.

File

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

Code

function mailhandler_update_7206() {
  $result = db_query('SELECT * FROM {mailhandler_mailbox}');
  while ($row = $result
    ->fetchAssoc()) {
    $row['settings'] = unserialize($row['settings']);
    if (isset($row['settings']['imap'])) {
      switch ($row['settings']['imap']) {
        case '0':
          $row['settings']['type'] = 'pop3';
          break;
        case '1':
          $row['settings']['type'] = 'imap';
          break;
      }
      if (empty($row['settings']['domain'])) {
        $row['settings']['type'] = 'local';
      }
      unset($row['settings']['imap']);
      db_update('mailhandler_mailbox')
        ->fields(array(
        'settings' => serialize($row['settings']),
      ))
        ->condition('mid', $row['mid'])
        ->execute();
    }
  }
}