Jump to content

Adding images - Update File List


bobdonkey

Recommended Posts

Hi all!

I have a question about the images and filemanager.

I have a routine that downloads images via FTP, and puts them all into folders in the /images/source folder. It then adds all the image IDs to the products using some joins. This all works fine.

However, when new images are added. they do not appear in the filemanager table, and consequently I cannot assign them to products, until I go into the admin site and click on 'Update file list'. This is not ideal, because it means I have to do something, and of course I want to do as little as possible! New products will be missing images until this is done.

So, my questions are:

1. Is the filemanager updated automatically according to some schedule?

2. How can I run it from my php scripts once images are downloaded?

Thanks

Link to comment
Share on other sites

1. No. Unfortunately, CubeCart is not yet coded (I believe) to properly database images that were bulk uploaded via FTP, either manually or by a time schedule.

2. Do Not Do This! The FileManager has a function to rebuild the file list (admin, Images, Update File List tab). Executing this function will, indeed, load all found images into the FileManager database. However, that process also renumbers the file id of the image records in the database - the consequence being that all associations between product and images have been destroyed.

Link to comment
Share on other sites

Hi bsmither

Thanks. I need to be able to do this, because when new images are added automatically (and I have several thousand organised in folders) I need them to show up on products in the inventory, again automatically. So, occasionally, say once a week, I will need to update filemanager and image_index in case new images have been imported.

What I already do is populate the image_index table based on the file_ids in the filemanager. So it wouldn't matter if the file_ids changed, if it wasn't for the fact that I am actually doing an update on duplicate values based on a unique index created from product_id and file_id in the image index. So I may end up with 2 images if I click on the button again...I need to test this. I could truncate the whole image_index first, but this means that I couldn't add any products manually using admin as they would be wiped out, and I want to be able to do this.

So not sure what my next move is here...maybe I can manually populate the filemanager as well, only adding new rows rather than truncating the table? And never use the Update File List button.

Incidentally, since file_id in filemanager is AUTO INCREMENT, how is it being wiped? I guess the routine is truncating the table, rather than doing an update?

 

Link to comment
Share on other sites

So I am not seeing any issues with this function. I tried the following:

- Adding a new image by uploading one, doing a rebuild
- Adding a new image directly into the source folder, and doing a rebuild

In both these cases, the new images are added to the end of the table, i.e. have the last file_ids. My products all look fine, both automatically and manually added.
This would seem to indicate that it is not doing a rebuild, it is just finding new files and doing an update. I don't see the file_ids change.

Also what I don't understand is, why would the rebuild truncate the entire table and set all new ids? This would cause the image_index folder to be wrong, and then all products would have the wrong image. How would it know how to then populate the image_index table again? This doesn't make sense to me.

Incidentally, from a UI perspective, it is a bit odd to have a tab that is actually a button in disguise, especially if it can cause issues with no warning!

Link to comment
Share on other sites

I've been looking over the code and cannot see the problem that I traced out earlier. I know the problem is there.

"Why would the rebuild truncate the entire table and set all new ids?"

One can look at the term "rebuild" in its most draconian aspect. I have no answer for why rebuild did/does what it did/does other than mention another term, "bug". In MySQL, deleting all the records is almost the same as truncating the table. In MySQL, the TRUNCATE command requires the user have DROP privileges. Maybe because MySQL makes a temporary table with the same schema as the target table, but with no records carried over. It then drops the target table and renames the temporary table. Perhaps part of the schema copied is the last-used auto-increment value.

"This would cause the image_index folder to be wrong, and then all products would have the wrong image. How would it know how to then populate the image_index table again?"

Exactly. That's what I traced out. Products wouldn't have the wrong image, they would have no image because the id's of rebuilt records would be in entirely new range of values.

 

"It is a bit odd to have a tab that is actually a button in disguise."

You will find that in many places in the admin. The tab is there, looking like a tab, because the intent of the tab is within functional scope of the navigation subject.

 

Link to comment
Share on other sites

Did some more tests last night, added several images manually and updated the file list. Still had no issues with file_ids being changed. The new images (whih are in folders among other existing images) are added to the end of the table. So it is not rebuilding the whole thing for me.

If this ever happens, what I will have to do is truncate the whole image_index table, and then my import script will rebuild it, since my products all have a image file name associated, so I can use a join to populate the image_index. But I would loose any images I had added manually, and would have to redo all of those again, which would be a massive hassle.

Link to comment
Share on other sites

  • 8 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...