Dirty Butter Posted May 13, 2017 Share Posted May 13, 2017 There's a new section in maintenance.index.inc.php in a recent 6.1.8 commit (NOT IN 6.1.7) /* Code to break out images from one massive folder into seperate ones $image_path = 'images/source/'; foreach (glob($image_path.'*') as $filename) { if(is_file($filename)) { $base_name = basename($filename); $folder_name = strtoupper(substr($base_name,0,1)); $folder_path = $image_path.$folder_name; if(!file_exists($folder_path)) { mkdir($folder_path); } rename($filename,$folder_path.'/'.$base_name); } } $files = $GLOBALS['db']->select('CubeCart_filemanager', '*'); foreach($files as $file) { $folder = strtoupper(substr($file['filename'], 0, 1)); $GLOBALS['db']->update('CubeCart_filemanager', array('filepath' => $folder.'/'), array('file_id' => $file['file_id'], 'filepath' => null)); } END OF IMAGE FOLDERS CODE */ I've tried, ever since folders could be added to FileManager, to gradually move images over to variously named file folders. I've made a hopeless mess that I just gave up on. I've tested this 6.1.8 commit code as shown to add 0-1,A-Z folder structure to a test site. All I had to do was un-comment it and go to Maintenance. It changes the file structure in FileManager automatically. It works great. BUT it ignores files that are already in folders (which is a good thing if you like your folder structure). If you like your folder structure you probably wouldn't want to enable this section, anyway. I would love to be able to re-engineer this code segment to TAKE ALL IMAGES OUT of existing folders, without losing their product associations. Then I could run it again, as the code stands, and get a nice neat 0-1, A-Z folder structure for all our images. Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted May 14, 2017 Share Posted May 14, 2017 Was there an issue associated with this change as I cannot find one ? @Al Brookbanks would it not be better to offer a method to reorganize based on assigned main category rather than the first letter of the filename of image ? Would seem to make much more sense and be much more useful ? Ian Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 14, 2017 Author Share Posted May 14, 2017 NO - sorry I did not make this clear. It does exactly as intended. But I already had attempted to move images into folders - a tedious one-at-a-time process. If I had started my store after Folders could be assigned, I would be OK. But my folder structure just kind of grew like Topsy, and never was followed through properly for all images. If I used the tool now on plushcatalog I would have the 0-1, A-Z folders PLUS all the folders I named. It would be beyond a mess. I would be glad to use it on my jumble of folders IF I could somehow FIRST take all of them out of the existing folders, keeping all product associations, delete all my then empty folders, and THEN run the tool. However, I DO agree, @havenswift-hosting that using the main Category might be a more logical way to assign the folders. That's basically what I tried to do to begin with, with a few illogical exceptions. But the 0-1, A-Z works pretty well (much better than my attempt). Quote Link to comment Share on other sites More sharing options...
ayz1 Posted May 14, 2017 Share Posted May 14, 2017 If you want to start from scratch you could move all your image files from their folders into the main image folder (you can do this in filemanager moving the whole folder contents at once or ftp them) and then reset the filepath in the filemanager table by running an appropriate query. You could then set up your new folders as you require. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 14, 2017 Author Share Posted May 14, 2017 3 hours ago, ayz1 said: reset the filepath in the filemanager table by running an appropriate query. How to do that? Quote Link to comment Share on other sites More sharing options...
ayz1 Posted May 14, 2017 Share Posted May 14, 2017 UPDATE `cc_CubeCart_filemanager` SET `filepath` = NULL Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 14, 2017 Author Share Posted May 14, 2017 Wouldn't that lose the database connection between which images are shown on specific products? We have something like 6k images with almost 5k listings. Quote Link to comment Share on other sites More sharing options...
ayz1 Posted May 14, 2017 Share Posted May 14, 2017 The file associationis are in the images_index table the filemanager table just tells cubecart where to look for the file. Probably best to test it though on a backup so you can see that it works. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 14, 2017 Author Share Posted May 14, 2017 Using the NULL query did not work the way I had hoped. I still have a conglomeration of naming system folders, and not all my images are now associated with the correct product. Of course this was done on a test site, so no problem. Quote Link to comment Share on other sites More sharing options...
ayz1 Posted May 14, 2017 Share Posted May 14, 2017 (edited) If you have run the query and moved all your image files into the images/source folder from their subfolders then it should work OK. I've tried it and works no problem. Maybe clearing the image cache might be worth doing as well. Edited May 14, 2017 by ayz1 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 14, 2017 Author Share Posted May 14, 2017 Sorry - looks like this isn't a good time for me to work on this - need better mental clarity. You obviously told me what to do, but I missed that part. Run the query. THEN physically move all images to the source folder. Then run the maintenance procedure. Quote Link to comment Share on other sites More sharing options...
ayz1 Posted May 14, 2017 Share Posted May 14, 2017 (edited) 9 minutes ago, Dirty Butter said: THEN physically move all images to the source folder. You can do this reasonably quickly in cPanel filemanager by selecting all the files and then moving all at once, no need to do them one at a time. Edited May 14, 2017 by ayz1 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 15, 2017 Author Share Posted May 15, 2017 I followed the directions correctly this time, and it worked. BUT (probably due to the large number of images involved) there were lots of missing images when all caches were cleared. and products were opened in the browser. This was all done on a test site, so no problem. And of course I had a backup database, so I could revert quickly. Quote Link to comment Share on other sites More sharing options...
ayz1 Posted May 16, 2017 Share Posted May 16, 2017 Have you checked the image file count in the main directory to check that they have all been copied over? On a product where the image doesn't show then check to se if the image is in the folder if not then it hasn't been copied over. As long as the file exists in the source folder and the filepath is set to NULL then it should be visible. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 16, 2017 Author Share Posted May 16, 2017 They did not all copy over. I've already checked. There's no apparent pattern to what worked and what didn't. I'll try again tomorrow with moving files out of one folder. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.