ZenphotoCMS Forum
Perl script to Import Menalto Gallery 2 Image Descriptions - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: Perl script to Import Menalto Gallery 2 Image Descriptions (/thread-2365.html)



Perl script to Import Menalto Gallery 2 Image Descriptions - Anudu - 2008-03-08

First of all: thankyou for zenphoto! It's quick, it's uncomplicated and it does it's job! Don't add too much extras and I luv you forever.

I had gallery2 running and it was a pain. Much too huge and hard to understand, when you needed to tweak it.

I wrote this perl script to import the image description from within gallery. Use at your own risk and only, if you know what you're doing:

---snip---
#!/usr/bin/perl
##############################################################################
use DBI();
$user = "xxx";
$password = "xxx";
$dbh = DBI->connect("DBI:mysql:database=xxx;host=localhost", "$user", "$password",
{'RaiseError' => 1});
$counter = 0;
%UMLAUTE = ( 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue','ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss');
@UMLKEYS = join("|", keys(%UMLAUTE));

$cursor = $dbh->prepare("select gallery2_FileSystemEntity.g_id, gallery2_FileSystemEntity.g_pathComponent, gallery2_Item.g_description from
gallery2_FileSystemEntity, gallery2_Item where gallery2_FileSystemEntity.g_id = gallery2_Item.g_id;") || die "Prepare schiefgegangen ($DBI::errstr)";

$cursor->execute() || die "Query schiefgegangen ($DBI::errstr)";
while(defined(my $row = $cursor->fetch))
{
$id = $row->[0];
$datei = $row->[1];
$besch = $row->[2];

$besch =~ s/(@UMLKEYS)/$UMLAUTE{$1}/g;
$besch = $dbh->quote($besch);
$datei = $dbh->quote($datei);

my $statement = "UPDATE zen_images SET title = $besch WHERE filename = $datei";

$dbh->do("$statement");

$counter++;
print "$counter: $datei --- $besch\n";

select(undef, undef, undef, 0.2); ## wait 200 ms for the database
}}
}
exit(0);
---snap---

It's intended to run in the shell, so don't try to call it from a browser. And check, if the queries work with your database, before you try.

Might help someone get rid of Gallery2! Smile


Perl script to Import Menalto Gallery 2 Image Descriptions - acrylian - 2008-03-08

I will add a link to this thread on our extensions page.


Perl script to Import Menalto Gallery 2 Image Descriptions - Megan - 2008-08-10

Just a few tips if you're using this:

- make sure to check the prefixes on the Gallery and Zenphoto tables. Mine are g2_ and zp_, not gallery2_ and zen_

This script assumes that you're putting zenphoto in the same database as Gallery. If yours is in a different database, simply define a second database conection and send the update statement to the new database:

`

$dbh2 = DBI->connect("DBI:mysql:database=xxxx;host=localhost", "$user", "$password",{'RaiseError' => 1});

my $statement = "UPDATE zp_images SET title = $besch WHERE filename = $datei";

$dbh2->do("$statement");

`

My databases both use the same usernames and passwords. if yours are different you'd need to define new variables for those as well.


Perl script to Import Menalto Gallery 2 Image Descriptions - efurban - 2008-08-10

inspired by this tool, I have wrote the migrator for gallery2 to zenphoto. http://apps.ouwu.com/confluence/display/pb/Gallery2+to+ZenPhoto+Migrator


Perl script to Import Menalto Gallery 2 Image Descriptions - Megan - 2008-08-17

That migrator didn't work for me - the image descriptions didn't copy over.

After running it I realized that the perl script above didn't work either. My husband ended up writing a sql statement that works:

`

UPDATE *zendatabase*.zp_images im

INNER JOIN *gallerydatabase*.g2_FileSystemEntity fse ON im.filename=fse.g_pathComponent

INNER JOIN *gallerydatabase*.g2_Item item ON fse.g_id=item.g_id

INNER JOIN *gallerydatabase*.g2_ChildEntity ce ON item.g_id=ce.g_id

INNER JOIN *zendatabase*.``zp_albums` zp_albums ON im.albumid=zp_albums.id
INNER JOIN (SELECT g_id, REPLACE(REPLACE(g_title, '"', '"'), '&', '&') galltit FROM *gallerydatabase*.g2_Item WHERE g_canContainChildren=1) AS g_album ON ce.g_parentId=g_album.g_id
SET im.`desc` = item.g_summary
WHERE g_album.galltit=zp_albums.title

Replace the *gallerydatabase* and *zendatabase* with the correct database names. ALso check the table prefixes and change them to match yours.


Perl script to Import Menalto Gallery 2 Image Descriptions - efurban - 2008-08-19

Megan, could you please send me the log file or output of the Migrator? The tool worked for me so I wanna find out why it didn't work for you. hopefully this eventually will become a useful tool for everyone else.


Perl script to Import Menalto Gallery 2 Image Descriptions - krainbolt - 2008-08-19

efurban, on your site under "Features" you state:

"migrate photos: titles only (since I don't have descriptions for photos in Gallery2)"

Wouldn't this likely be the reason image descriptions aren't converting over?


Perl script to Import Menalto Gallery 2 Image Descriptions - dbogen - 2012-05-08

Went through this process recently. After Googling around for a solution, I mashed together several partial solutions and came up with a Frankenstein script that does most of the heavy lifting for you. The script is posted on my website at http://www.bogen.org/2012/05/07/gallery2-to-zenphoto-migration/


Perl script to Import Menalto Gallery 2 Image Descriptions - acrylian - 2012-05-08

Ok, we will put an entry for this on the extensions section, too.


Perl script to Import Menalto Gallery 2 Image Descriptions - acrylian - 2012-05-08

Great, I have put an entry on our extensions section:
http://www.zenphoto.org/news/gallery2-to-zenphoto-migration

If we may ask why did you choose Zenphoto against for example the newer Gallery3?