5 * Installation functions for Wysiwyg module.
9 * Implementation of hook_schema().
11 function wysiwyg_schema() {
12 $schema['wysiwyg'] = array(
13 'description' => 'Stores Wysiwyg profiles.',
16 'description' => 'The {filter_format}.format of the text format.',
19 // Primary keys are implicitly not null.
23 'description' => 'Internal name of the editor attached to the text format.',
30 'description' => 'Configuration settings for the editor.',
35 'primary key' => array('format'),
36 'foreign keys' => array(
38 'table' => 'filter_format',
39 'columns' => array('format' => 'format'),
43 $schema['wysiwyg_user'] = array(
44 'description' => 'Stores user preferences for wysiwyg profiles.',
47 'description' => 'The {users}.uid of the user.',
54 'description' => 'The {filter_format}.format of the text format.',
60 'description' => 'Boolean indicating whether the format is enabled by default.',
69 'uid' => array('uid'),
70 'format' => array('format'),
72 'foreign keys' => array(
75 'columns' => array('uid' => 'uid'),
78 'table' => 'filter_format',
79 'columns' => array('format' => 'format'),
87 * Implementation of hook_enable().
89 function wysiwyg_enable() {
90 // Disable conflicting, obsolete editor integration modules whenever this
91 // module is enabled. This is crude, but the only way to ensure no conflicts.
119 * Implements hook_update_dependencies().
121 function wysiwyg_update_dependencies() {
122 // Ensure that format columns are only changed after Filter module has changed
123 // the primary records.
124 $dependencies['wysiwyg'][7000] = array(
128 return $dependencies;
132 * Retrieve a list of input formats to associate profiles to.
134 function _wysiwyg_install_get_formats() {
136 $result = db_query("SELECT format, name FROM {filter_formats}");
137 while ($format = db_fetch_object($result)) {
138 // Build a list of all formats.
139 $formats[$format->format
] = $format->name
;
141 $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format
);
142 while ($filter = db_fetch_object($result2)) {
143 // If PHP filter is enabled, remove this format.
144 if ($filter->module
== 'php') {
145 unset($formats[$format->format
]);
154 * Associate Wysiwyg profiles with input formats.
156 * Since there was no association yet, we can only assume that there is one
157 * profile only, and that profile must be duplicated and assigned to all input
158 * formats (except PHP code format). Also, input formats already have
159 * titles/names, so Wysiwyg profiles do not need an own.
161 * Because input formats are already granted to certain user roles only, we can
162 * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
163 * input formats and permissions makes plugin_count obsolete, too.
165 * Since the resulting table is completely different, a new schema is installed.
167 function wysiwyg_update_6001() {
169 if (db_table_exists('wysiwyg')) {
172 // Install new schema.
173 db_create_table($ret, 'wysiwyg', array(
175 'format' => array('type' => 'int', 'not null' => TRUE
, 'default' => 0),
176 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE
, 'default' => ''),
177 'settings' => array('type' => 'text', 'size' => 'normal'),
179 'primary key' => array('format'),
182 // Fetch all input formats.
183 $formats = _wysiwyg_install_get_formats();
185 // Fetch all profiles.
186 $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
187 while ($profile = db_fetch_object($result)) {
188 $profile->settings
= unserialize($profile->settings
);
189 // Extract editor name from profile settings.
190 $profile->editor
= $profile->settings
['editor'];
192 unset($profile->settings
['editor']);
193 unset($profile->settings
['old_name']);
194 unset($profile->settings
['name']);
195 unset($profile->settings
['rids']);
196 // Sorry. There Can Be Only One. ;)
201 // Rebuild profiles and associate with input formats.
202 foreach ($formats as
$format => $name) {
204 // We can't use update_sql() here because of curly braces in serialized
206 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor
, serialize($profile->settings
));
209 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name
), '%format' => check_plain($name))),
214 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
215 db_drop_table($ret, 'wysiwyg_profile');
216 db_drop_table($ret, 'wysiwyg_role');
222 * Clear JS/CSS caches to ensure that clients load fresh copies.
224 function wysiwyg_update_6200() {
226 // Change query-strings on css/js files to enforce reload for all users.
227 _drupal_flush_css_js();
229 drupal_clear_css_cache();
230 drupal_clear_js_cache();
232 // Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
235 // Flush content caches.
240 'query' => 'Caches have been flushed.',
246 * Change {wysiwyg}.format into a string.
248 function wysiwyg_update_7000() {
249 db_drop_primary_key('wysiwyg');
250 db_change_field('wysiwyg', 'format', 'format', array(
255 db_add_primary_key('wysiwyg', array('format'));
259 * Create the {wysiwyg_user} table.
261 function wysiwyg_update_7200() {
262 if (!db_table_exists('wysiwyg_user')) {
263 db_create_table('wysiwyg_user', array(
264 'description' => 'Stores user preferences for wysiwyg profiles.',
267 'description' => 'The {users}.uid of the user.',
274 'description' => 'The {filter_format}.format of the text format.',
280 'description' => 'Boolean indicating whether the format is enabled by default.',
289 'uid' => array('uid'),
290 'format' => array('format'),
292 'foreign keys' => array(
295 'columns' => array('uid' => 'uid'),
298 'table' => 'filter_format',
299 'columns' => array('format' => 'format'),
305 db_change_field('wysiwyg_user', 'format', 'format', array(
306 'description' => 'The {filter_format}.format of the text format.',