Closed dilab closed 10 years ago
How so? Number 4 wouldn't generate "abc-1" as "abc" doesn't exist, it would stay as "abc".
Because you are using LIKE to check the slug.
So the conditions is [slug LIKE] => 'abc%'. Which will return count as 1.
That is how you get 'abc-1' at the Number 4.
Hope it is clear.
I'll have to change the LIKE logic then, because I guess "abcd" will also trigger it.
Rewrote the queries.
This will not work.
For example:
You will see point 2 and 3 are producing the same slug.
Why do not you just use a while loop to check the uniqueness of the slug?
It runs 2 queries, so if our slug was abc.
1st query - If abc does not exist, then abc is the slug, else... 2nd query - Do a wildcard search for abc-%, which will return slug as abc-#.
The queries aren't doing an &&, they are 2 separate queries.
My point 3 is saying:
1st query: abc exists, and $count = 1 , so continue to 2nd query 2nd query: it only check abc-%, which will return $count = 1 again. Which generates a slug with value of 'abc-1'.
You see the problem here? point 2 and 3 are producing the same slug.
I just need to fix that if statement, one sec.
_makeUnique functions checks the slug and append a count. This is not a correct way to make it unique.
e.g.