wysiwyg_editor.install 2.02 KB
Newer Older
1 2 3 4
<?php
// $Id$

/**
5
 * Implementation of hook_install().
6
 */
7
function wysiwyg_editor_install() {
8 9 10
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
11 12 13 14 15 16 17 18 19 20
      db_query("CREATE TABLE {wysiwyg_editor_profile} (
        name varchar(128) NOT NULL default '',
        settings text,
        PRIMARY KEY (name)
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE {wysiwyg_editor_role} (
        name varchar(128) NOT NULL default '',
        rid tinyint(3) unsigned NOT NULL default '0',
        PRIMARY KEY (name,rid)
      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
21 22 23
      break;

    case 'pgsql':
24 25 26 27 28 29 30 31 32 33
      db_query("CREATE TABLE {wysiwyg_editor_profile} (
        name varchar(128) NOT NULL default '',
        settings text,
        PRIMARY KEY (name)
      )");
      db_query("CREATE TABLE {wysiwyg_editor_role} (
        name varchar(128) NOT NULL default '',
        rid smallint NOT NULL default '0',
        PRIMARY KEY (name,rid)
      )");
34 35
      break;
   }
36 37
   // Import data from old editor modules.
   wysiwyg_editor_migrate_tinymce();
38 39
}

40 41 42 43 44 45
/**
 * Implementation of hook_uninstall()
 */
function wysiwyg_editor_uninstall() {
  db_query('DROP TABLE {wysiwyg_editor_profile}');
  db_query('DROP TABLE {wysiwyg_editor_role}');
46 47 48
}

/**
49
 * Migrate from TinyMCE.
50
 */
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
function wysiwyg_editor_migrate_tinymce() {
  if (db_table_exists('tinymce_settings')) {
    $schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
    if ($schema >= 1) {
      // Import TinyMCE settings.
      db_query('INSERT INTO {wysiwyg_editor_profile} SELECT * FROM {tinymce_settings}');
      // Import TinyMCE profile role assignments.
      db_query('INSERT INTO {wysiwyg_editor_role} SELECT * FROM {tinymce_role}');
      
      // Disable TinyMCE module.
      module_disable(array('tinymce'));
    }
    else {
      drupal_set_message(t('To migrate your existing TinyMCE settings to Wysiwyg Editor, please update TinyMCE module to the latest official release, and re-install Wysiwyg Editor module.'));
    }
  }
67
}
68