7 minutes reading time (1308 words)

Migrating from JoomGallery to Phoca

July-Joomgallery-to-Phoca

The process of migrating a Joomla website can sometimes present non-trivial challenges for users. If your site is built using standard components, the migration process is typically straightforward and even sometimes a child's play.

In such cases, you can create a copy of the website, update it to Joomla version 4 or 5, and then proceed with setting up or designing a new template. Content is usually transferred smoothly in these scenarios.

But what if you need to transfer content of a different type or that is more complex?

For one particular client project, I encountered the challenge of having to migrate a gallery component on a website with Joomla 3.10.12 onboard. The client was using the JoomGallery component specifically. Unfortunately, at the time of this writing, JoomGallery as noted on the official website the Joomla 4 / 5 version is still in the alpha stage and is not recommended for updating on a production website. It is intended for testing purposes only, which is not an ideal scenario for a live, production-ready website. The part of my task was to transfer all categories and photos to PhocaGallery. 

Manual migration from one extension to another

If you try to find a migrator or script for this, you will find that there are not many options, if any. So, I decided to do it manually - after all, we have access to PHPMyadmin, where we can study and compare how everything is organized, and try to write queries ourselves. However, before starting with SQL queries, preliminary actions should be taken in the gallery itself.

On a copy of the site, even before the migration, I updated JoomGallery to version 3.7, and later to the latest alpha version. 

But now I think that was a mistake, because when I installed these new versions, the names of categories and files in the database were changed. Where “_” signs were used - now there is a dash “-”. This later was added to my problems when I found file paths in the content editor, or in the fields tables in database.

Preparation

On the site provided to me for migration, photos were collected from 2017 by different editors who, at the beginning of the site's existence, had no idea how to prepare everything in a logical or organized way. Therefore, I decided to first organize all the categories in JoomGallery, the categories and photos in them, clean up whatever was unnecessary, and distribute them into sub-sections. I decided that it was possible to organize everything by years in chronological order. Newer categories were already placed in subcategories in relation to their parent years. We created missing categories of years and moved the event categories there. After that, we checked how everything looked on the front end.

Once all of this was handled, we could start looking at the data structure and what we needed to get things done:

Identifying the fields

We needed the following fields: id - unique identifier, parent_id - identifier of the parent category, if the category is not root, owner_id - owner identifier, alias, title - category name, userfolder - the folder where photos from this category are located. It is possible that some users may have additional data in other fields, so they need to be matched and added to the query.

xcfy2_phocagallery_categories xcfy2_joomgallery_catg

 
A query to fill the Phocagallery tables with JoomGallery content

Naturally, now we have two galleries on one site - old and new, so tables for both are in the same database. When everything was ready, we started writing the query. We needed to compare tables for categories in both extensions. We used tables xcfy2_joomgallery_catg and xcfy2_joomgallery to insert data into tables xcfy2_phocagallery_categories and xcfy2_phocagallery respectively:

Insert into `xcfy2_phocagallery_categories` (id, parent_id, owner_id, title, alias, published, userfolder) select cid, parent_id, owner, name, alias, published, catpath from `xcfy2_joomgallery_catg`

As a result, 220 rows were added. However, there is a small nuance: JoomGallery starts counting categories from the root category, whereas in Phoca Gallery this is handled differently so I later went through the main categories and removed the parent category, as I only had 7 of them.

Next, we moved all the photos. The query was similar:

Insert into `xcfy2_phocagallery` (id, catid, title, alias, filename, date, published, approved, hits) select id, catid, imgtitle, alias, imgfilename, imgdate, published, approved, hits from `xcfy2_joomgallery`

Correcting the image paths

Now we go to Components -> Phocagallery and check our categories and photos. And here we have another problem - the path to image files does not match. First, we need to physically move (or copy) photos from the folder 'joomgallery/originals' to 'phocagallery' with the hosting’s file manager or via (S)FTP.

Then I had to make a dump of the table 'xcfy2_phocagallery', download it to my computer, and go through all the categories using 'search and replace', replacing the path to the files in each category. As I mentioned earlier, the editors used to do everything without a system, so everything needs to be checked. 

Moving the gallery wasn't the only thing I needed to do. In the content articles, the redactors (content managers) used photos from Joomgallery, and in many of them you can find img tags such as

<img style="display: block; margin-left: auto; margin-right: auto;" src="/images/joomgallery/details/__19/4_03_2021_some_category_fos_183/4_03_21_same_foto_7_20210307_1009651488.jpg" width="700" />

Here we need “find and replace” in database 

SELECT * FROM `xcfy2_content` WHERE `introtext` LIKE '%joomgallery%' and we find some as 

<img style="display: block; margin-left: auto; margin-right: auto;" src="/images/joomgallery/originals/__19/24_12_2021_pasterka_202/erc_2847_20211227_1002682471.jpg">

In many cases I can just replace images/joomgallery/originals to images/phocagallery, but in my case, when i updated Joomgallery to the newest alpha version, I lost the true file path, and needed to verify the correct path. They can be changed from 24_12_2021_someevent_202 to 24-12-2021-someevent_202 for example.

We should also not forget about the images inserted as a link using the Joomgallery plugin in a content editor: 

<a href="joomplu:7037"> <img class="jg_photo" style="display: block; margin-left: auto; margin-right: auto;" src="/index.php?option=com_joomgallery&amp;view=image&amp;format=raw&amp;id=7037&amp;type=orig" alt="joomplu:7037" width="537" height="358" /></a>

We need to find and change it. 

And the next one - we have Joomgallery plugin in articles - {joomplucat:83 limit=46|columns=3} where 83 is a Joomgallery category, we can use a similar plugin from Phocagallery - just install it, and we can use this:

{phocagallery view=category|categoryid=83|limitstart=0|limitcount=0} or
{phocagallery view=category-masonry|categoryid=83|limitstart=0|limitcount=0}. 

A more convenient solution

Now, I think that a more convenient solution is not to use a separate gallery, but to put all the photos in the images/year2024/new-event/ folder for example, and use standard Joomla fields, with which we can display all our photos for the event in the form of a slider, slideshow, or mini-gallery. In this case, we are not tied to a specific component, so the file paths are not changed until we delete them ourselves or change them manually via FTP.

You can designate all articles in which you place such galleries with photos with some tag, for example “photo gallery”, make a menu item for this tag, and make a different layout for such a page so that the article blog looks different. 

P.S. And now there’s a small fly in the ointment in all of this.

After all of that, when I did all this manually, especially changing the paths for all files in the category, colleagues sent me this link https://gist.github.com/sergeytolkachyov/b212276252a92a69a64067bb75eb55d5. This script, according to the author, is for Joomla 4, and it is already two years old. Maybe today, it needs to be improved. But this would probably greatly simplify my transfer task. In reality, there’s not a whole lot of very complicated things here :)

Some articles published on the Joomla Community Magazine represent the personal opinion or experience of the Author on the specific topic and might not be aligned to the official position of the Joomla Project

1
New to the Joomla Community? Join a session to get...
Groundhog Day, but the fun way - Pizza, Bugs, and ...
 

Comments

Already Registered? Login Here
No comments made yet. Be the first to submit a comment

By accepting you will be accessing a service provided by a third-party external to https://magazine.joomla.org/