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');
29 * Implementation of hook_uninstall()
31 function wysiwyg_uninstall() {
32 drupal_uninstall_schema('wysiwyg');
36 * Implementation of hook_enable().
38 function wysiwyg_enable() {
39 // Disable conflicting, obsolete editor integration modules whenever this
40 // module is enabled. This is crude, but the only way to ensure no conflicts.
67 * Retrieve a list of input formats to associate profiles to.
69 function _wysiwyg_install_get_formats() {
71 $result = db_query("SELECT format, name FROM {filter_formats}");
72 while ($format = db_fetch_object($result)) {
73 // Build a list of all formats.
74 $formats[$format->format
] = $format->name
;
76 $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format
);
77 while ($filter = db_fetch_object($result2)) {
78 // If PHP filter is enabled, remove this format.
79 if ($filter->module
== 'php') {
80 unset($formats[$format->format
]);
89 * Associate Wysiwyg profiles with input formats.
91 * Since there was no association yet, we can only assume that there is one
92 * profile only, and that profile must be duplicated and assigned to all input
93 * formats (except PHP code format). Also, input formats already have
94 * titles/names, so Wysiwyg profiles do not need an own.
96 * Because input formats are already granted to certain user roles only, we can
97 * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
98 * input formats and permissions makes plugin_count obsolete, too.
100 * Since the resulting table is completely different, a new schema is installed.
102 function wysiwyg_update_6001() {
104 if (db_table_exists('wysiwyg')) {
107 // Install new schema.
108 db_create_table($ret, 'wysiwyg', array(
110 'format' => array('type' => 'int', 'not null' => TRUE
, 'default' => 0),
111 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE
, 'default' => ''),
112 'settings' => array('type' => 'text', 'size' => 'normal'),
114 'primary key' => array('format'),
117 // Fetch all input formats.
118 $formats = _wysiwyg_install_get_formats();
120 // Fetch all profiles.
121 $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
122 while ($profile = db_fetch_object($result)) {
123 $profile->settings
= unserialize($profile->settings
);
124 // Extract editor name from profile settings.
125 $profile->editor
= $profile->settings
['editor'];
127 unset($profile->settings
['editor']);
128 unset($profile->settings
['old_name']);
129 unset($profile->settings
['name']);
130 unset($profile->settings
['rids']);
131 // Sorry. There Can Be Only One. ;)
136 // Rebuild profiles and associate with input formats.
137 foreach ($formats as
$format => $name) {
139 // We can't use update_sql() here because of curly braces in serialized
141 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor
, serialize($profile->settings
));
144 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name
), '%format' => check_plain($name))),
149 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
150 db_drop_table($ret, 'wysiwyg_profile');
151 db_drop_table($ret, 'wysiwyg_role');