Duplicate Titles / Unique URL Titles
Posted: 22 August 2007 01:58 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  647
Joined  05-16-2004

So, I have a blog where I reuse the exact same title over and over for each blog post.  When I use the same title, EE appends a number to the end of the url_title so that it’s always unique.  So, my blog posts are always “Overheard” and my url_titles are overheard_167, overheard_221, etc.

But EE has a “safety” check in cp.publish.php that only tries 50 times to get a new URL title when it encounters a repeated title:

// Safety
         
if ($i >= 50)
         
{
            $error[]
= $LANG->line('url_title_not_unique');
            
            break;
         
}

Every time I upgrade I have to change this loop to something like 1000 or 5000 so that I can use the same title more than 50 times.

Any chance that this could be fixed permanently to something larger?  Thanks.

TTFN
Travis

 Signature 

Fight spam better with “Defensio for EE,” a free module


Hop Studios Internet Consulting
http://www.hopstudios.com/

Profile
 
 
Posted: 22 August 2007 02:25 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15869
Joined  06-03-2002

Not really - 50 queries to check for a unique url_title is quite enough to dish out.  You see that it’s running a query for each loop, right?  So if you increase that to 5000 and actually need that many, then every single entry published is running hundreds or even thousands of queries.

A better solution for your unique situation would be a publish form extension that would set the url_title when the form is loaded.  At that stage, you could simply do a query where title = ‘Overheard’ ordered by url title, descending, limit 1.  Add 1 onto whatever number is on the end of the fetched url title, and set it down in the form field so when you submit, it’s already unique.

If you do not have a good way of the publish form knowing when to do this and when not to (for instance if this weblog is used for other things), you could also use the ‘submit_new_entry_start’ hook, and if the submitted title = “Overheard”, do the query dance I mention above, and set $_POST[‘url_title’] directly to the necessary value.

 Signature 
Profile
MSG
 
 
Posted: 22 August 2007 05:29 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  647
Joined  05-16-2004

Sure, or EE could do this natively.  How about something like, if url_title exists, look up all url_titles matching {title}[0-9]+, sort, and add 1 to the [^0-9]+ part.

I guess my point is just that the current method of a 50-times loop isn’t working for me, and that I’d like something that was able to handle my situation.

I should also point out that, even though I’m currently looping about 400 times for each post I publish on this blog, my publishing time is also currently sub-2 seconds; it’s not like this has been a problem for me.

TTFN
Travis

 Signature 

Fight spam better with “Defensio for EE,” a free module


Hop Studios Internet Consulting
http://www.hopstudios.com/

Profile
 
 
Posted: 04 June 2008 04:46 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6617
Joined  04-15-2006
Derek Jones - 22 August 2007 02:25 PM

A better solution for your unique situation would be a publish form extension that would set the url_title when the form is loaded.  At that stage, you could simply do a query where title = ‘Overheard’ ordered by url title, descending, limit 1.  Add 1 onto whatever number is on the end of the fetched url title, and set it down in the form field so when you submit, it’s already unique.

Derek,

Sorry for bringing up such an old post but was just wondering how you would even start going about making an extension like this? Also (I could be wrong on this idea here so please do feel free to tell me if I am as I would like to learn from this one) instead of the query you are mentioning could the extension append say the time in seconds since epoch or something else to the end. I would just be worried that if you had lots of people entering data at the same time then you may get two people submit data at the same time? I know this is probably a very very slim chance but I have seen this happen in other database systems in the past.

Not sure if this would be a problem in this case as I’m not even sure how to do what you are talking about and so perhaps ExpressionEngine has some built in way of locking the entry_id as you write it to the database, I guess it does?

Anyway I was just wondering if you wouldn’t mind perhaps giving a quick tutorial on how to go about doing this as I know it would help a lot of people out and I am pretty certain that I may well find myself in this predicament in the very near future so any help on creating this kind of extension would be great thank you.

I have actually already implemented something on an SAEF which just appends the current time to the URL title so that every single entry is unique but would love to know how you go about doing this in the Control Panel. I do understand extensions to a certain limit and the hooks involved but just not certain how to put it all together.

Also if you think that this thread should be moved to another new thread then please do feel free to do so. It’s a bit of a shame that there isn’t a feature on the forums here like you have when a post is finished with that allows you to start a related post but to be able to start one before the existing one is closed? Perhaps might be a nice addition to these forums? wink

Thanks.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 04 June 2008 04:54 PM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15869
Joined  06-03-2002

2.0 addresses this, but the easier extension would be the other method that I mentioned, an extension that handles it on submit, with the ‘submit_new_entry_start’ hook.  You’d honestly want that check anyway, as there could be situations in multi-author environments, or even of your own accord by opening multiple tabs and keying in entries, that you’d still have a non-unique URL title if you’re only modifying it on the publish page.

 Signature 
Profile
MSG
 
 
Posted: 04 June 2008 05:20 PM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6617
Joined  04-15-2006

Thanks Derek,

So with that hook would it instead not just be easier on the system to append the entry_id of the entry you are about to publish to the end of the url_title instead?

Just really wondering how you go about doing those kinds of extensions as I have never really understood how you get that deep with the hooks and I have always come a cropper in that not knowing enough of what exactly is supposed to be written to do all of these things that I have ended up copying copious amounts of the core code into the extension itself which I would rather not do wherever possible. I have never let any of these extensions out in to the public domain though and they have only ever really been test cases on localhost servers and so I would never really use them in a live install as I would be to scared that something would change with the base code and so the extension would stop working so any lines of a tutorial as to how you would go about this would be greatly appreciated.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 05 June 2008 09:20 AM   [ Ignore ]   [ # 6 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32924
Joined  05-14-2004

I split the coding discussion, you can find the rest here.  Let’s keep this thread on track for the feature request itself. Thanks!

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65102 Total Logged-in Users: 57
Total Topics: 82263 Total Anonymous Users: 22
Total Replies: 442112 Total Guests: 253
Total Posts: 524375    
Members ( View Memberlist )