You are here

function _subscriptions_mail_mail_edit_import in Subscriptions 6

1 call to _subscriptions_mail_mail_edit_import()
subscriptions_mail_mail_edit_list_form_submit in ./subscriptions_mail.mail_edit_D5.inc

File

./subscriptions_mail.mail_edit_D5.inc, line 142
Subscriptions module mail gateway helper functions for upgrading mail_edit D5 to D6.

Code

function _subscriptions_mail_mail_edit_import($old_mailkey, $new_mailkey, $description, $languages) {
  $success = FALSE;
  if ($row = db_fetch_array(db_query("SELECT * FROM {mail_edit_d5} WHERE mailkey = '%s'", $old_mailkey))) {
    if (empty($row['description'])) {
      $row['description'] = filter_xss($description, array());
    }
    $success = TRUE;
    foreach ($languages as $language) {
      $variables = array(
        '%key' => $new_mailkey,
        '%language' => $language,
      );
      if (db_result(db_query("SELECT COUNT(*) FROM {mail_edit} WHERE id = '%s' AND language = '%s'", $new_mailkey, $language))) {
        drupal_set_message(t("%language translation of %key cannot be imported because it's already defined.", $variables), 'warning');
        $success = FALSE;
      }
      elseif (db_query("INSERT INTO {mail_edit} (description, subject, id, body, language) VALUES ('%s', '%s', '%s', '%s', '%s')", $row['description'], $row['subject'], $new_mailkey, $row['body'], $language) && db_affected_rows()) {
        drupal_set_message(t('%language translation of %key has been imported.', $variables));
      }
      else {
        drupal_set_message(t('%language translation of %key failed to import.', $variables), 'error');
        $success = FALSE;
      }
    }
    if ($success) {
      db_query("DELETE FROM {mail_edit_d5} WHERE mailkey = '%s'", $old_mailkey);
    }
  }
  return $success;
}