You are here

function wysiwyg_migrate_tinymce in Wysiwyg 6

Same name and namespace in other branches
  1. 5 wysiwyg.install \wysiwyg_migrate_tinymce()

Migrate from TinyMCE.

1 call to wysiwyg_migrate_tinymce()
wysiwyg_install in ./wysiwyg.install
Implementation of hook_install().

File

./wysiwyg.install, line 39

Code

function wysiwyg_migrate_tinymce() {
  if (db_table_exists('tinymce_settings')) {
    $schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
    if ($schema >= 1) {

      // Migrate profile configurations.
      $profiles = db_query("SELECT settings FROM {tinymce_settings}");
      while ($profile = db_fetch_array($profiles)) {
        $settings = unserialize($profile['settings']);

        // Convert buttons/plugins into an associative array.
        $old_buttons = isset($settings['buttons']) ? $settings['buttons'] : array();
        $settings['buttons'] = array();
        foreach ($old_buttons as $old_button => $enabled) {
          list($plugin, $button) = explode('-', $old_button, 2);
          $settings['buttons'][$plugin][$button] = 1;
        }
        foreach (_wysiwyg_install_get_formats() as $format => $name) {

          // We can't use update_sql() here because of curly braces in serialized
          // array.
          db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, 'tinymce', '%s')", $format, serialize($settings));
        }

        // We can only migrate one profile.
        break;
      }

      // Disable TinyMCE module.
      module_disable(array(
        'tinymce',
      ));
      drupal_set_message('TinyMCE module can be safely uninstalled now.');
    }
    else {
      drupal_set_message('To migrate your existing TinyMCE settings to Wysiwyg Editor, please update TinyMCE module to the latest official release, and re-install Wysiwyg Editor module.');
    }
  }
}