Installing an in-code input format with the same name as an existing in-database input format produces SQL errors:
Duplicate entry 'Filtered HTML' for key 2 query: INSERT INTO ho4p_filter_formats (name) VALUES ('Filtered HTML') in /var/www/drupal/sites/all/modules/input_formats/input_formats.module on line 515.
Duplicate entry 'Filtered HTML' for key 2 query: UPDATE ho4p_filter_formats SET cache = 1, name='Filtered HTML', roles = ',1,2,' WHERE format = 3 in /var/www/drupal/sites/all/modules/input_formats/input_formats.module on line 535.
It also messes up database records for another existing in-database input format. This is because "name" is primary key on "filter_formats" table, and input_formats_save() does not check for errors when insering there on line 515. When a duplicate insert is attempted, then $input_format->format is set incorrectly in the next code line, and subsequent code in input_formats_save() goes on to update that wrong format, effectively messing it up completely.
Attached a patch (against CVS HEAD). The new code, upon finding an in-database format with the same name, updates it instead of trying to create a new format. I'm not sure if this is ideal behaviour, but at least it seems better than the current one.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | input_formats-duplicate-entry-991344-4.patch | 1.28 KB | scottrigby |
| #5 | input_formats-duplicate-entry-991344-5.patch | 1.31 KB | scottrigby |
| input_formats-duplicates.patch | 1.06 KB | ahtih |
Comments
Comment #1
hiddentao commentedAm having this same problem. +1.
I'm using Input Formats with Exportables and the Exportables table gets corrupted because all the filter formats end up having the same ids in it.
Comment #2
andrew_mallis commentedAlso had this problem. We want to control the allowd html allowed tags.
The patch above made the error go away, but does not insert our new values anywhere in this input format/
Comment #3
davidtrainer commentedsubscribing.
Comment #4
scottrigbyRewrote this a bitgit-formatted patch against 6.x-1.x (assuming that's where development is happening apart from the api?)Edit: Use #5 instead
Comment #5
scottrigbyRevised. It's be great to get someone to test this on a fresh install.
Comment #6
dagmarThanks for working on this. I will commit this if you say that works. However I have a question:
What happens with "The patch above made the error go away, but does not insert our new values anywhere in this input format/" mentioned in #2?
Comment #7
scottrigbyhi dagmar - I rewrote the query to do exactly what the original part of this function does (insert a record so we can get the numeric format id), except it checks to make sure that format isn't already there before trying to insert it.
Rather than a single query like #1, I used a few more lines but made it more readable, and also should be DB-type-agnostic. So I don't think #2 will be an issue here
Comment #8
ZenDoodles commented/me waves at scottrigby
I have reviewed and tested this patch (although not on a fresh install yet). It looks good to me.
Comment #9
c4rl commentedBump! There it is.
This project need a new maintainer? #D6forlife.