summaryrefslogtreecommitdiffstats
path: root/wysiwyg_editor.install
blob: aa3bd70e28b6d2023205e7fb108f8a8fc5a9f820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
// $Id$


/**
 * Implementation of hook_schema().
 */
function wysiwyg_editor_schema() {
  $schema = array();
  $schema['wysiwyg_editor_profile'] = array(
    'description' => t('Stores Wysiwyg Editor profiles.'),
    'fields' => array(
      'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
      'settings' => array('type' => 'text', 'size' => 'normal'),
      'plugin_count' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
    ),
    'primary key' => array('name'),
  );
  $schema['wysiwyg_editor_role'] = array(
    'description' => t('Stores user role access permissions for Wysiwyg Editor profiles.'),
    'fields' => array(
      'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
      'rid' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
    ),
    'primary key' => array('name', 'rid'),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function wysiwyg_editor_install() {
  drupal_install_schema('wysiwyg_editor');
  // Import data from old editor modules.
  wysiwyg_editor_migrate_tinymce();
}

/**
 * Implementation of hook_uninstall()
 */
function wysiwyg_editor_uninstall() {
  drupal_uninstall_schema('wysiwyg_editor');
}

/**
 * Migrate from TinyMCE.
 */
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} (name, settings) SELECT name, settings FROM {tinymce_settings}');
      // Import TinyMCE profile role assignments.
      db_query('INSERT INTO {wysiwyg_editor_role} (name, rid) SELECT name, rid FROM {tinymce_role}');

      // Disable TinyMCE module.
      module_disable(array('tinymce'));

      // Update configuration.
      wysiwyg_editor_update_5001();
    }
    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.'));
    }
  }
}

/**
 * Convert buttons and plugins into associative array and fix plugin count for old profiles.
 *
 * Note: This update is required for wysiwyg_editor_migrate_tinymce().
 */
function wysiwyg_editor_update_5001() {
  $ret = array();
  $profiles = db_query("SELECT name, settings, plugin_count FROM {wysiwyg_editor_profile}");
  while ($profile = db_fetch_array($profiles)) {
    $settings = unserialize($profile['settings']);
    if (isset($settings['form_id'])) {
      $old_buttons = (isset($settings['buttons']) ? $settings['buttons'] : array());
      $settings['buttons'] = array();
      $plugin_count = 0;
      foreach ($old_buttons as $old_button => $enabled) {
        list($plugin, $button) = explode('-', $old_button, 2);
        $settings['buttons'][$plugin][$button] = 1;
        $plugin_count++;
      }
      // We can't use update_sql() here because of curly braces in serialized
      // array.
      db_query("UPDATE {wysiwyg_editor_profile} SET settings = '%s', plugin_count = %d WHERE name = '%s'", serialize($settings), $plugin_count, $profile['name']);
    }
  }
  return $ret;
}

/**
 * Add editor key to wysiwyg profiles.
 */
function wysiwyg_editor_update_6002() {
  $ret = array();
  $profiles = db_query("SELECT name, settings FROM {wysiwyg_editor_profile}");
  while ($profile = db_fetch_object($profiles)) {
    $settings = unserialize($profile->settings);
    if (!isset($settings['editor'])) {
      $settings['editor'] = 'tinymce';
      // We can't use update_sql() here because of curly braces in serialized
      // array.
      db_query("UPDATE {wysiwyg_editor_profile} SET settings = '%s' WHERE name = '%s'", serialize($settings), $profile->name);
    }
  }
  return $ret;
}