Issue #1132142 by tacituseu, TwoD, sun: Fixed nicEdit not removing its
[project/wysiwyg.git] / wysiwyg.install
1 <?php
2
3 /**
4 * @file
5 * Installation functions for Wysiwyg module.
6 */
7
8 /**
9 * Implementation of hook_schema().
10 */
11 function wysiwyg_schema() {
12 $schema['wysiwyg'] = array(
13 'description' => 'Stores Wysiwyg profiles.',
14 'fields' => array(
15 'format' => array(
16 'description' => 'The {filter_format}.format of the text format.',
17 'type' => 'varchar',
18 'length' => 255,
19 // Primary keys are implicitly not null.
20 'not null' => TRUE,
21 ),
22 'editor' => array(
23 'description' => 'Internal name of the editor attached to the text format.',
24 'type' => 'varchar',
25 'length' => 128,
26 'not null' => TRUE,
27 'default' => '',
28 ),
29 'settings' => array(
30 'description' => 'Configuration settings for the editor.',
31 'type' => 'text',
32 'size' => 'normal',
33 ),
34 ),
35 'primary key' => array('format'),
36 'foreign keys' => array(
37 'format' => array(
38 'table' => 'filter_format',
39 'columns' => array('format' => 'format'),
40 ),
41 ),
42 );
43 $schema['wysiwyg_user'] = array(
44 'description' => 'Stores user preferences for wysiwyg profiles.',
45 'fields' => array(
46 'uid' => array(
47 'description' => 'The {users}.uid of the user.',
48 'type' => 'int',
49 'unsigned' => TRUE,
50 'not null' => TRUE,
51 'default' => 0,
52 ),
53 'format' => array(
54 'description' => 'The {filter_format}.format of the text format.',
55 'type' => 'varchar',
56 'length' => 255,
57 'not null' => FALSE,
58 ),
59 'status' => array(
60 'description' => 'Boolean indicating whether the format is enabled by default.',
61 'type' => 'int',
62 'unsigned' => TRUE,
63 'not null' => TRUE,
64 'default' => 0,
65 'size' => 'tiny',
66 ),
67 ),
68 'indexes' => array(
69 'uid' => array('uid'),
70 'format' => array('format'),
71 ),
72 'foreign keys' => array(
73 'uid' => array(
74 'table' => 'users',
75 'columns' => array('uid' => 'uid'),
76 ),
77 'format' => array(
78 'table' => 'filter_format',
79 'columns' => array('format' => 'format'),
80 ),
81 ),
82 );
83 return $schema;
84 }
85
86 /**
87 * Implementation of hook_enable().
88 */
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.
92 module_disable(array(
93 'ckeditor',
94 'editarea',
95 'editonpro',
96 'editor',
97 'fckeditor',
98 'freerte',
99 'htmlarea',
100 'htmlbox',
101 'jwysiwyg',
102 'markitup',
103 'nicedit',
104 'openwysiwyg',
105 'pegoeditor',
106 'quicktext',
107 'tinymce',
108 'tinymce_autoconf',
109 'tinytinymce',
110 'whizzywig',
111 'widgeditor',
112 'wymeditor',
113 'xstandard',
114 'yui_editor',
115 ));
116 }
117
118 /**
119 * Implements hook_update_dependencies().
120 */
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(
125 'filter' => 7010,
126 );
127
128 return $dependencies;
129 }
130
131 /**
132 * Retrieve a list of input formats to associate profiles to.
133 */
134 function _wysiwyg_install_get_formats() {
135 $formats = array();
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;
140 // Fetch filters.
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]);
146 break;
147 }
148 }
149 }
150 return $formats;
151 }
152
153 /**
154 * Associate Wysiwyg profiles with input formats.
155 *
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.
160 *
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.
164 *
165 * Since the resulting table is completely different, a new schema is installed.
166 */
167 function wysiwyg_update_6001() {
168 $ret = array();
169 if (db_table_exists('wysiwyg')) {
170 return $ret;
171 }
172 // Install new schema.
173 db_create_table($ret, 'wysiwyg', array(
174 'fields' => 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'),
178 ),
179 'primary key' => array('format'),
180 ));
181
182 // Fetch all input formats.
183 $formats = _wysiwyg_install_get_formats();
184
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'];
191 // Clean-up.
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. ;)
197 break;
198 }
199
200 if ($profile) {
201 // Rebuild profiles and associate with input formats.
202 foreach ($formats as $format => $name) {
203 // Insert profiles.
204 // We can't use update_sql() here because of curly braces in serialized
205 // array.
206 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor, serialize($profile->settings));
207 $ret[] = array(
208 'success' => TRUE,
209 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name), '%format' => check_plain($name))),
210 );
211 }
212 }
213
214 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
215 db_drop_table($ret, 'wysiwyg_profile');
216 db_drop_table($ret, 'wysiwyg_role');
217
218 return $ret;
219 }
220
221 /**
222 * Clear JS/CSS caches to ensure that clients load fresh copies.
223 */
224 function wysiwyg_update_6200() {
225 $ret = array();
226 // Change query-strings on css/js files to enforce reload for all users.
227 _drupal_flush_css_js();
228
229 drupal_clear_css_cache();
230 drupal_clear_js_cache();
231
232 // Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
233 menu_rebuild();
234
235 // Flush content caches.
236 cache_clear_all();
237
238 $ret[] = array(
239 'success' => TRUE,
240 'query' => 'Caches have been flushed.',
241 );
242 return $ret;
243 }
244
245 /**
246 * Change {wysiwyg}.format into a string.
247 */
248 function wysiwyg_update_7000() {
249 db_drop_primary_key('wysiwyg');
250 db_change_field('wysiwyg', 'format', 'format', array(
251 'type' => 'varchar',
252 'length' => 255,
253 'not null' => TRUE,
254 ));
255 db_add_primary_key('wysiwyg', array('format'));
256 }
257
258 /**
259 * Create the {wysiwyg_user} table.
260 */
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.',
265 'fields' => array(
266 'uid' => array(
267 'description' => 'The {users}.uid of the user.',
268 'type' => 'int',
269 'unsigned' => TRUE,
270 'not null' => TRUE,
271 'default' => 0,
272 ),
273 'format' => array(
274 'description' => 'The {filter_format}.format of the text format.',
275 'type' => 'varchar',
276 'length' => 255,
277 'not null' => FALSE,
278 ),
279 'status' => array(
280 'description' => 'Boolean indicating whether the format is enabled by default.',
281 'type' => 'int',
282 'unsigned' => TRUE,
283 'not null' => TRUE,
284 'default' => 0,
285 'size' => 'tiny',
286 ),
287 ),
288 'indexes' => array(
289 'uid' => array('uid'),
290 'format' => array('format'),
291 ),
292 'foreign keys' => array(
293 'uid' => array(
294 'table' => 'users',
295 'columns' => array('uid' => 'uid'),
296 ),
297 'format' => array(
298 'table' => 'filter_format',
299 'columns' => array('format' => 'format'),
300 ),
301 ),
302 ));
303 }
304 else {
305 db_change_field('wysiwyg_user', 'format', 'format', array(
306 'description' => 'The {filter_format}.format of the text format.',
307 'type' => 'varchar',
308 'length' => 255,
309 'not null' => FALSE,
310 ));
311 }
312 }