Jump to content

Way to UNDO Image File structure in 6.1.8??????


Dirty Butter

Recommended Posts

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by ayz1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by ayz1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...