We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Reusing old file upload location IDs

How Do I?

Rick Lecoat's avatar
Rick Lecoat
128 posts
10 years ago
Rick Lecoat's avatar Rick Lecoat

I typically create a new file upload location thusly:

  1. Create the folder on the server and assign it the correct (777) permissions;
  2. Specify the name, ID and location in my Master config file;
  3. Go to ‘Create new upload destination’ in the CP, enter any old nonsense in the ‘Descriptive name’ field, and click ‘Submit’.

The location is created and defined with the correct paths and name as specified in the master config file. Easy. My code in the master config looks like this:

1 => array(
    'name'        => "Article images",
    'server_path' => $base_path . "/library/user_content/article_images/",
    'url'         => $base_url . "/library/user_content/article_images/"
)

Now, if I want to delete the location, I simply delete it from the list in the CP, delete the folder from the server and delete the relevant lines of code in the Master config file. That’s fine.

But say I delete the location with an ID of 5; I then create a new location, and I’d quite like to reuse that ID 5 for the new location. It’s not being used any more, after all. But there seems no way to get EE to allow me to reuse the ID 5, even if I specify the that ID in the master config. It seems that once an ID has been allocated it can never be unallocated or reallocated, even if the original has been deleted. Currently, after creating and deleting a few different upload destinations, I have five destinations with IDs 1, 2, 3, 8 & 9. IDs 4-7 apparently cannot be re-used, even though they no longer have a destination associated with them. And, having created (and subsequently deleted) a couple more destinations in the process of testing prior to posting this, IDs 10 and 11 are now used up too.

I know it doesn’t really matter what ID something has, but it does make the code look a bit gappy and untidy.

So: am I missing something? Is there a way to get EE to ‘forget’ that an ID was once used now that it’s no longer so?

       
Giraffentoast's avatar
Giraffentoast
152 posts
10 years ago
Giraffentoast's avatar Giraffentoast

I’ve never used that ‘master config file’, but what you describe sounds like standard (mysql) database behaviour. When rows are deleted from a table (say: table “upload locations”), their IDs are not reused.

Say you got IDs 1 2 3 4 5 and ID 4 is deleted. The next insert will create ID 6, not 4, and you’ll be at 1 2 3 _ 5 6.

The only sane way to reset the inner database counter (iterator), is to truncate (empty) the table afaik. Or you could set the counter manually of course – which doesnt make sense because you’d need to set it to 4, insert a row, then set it to 6 or 7 to avoid a collision with existing ID 5.

Leave it as it is, it’s meant to be like that. 😉

       
Rick Lecoat's avatar
Rick Lecoat
128 posts
10 years ago
Rick Lecoat's avatar Rick Lecoat

Good enough. Thanks.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.