| Felix Laate
                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Monday 26 April 2004 1:07:31 am 
                                                                
                                                                 Hi all! I upgraded a 3.2-4 system to 3.3-4, and all works well except for the fact that all the "old" images are "lost". In the output-xhtml they are reduced to  
<img src= /> . New images can be upload and are displayed as normal. I've searched the fora and documentation, and I found many questions but not the final answer. Is there a solution? Or will I have to re-upload all the images, and edit all the articles? Or even downgrade? Any help is appreciated! Felix Publlic Relations ManagerGreater Stavanger
 www.greaterstavanger.com
 | 
                                                
                                                                                                                                                        
                                                        | Marcus Ilgner
                                                                                                                             | Monday 26 April 2004 3:44:47 am 
                                                                 Hi Felix, 
this is because of the new directory structure in var/<yourdesign>/storage. I wrote this small script (runs on Linux only, I fear, but migration should be fairly easy) to migrate the old structure into the new hierarchy. Take a look at it and maybe comment out copy() and mkdirs() on the first run.Also make sure to run the cleanup script beforehand.
 
#!/usr/bin/php4
<?php
        function mkdirs($mode, $path)
        {
                exec("mkdir -m $mode -p $path");
        }
                                                                                                                            
        $server = "localhost";
        $user = "Exponential"; // put your mysql-user here
        $password = "password"; // put your password here
        $database = "ez"; // put your database name here
        $baseDir = "var/mydesign/storage/"; // change design name here
                                                                                                                            
        //connect
        $connection = mysql_connect( $server, $user, $password, false );
        mysql_select_db( $database );
                                                                                                                            
        //find all ezimage attributes
        $result = mysql_query( "SELECT id, language_code, version, contentobject_id FROM ezcontentobject_attribute WHERE da
                                                                                                                            
        //enumerate all images
        while( ($data = mysql_fetch_assoc( $result )) != false )
        {
                //attribute
                $attribute_id = $data["id"];
                $version_number = $data["version"];
                $language_code = $data[ "language_code" ];
                $object_id = $data["contentobject_id"];
                                                                                                                            
                //old filename
                $subresult = mysql_query( "SELECT filename FROM ezimage WHERE contentobject_attribute_id=$attribute_id AND
                $row = mysql_fetch_row( $subresult );
                $old_filename = $row[0];
                $oldDir = $baseDir . "original/image/" . $old_filename;
                                                                                                                            
                //build new filename
                $subresult = mysql_query( "SELECT path_identification_string FROM ezcontentobject_tree WHERE contentobject_
                $row = mysql_fetch_row( $subresult );
                $path_string = $row[0];
                $newDir = "images/" . $path_string . "/" . $attribute_id . "-" . $version_number . "-" . $language_code;
                                                                                                                            
                printf("Creating dir %s\n", $newDir );
                mkdirs( 0770, $newDir );
                                                                                                                            
                $asPath = explode( "/", $newDir );
                                                                                                                            
                $newFile = $newDir . "/" . $asPath[ count( $asPath ) - 2 ] . "1.jpg";
                                                                                                                            
                //copy file
                copy( $oldDir, $newFile );
                printf( "Copying \"%s\" to \"%s\"\n", $oldDir, $newFile );
        }
                                                                                                                            
        mysql_close( $connection );
?>
After running this script, just clear the cache and visit the site. The database should then get updated automagically. 
GreetingsMarcus
 |