forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: Fippls on March 28, 2013, 05:06:06 pm

Title: Gallery2 import tool for Coppermine 1.5.x
Post by: Fippls on March 28, 2013, 05:06:06 pm
Hi,

Hope I'm posting this in the correct forum! I recently installed Coppermine 1.5 and wanted to import all my gallery2 items, so tried using the excellent tool posted here:
http://forum.coppermine-gallery.net/index.php/topic,51300.0.html (http://forum.coppermine-gallery.net/index.php/topic,51300.0.html)

It seems that parts of Coppermine have changed so that the tool no longer works. Since I've spent some time fixing it, I thought it would be a good thing to share it with the rest of the world :) This version also copies across the view counts for albums, not just for images.

Instructions:
1. Download the import_gallery2.php script mentioned in the link at start of this post and follow the instructions on where to place it and configuring access to the gallery you're migrating from, but skip the parts about replacing code.

2. Edit import_gallery2.php and locate the following line:
Code: [Select]
$query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} SET title='".addslashes($row[0])."', description='".addslashes($row[1])."'"; and then replace it with this instead:
Code: [Select]
$query = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} SET title='".addslashes($row[0])."', alb_hits='$numAlbumViews', description='".addslashes($row[1])."'";
3. Place this code just above the line you just changed:
Code: [Select]
     # ----------------------------------
     # Gets view counts for albums as well
     $albumViewCountQuery = "SELECT {$cp}viewcount from {$tp}itemattributesmap WHERE {$cp}itemid = '$galAlbum'";
     $albumViewCountResult = mysql_query($albumViewCountQuery);

     if (!mysql_num_rows($albumViewCountResult)) {
        cpg_die(ERROR, "Could not get view counts for selected album <B>$galAlbum</B>");
     }

     $albumViewCountRow = mysql_fetch_array($albumViewCountResult, MYSQL_NUM);
     mysql_free_result($albumViewCountResult);

     $numAlbumViews = $albumViewCountRow[0];

4. Locate this line:
Code: [Select]
$result1 = add_picture ($aid, $albPath."/", $imageFullName, 0, $imageTitle, $imageCaption, $imageKeywords, '', '', '', '', 0, $raw_ip, $hdr_ip, $viewCount); and replace it with this line:
Code: [Select]
$result1 = add_picture ($aid, $albPath."/", $imageFullName, 0, $imageTitle, $imageCaption, $imageKeywords, '', '', '', '', 0, $raw_ip, $hdr_ip, 0, 0, $viewCount);
5. Create a backup of include/picmgmt.inc.php

6. Edit include/picmgmt.inc.php and locate this line:
Code: [Select]
function add_picture($aid, $filepath, $filename, $position = 0, $title = '', $caption = '', $keywords = '', $user1 = '', $user2 = '', $user3 = '', $user4 = '', $category = 0, $raw_ip = '', $hdr_ip = '', $iwidth = 0, $iheight = 0) and replace it with this line:
Code: [Select]
function add_picture($aid, $filepath, $filename, $position = 0, $title = '', $caption = '', $keywords = '', $user1 = '', $user2 = '', $user3 = '', $user4 = '', $category = 0, $raw_ip = '', $hdr_ip = '', $iwidth = 0, $iheight = 0, $hits = 0)
7. Locate this line:
Code: [Select]
$query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, approved, pic_raw_ip, pic_hdr_ip, position, guest_token) VALUES ('{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['approved']}', '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}', '{$CURRENT_PIC_DATA['guest_token']}')"; and replace it with this line:
Code: [Select]
$query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, approved, pic_raw_ip, pic_hdr_ip, position, guest_token, hits) VALUES ('{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['approved']}', '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}', '{$CURRENT_PIC_DATA['guest_token']}', $hits)";Basically, all you're doing here is adding a "hits" parameter to the SQL query.


Hopefully this should work fine! I've tested it on Coppermine 1.5.20 and imported from Gallery 2.3.1.
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: phill104 on March 28, 2013, 06:30:35 pm
Thanks for your excellent contribution. I am sure the community can make good use of this. The script was very popular for cpg1.4
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: google on April 03, 2014, 10:56:27 pm
Hi,

I tried this on 1.5.20 and the gallery version 2.3.1 and 2.3.3 . It didn't work for me. When I say import it just refreshes the page and I see nothing happening.

Also tried on 1.5.28
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: bpiermat on April 03, 2014, 11:34:44 pm
I have the same issue. Waiting for a solution! Please help
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: google on April 04, 2014, 01:52:56 am
OK., I found a round about way. But works.

I installed 1.4.27 version from coppermine repository. You can later update this to latest 1.5.x

and edited the files with mix of information posted here by Fipplis and thread he pointed to.

I have attached files. Update config values in importer file and change extension to .php and place it in coppermine folder and the picmgmt (change extension to php) in include folder.

Let me know if it works for you. I have imported successfully from gallery v2.3.1
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: bpiermat on April 04, 2014, 05:28:14 am
Thanks! How is the best way to downgrade? Upload over the top of 1.5.x?
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: bpiermat on April 04, 2014, 05:32:51 am
I have a clean install, no photos or anything.....yet
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: bpiermat on April 04, 2014, 06:04:28 am
OK I did what you suggested and the database/albums came over. But all the pictures did not transfer. Is there a trick?
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: bpiermat on April 04, 2014, 06:34:55 am
Got it to WORK! I had to change the album directory in the import php file!!
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: google on April 04, 2014, 06:53:07 am
Glad to know it worked  :)
Title: Re: Gallery2 import tool for Coppermine 1.5.x
Post by: f3red on July 22, 2015, 05:32:45 am
What is the current status of this tool?

Thanks,
f3