Not signed in (Sign In)

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorfanz
    • CommentTimeJul 28th 2009 edited
     
    Hi!

    I've seen some old similar topics but couldn't find a solution.

    When I uploaded my files I all named them using underscores for the spaces. Now I understood later that this wasn't a good idea and that I should use hyphens instead (for more search engine-friendly URLs).

    So I'd like to replace all underscores with hyphens, but hopefully without losing all my descriptions! Would there be any way to achieve this? Or will I be forced to delete them all, re-upload them and write all my captions and descriptions again?

    Thanks so much!
    • CommentAuthorfanz
    • CommentTimeJul 29th 2009
     
    Would anybody know a solution? Or let me know as well if there is no solution... Then I will start doing it manually! (but I really hope I won't have to do that as it would take hours!).
    • CommentAuthorchewbears
    • CommentTimeJul 29th 2009
     
    I am no pro at this but here is what I would do.

    In your mysql you should get out a csv file/table of all of your descriptions. Then you import the photos named correctly, and then upload the csv file for descriptions for the new photos. Then once you know it works just delete the originals. Reuploading the images shouldn't take hours. Or you could just copy paste the properly named images to your image directory and then just rename the paths in the mysql table to match the new photonames. Again you could import a proper csv table for the paths so you don't have to type them in.
    Thankful People: fanz
    •  
      CommentAuthorsidtheduck
    • CommentTimeJul 30th 2009 edited
     
    fanz,

    You could also create a new file called 'rename.php' or something, upload it to your Plogger root directory (where plog-config.php is located) and have it run the following code:

    Version beta3:
    <?php
    include(dirname(__FILE__).'/gallery.php');
    $query = "SELECT * FROM `plogger_pictures` WHERE 1";
    $result = run_query($query);
    while ($row = mysql_fetch_assoc($result)) {
    $old_path = $row['path'];
    $basename = basename($row['path']);
    $path = dirname($row['path']).'/';
    $new_path = $path.str_replace('_', '-', $basename);
    if ($new_path != $old_path) {
    $move = @rename(PLOGGER_DIR.'images/'.$old_path, PLOGGER_DIR.'images/'.$new_path);
    if (!$move) {
    echo "\n".'<li>Error renaming filename from <strong>'.basename($old_path).'</strong> to <strong>'.basename($new_path).'</strong></li>';
    } else {
    $sql = "UPDATE `plogger_pictures` SET `path` = '".mysql_real_escape_string($new_path)."' WHERE `id` = ".$row['id'];
    $sql_result = run_query($sql);
    if (!$sql_result) {
    echo "\n".'<li>Error updating filename in database for <strong>'.basename($old_path).'</strong></li>';
    } else {
    echo "\n".'<li>Updated filename to <strong>'.basename($new_path).'</strong></li>';
    }
    }
    }
    }
    echo "\n".'<br />Done!';
    ?>


    SVN Version > rev550:
    <?php
    include(dirname(__FILE__).'/gallery.php');
    $query = "SELECT * FROM `plogger_pictures` WHERE 1";
    $result = run_query($query);
    while ($row = mysql_fetch_assoc($result)) {
    $old_path = $row['path'];
    $basename = basename($row['path']);
    $path = dirname($row['path']).'/';
    $new_path = $path.str_replace('_', '-', $basename);
    if ($new_path != $old_path) {
    $move = @rename(PLOGGER_DIR.'plog-content/images/'.$old_path, PLOGGER_DIR.'plog-content/images/'.$new_path);
    if (!$move) {
    echo "\n".'<li>Error renaming filename from <strong>'.basename($old_path).'</strong> to <strong>'.basename($new_path).'</strong></li>';
    } else {
    $sql = "UPDATE `plogger_pictures` SET `path` = '".mysql_real_escape_string($new_path)."' WHERE `id` = ".$row['id'];
    $sql_result = run_query($sql);
    if (!$sql_result) {
    echo "\n".'<li>Error updating filename in database for <strong>'.basename($old_path).'</strong></li>';
    } else {
    echo "\n".'<li>Updated filename to <strong>'.basename($new_path).'</strong></li>';
    }
    }
    }
    }
    echo "\n".'<br />Done!';
    ?>


    I have not tested it just yet, so use at your own risk. I just modified it from another post. It should work, but if you want to wait, I can test it in the morning.
    Thankful People: fanz
    • CommentAuthorfanz
    • CommentTimeJul 30th 2009 edited
     
    Wow thanks so much chewbears and sidtheduck for your help. Sidtheduck, your solution looks easier to implement, so I took the risk and gave it a try but it didn't work.

    I'm getting these errors for all pictures:

    Notice: Undefined variable: basename in /home/picturh8/public_html/travel/rename.php on line 7
    Error renaming filename from young_carriage_driver_cows.jpg to

    Notice: Undefined variable: basename in /home/picturh8/public_html/travel/rename.php on line 7
    Error renaming filename from wooden_bridge_grand_tsingy.jpg to

    ...

    I use the lastest SVN so I tried the second version of the code. Also worth noting is that I don't have the collection name in URLs but I don't think that should make a difference.

    If you need to have a look here is my gallery: http://picturesfromearth.com/travel/

    Thanks again!
    •  
      CommentAuthorsidtheduck
    • CommentTimeJul 30th 2009
     
    fanz,

    Sorry about that. I figured I would miss a variable change. :P

    I edited my post above that should clear up the variable and rename the files now.
    • CommentAuthorfanz
    • CommentTimeJul 30th 2009
     
    Hum still not working, I get this error now for all pictures:

    Notice: Undefined variable: old_name in /home/picturh8/public_html/travel/rename.php on line 7
    Error renaming filename from young_carriage_driver_cows.jpg to

    ...

    I prefer not to make changes myself because I don't understand exactly how this code should work...
    •  
      CommentAuthorsidtheduck
    • CommentTimeJul 30th 2009 edited
     
    Hi fanz,

    You visited just as I was making another edit. The final code above is now updated and has been tested on my server. Hope it works for you now!
    Thankful People: fanz
    • CommentAuthorfanz
    • CommentTimeJul 30th 2009
     
    It worked, thanks a lot this is really super helpful!