5 * Implementation of hook_schema().
7 function wysiwyg_schema() {
9 $schema['wysiwyg'] = array(
10 'description' => t('Stores Wysiwyg profiles.'),
12 'format' => array('type' => 'int', 'not null' => TRUE
, 'default' => 0),
13 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE
, 'default' => ''),
14 'settings' => array('type' => 'text', 'size' => 'normal'),
16 'primary key' => array('format'),
22 * Implementation of hook_install().
24 function wysiwyg_install() {
25 drupal_install_schema('wysiwyg');
26 // Import settings from old editor modules.
27 wysiwyg_migrate_tinymce();
31 * Implementation of hook_uninstall()
33 function wysiwyg_uninstall() {
34 drupal_uninstall_schema('wysiwyg');
38 * Migrate from TinyMCE.
40 function wysiwyg_migrate_tinymce() {
41 if (db_table_exists('tinymce_settings')) {
42 $schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
44 // Migrate profile configurations.
45 $profiles = db_query("SELECT settings FROM {tinymce_settings}");
46 while ($profile = db_fetch_array($profiles)) {
47 $settings = unserialize($profile['settings']);
48 // Convert buttons/plugins into an associative array.
49 $old_buttons = (isset($settings['buttons']) ?
$settings['buttons'] : array());
50 $settings['buttons'] = array();
51 foreach ($old_buttons as
$old_button => $enabled) {
52 list($plugin, $button) = explode('-', $old_button, 2);
53 $settings['buttons'][$plugin][$button] = 1;
55 foreach (_wysiwyg_install_get_formats() as
$format => $name) {
56 // We can't use update_sql() here because of curly braces in serialized
58 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, 'tinymce', '%s')", $format, serialize($settings));
60 // We can only migrate one profile.
63 // Disable TinyMCE module.
64 module_disable(array('tinymce'));
65 drupal_set_message('TinyMCE module can be safely uninstalled now.');
68 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.');
74 * Retrieve a list of input formats to associate profiles to.
76 function _wysiwyg_install_get_formats() {
78 $result = db_query("SELECT format, name FROM {filter_formats}");
79 while ($format = db_fetch_object($result)) {
80 // Build a list of all formats.
81 $formats[$format->format
] = $format->name
;
83 $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format
);
84 while ($filter = db_fetch_object($result2)) {
85 // If PHP filter is enabled, remove this format.
86 if ($filter->module
== 'php') {
87 unset($formats[$format->format
]);
96 * Associate Wysiwyg profiles with input formats.
98 * Since there was no association yet, we can only assume that there is one
99 * profile only, and that profile must be duplicated and assigned to all input
100 * formats (except PHP code format). Also, input formats already have
101 * titles/names, so Wysiwyg profiles do not need an own.
103 * Because input formats are already granted to certain user roles only, we can
104 * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
105 * input formats and permissions makes plugin_count obsolete, too.
107 * Since the resulting table is completely different, a new schema is installed.
109 function wysiwyg_update_6001() {
111 if (db_table_exists('wysiwyg')) {
114 // Install new schema.
115 db_create_table($ret, 'wysiwyg', array(
117 'format' => array('type' => 'int', 'not null' => TRUE
, 'default' => 0),
118 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE
, 'default' => ''),
119 'settings' => array('type' => 'text', 'size' => 'normal'),
121 'primary key' => array('format'),
124 // Fetch all input formats.
125 $formats = _wysiwyg_install_get_formats();
127 // Fetch all profiles.
128 $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
129 while ($profile = db_fetch_object($result)) {
130 $profile->settings
= unserialize($profile->settings
);
131 // Extract editor name from profile settings.
132 $profile->editor
= $profile->settings
['editor'];
134 unset($profile->settings
['editor']);
135 unset($profile->settings
['old_name']);
136 unset($profile->settings
['name']);
137 unset($profile->settings
['rids']);
138 // Sorry. There Can Be Only One. ;)
143 // Rebuild profiles and associate with input formats.
144 foreach ($formats as
$format => $name) {
146 // We can't use update_sql() here because of curly braces in serialized
148 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor
, serialize($profile->settings
));
151 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name
), '%format' => check_plain($name))),
156 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
157 db_drop_table($ret, 'wysiwyg_profile');
158 db_drop_table($ret, 'wysiwyg_role');