Using version 6.x-1.1 of knurl it's impossible to add more than one short url!
The reason is, that you're using a field called 'tid' as primary key which is neither incremented in your code nor an auto increment field in the database. (Might be some old code).
Unfortunetely you don't handle database errors and report success to the user. But the database error could be found in watchdog:
Duplicate entry for key 1 query: INSERT INTO knurl (uid, short_url, link) values ...
Attached you'll find a patch that changes the database schema using hook_update for a 6.x-1.2 release. Additionally I changed the code for saving a new short URL to deal with database errors.
| Comment | File | Size | Author |
|---|---|---|---|
| fix_db_schema.patch | 3.99 KB | mkalkbrenner |
Comments
Comment #1
schandur commentedHi Markus,
Any reason why you decided to drop the tid field? In my local setup, I changed the 'tid' field's type to 'serial' (in hook_schema) and it seems to be working fine.
Cheers,
Sandeep
Comment #2
mkalkbrennerHi schandur,
I searched the code for tid and didn't find any real need for it.
On the other hand most queries use an index over short_url to get their result.
So the benefit of droping tid and declaring short_url as primary key is that you have one index less on your database (which only matters in large scale environments in different ways) and that short_url becomes unique on the database layer (which could also be achieved via an additional unique constraint in schema).
Additionally tid isn't a good name for that field because most people would associate taxonomy term ids with tid.
Markus
Comment #3
devkinetic commentedI believe i found a good middle ground between both fixes. Changing tid to kid for "knurl ID" and changing it's type to serial. I left it in because it serves as a good way to find the most recently added items and works well on the redesigned "knurl/show" page.
This will be patched in the release in a few days. if you are running a modified version be sure to disable and uninstall your existing module before updating as the patch is based off of the 1.1 release.
Comment #4
devkinetic commentedComment #5
devkinetic commentednix my previous comment, you can now upgrade from 1.1 to 1.2 when released, i've added a hook_update in the schema.