forum.coppermine-gallery.net

Support => cpg1.5 plugins => cpg1.5.x Support => cpg1.5 plugin contributions => Topic started by: gmc on April 18, 2015, 04:26:12 am

Title: Gallery Merge Plugin for CPG 1.5.x
Post by: gmc on April 18, 2015, 04:26:12 am
I can't call this a bouncing baby plugin... at over 6,000 lines of code... and I lost count of the hours...
Actually merging the database records of different galleries into one falls into the category "nearly impossible", as the IDs that are supposed to be unique will exist in both galleries. This is the case for almost all key fields in all database tables - coming up with a converter that will merge two galleries into one has not been accomplished and is very far from trivial.
Merging galleries with only one admin uploader and FTP-upload plus batch-add will be comparatively easy. Merging galleries with a lot of user interaction will be hard to impossible.
...
Joachim
Well - I like a challenge... and I had a need - having merged a few sites each with their own gallery - and wanting to combine them...  I went far beyond what I needed to accomplish my merge in the hopes it will help others do the same... as I have seen a few requests over the years. The merge of both files (if local filesystem) and database (local or remote with proper credentials) is supported.

As stated in the quote above - this is far from trivial - please read the docs... and the messages from the plugin (there is a 'simulate' mode to see what will happen without making any changes that will give you warnings and errors to investigate.)
If you have questions please ask... preferably before you execute the merge.


Of course - PLEASE - backup the TARGET filesystem and database prior to running the actual merge! The SOURCE system is only read from - no changes will be made there. Yes - the script will backup the database tables being changed as well - and offers the ability to restore/backout the database changes - but ultimately the backup responsibility, and ability to recover your gallery remains YOURS.
The plugin makes no attempt to backup the target filesystem - again that responsibility is YOURS. The plugin should only update the albums directory - and based on config settings can add to plugins, languages, and themes directories. I recommend completing the merge on a test copy of your gallery first to verify expected results.


There is full mapping support to maintain relationships between usergroups, users, categories, albums, pictures... including support for userpics - creating the new folder names with correct values.
Favpics entries, picture hits, votes, keywords maintained (merged if duplicates between galleries.)
 
There is support that can be added ('plugins to the plugin') to accommodate 'plugin created tables' leveraging the mapping and capabilities used for core tables (example skeleton and coded script for minicms provided.)

A rather extensive readme file can be viewed at (2 documents also included in the zip file of course...):
http://greggallery.gmcdesign.com/plugins/gallery_merge/readme.php (http://greggallery.gmcdesign.com/plugins/gallery_merge/readme.php) - base plugin
http://greggallery.gmcdesign.com/plugins/gallery_merge/readme_plugin_support.php (http://greggallery.gmcdesign.com/plugins/gallery_merge/readme_plugin_support.php) - the 'plugins to the plugin'
(the readme pages are coded to be displayed in or out of coppermine...)

The results:
Old galleries:
http://greggallery2.gmcdesign.com (http://greggallery2.gmcdesign.com) (a copy pre-merge of the target gallery)
http://bkgallery.gmcdesign.com (http://bkgallery.gmcdesign.com)
http://skygallery.gmcdesign.com (http://skygallery.gmcdesign.com)
New merged gallery:
http://greggallery.gmcdesign.com (http://greggallery.gmcdesign.com)

The only manual tasks I did after the merge:
And of course I have continued to add albums/pictures to the target gallery since completing the merge...

Restrictions:

Disclaimers:

Contributions welcome!
If you assess a plugin for impact to merge processing, let me know... (provide the array statements if you have them) I will include in the next release... (see the plugin readme above) I just couldn't review them all and release this anytime soon...
If you translate the language file, I would also be happy to include in next release. (Debug/diagnostic messages are in English so I can support you - all other informational/warning/error messages are in the language file and can be translated.)

Code is attached below.

Good luck, and let me know what you think...
Thanks!
Greg (gmc on the cpg forum)
Title: Re: Gallery Merge Plugin for CPG 1.5.x
Post by: Phill Luckhurst on April 18, 2015, 11:06:22 pm
Blimey Greg, that is a monster tool. Well done and great work as ever.
Title: Re: Gallery Merge Plugin for CPG 1.5.x
Post by: cmfa on April 19, 2015, 12:41:43 pm
hi greg

Quote
Fatal error: Call-time pass-by-reference has been removed in /homepages/htdocs/home.eu/Coop/plugins/gallery_merge/functions.php on line 2170
Title: Re: Gallery Merge Plugin for CPG 1.5.x
Post by: gmc on April 19, 2015, 01:34:36 pm
Fatal error: Call-time pass-by-reference has been removed in /homepages/htdocs/home.eu/Coop/plugins/gallery_merge/functions.php on line 2170
That one snuck through... Pre PHP5.4 - it is an allowed, though not needed syntax... (and my test site is still at 5.3.x).
I obviously copied the function definition to the call - and didn't remove the & from the 'call by reference'.
in functions.php, change line 2170 from:
Code: [Select]
  gallery_merge_compare_structure($table_constant, $source_table, $target_table, $obsolete_keys, &$skip_keys);
to:
Code: [Select]
  gallery_merge_compare_structure($table_constant, $source_table, $target_table, $obsolete_keys, $skip_keys);
Amazingly in over 6,000 lines - appears this is the only one that slipped through... scanned for ', &', ',&' and '(&' and all remaining are function definition statements...

I'll include in V1.1.
Thanks for letting me know!
Greg