5 * Implementation of hook_schema().
7 function wysiwyg_schema() {
8 $schema['wysiwyg'] = array(
9 'description' => t('Stores Wysiwyg profiles.'),
11 'format' => array('type' => 'int', 'not null' => TRUE
, 'default' => 0),
12 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE
, 'default' => ''),
13 'settings' => array('type' => 'text', 'size' => 'normal'),
15 'primary key' => array('format'),
21 * Implementation of hook_enable().
23 function wysiwyg_enable() {
24 // Disable conflicting, obsolete editor integration modules whenever this
25 // module is enabled. This is crude, but the only way to ensure no conflicts.
52 * Retrieve a list of input formats to associate profiles to.
54 function _wysiwyg_install_get_formats() {
56 $result = db_query("SELECT format, name FROM {filter_formats}");
57 while ($format = db_fetch_object($result)) {
58 // Build a list of all formats.
59 $formats[$format->format
] = $format->name
;
61 $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format
);
62 while ($filter = db_fetch_object($result2)) {
63 // If PHP filter is enabled, remove this format.
64 if ($filter->module
== 'php') {
65 unset($formats[$format->format
]);
74 * Associate Wysiwyg profiles with input formats.
76 * Since there was no association yet, we can only assume that there is one
77 * profile only, and that profile must be duplicated and assigned to all input
78 * formats (except PHP code format). Also, input formats already have
79 * titles/names, so Wysiwyg profiles do not need an own.
81 * Because input formats are already granted to certain user roles only, we can
82 * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
83 * input formats and permissions makes plugin_count obsolete, too.
85 * Since the resulting table is completely different, a new schema is installed.
87 function wysiwyg_update_6001() {
89 if (db_table_exists('wysiwyg')) {
92 // Install new schema.
93 db_create_table($ret, 'wysiwyg', array(
95 'format' => array('type' => 'int', 'not null' => TRUE
, 'default' => 0),
96 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE
, 'default' => ''),
97 'settings' => array('type' => 'text', 'size' => 'normal'),
99 'primary key' => array('format'),
102 // Fetch all input formats.
103 $formats = _wysiwyg_install_get_formats();
105 // Fetch all profiles.
106 $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
107 while ($profile = db_fetch_object($result)) {
108 $profile->settings
= unserialize($profile->settings
);
109 // Extract editor name from profile settings.
110 $profile->editor
= $profile->settings
['editor'];
112 unset($profile->settings
['editor']);
113 unset($profile->settings
['old_name']);
114 unset($profile->settings
['name']);
115 unset($profile->settings
['rids']);
116 // Sorry. There Can Be Only One. ;)
121 // Rebuild profiles and associate with input formats.
122 foreach ($formats as
$format => $name) {
124 // We can't use update_sql() here because of curly braces in serialized
126 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor
, serialize($profile->settings
));
129 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name
), '%format' => check_plain($name))),
134 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
135 db_drop_table($ret, 'wysiwyg_profile');
136 db_drop_table($ret, 'wysiwyg_role');
142 * Clear JS/CSS caches to ensure that clients load fresh copies.
144 function wysiwyg_update_6200() {
146 // Change query-strings on css/js files to enforce reload for all users.
147 _drupal_flush_css_js();
149 drupal_clear_css_cache();
150 drupal_clear_js_cache();
152 // Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
155 // Flush content caches.
160 'query' => 'Caches have been flushed.',