Automattic / Automattic/jetpack

Importing post with galleries doesn't work properly

Open
#22,182 5 comments 0 reactions 0 assignees View on GitHub
[Block] Tiled Gallery [Plugin] Jetpack [Pri] Normal Bug
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impacted plugin

Jetpack

### Steps to Reproduce

Feature "import" doesn't work properly when the imported post has galleries. I expect it to import the galleries and the images and the gallery to keep working, but instead of that when clicking an image in the gallery, another image is loaded.

The galleries were created using Jetpack Galleries

The import tools works ok in terms of actually importing the images to the Media database and showing them in the gallery, but it doesn't replace other fields that referes to the images that are important for the gallery to work properly, so some of the references of the images point to the previous ID (the ID of the image in the previous blog from where the post was imported) instead of the current ID of the image.

It also seems that when the old ID doesn't exist in the current wordpress installation, the image is nevertheless correctly loaded when clicking on it, but if the ID exists, the image associated with that ID is loaded instead.

You can see this in action in this published post:

https://randomtrip.pt/guia-terceira-acores/

The post was imported and translated from https://randomtrip.es/guia-terceira-azores/ . The galleries show the correct pictures, but when clicking on them (when opening the gallery) in some cases the image loaded is completely different from the image in the gallery.

When inspecting the code of the first gallery, we can see that there are several references to randomtrip.es that should've been updated when importing the post, but they are not. Also, the IDs included in the first line (the one that defines the blog) are the IDs of the images in the origin post (the one imported), not on the current one. (red: incorrect references. green: correct references)

![import-galleries-not-working](https://user-images.githubusercontent.com/553835/147490055-9b16cc7b-67e6-4801-9322-4f2c4f36fc64.jpg)

The actual IDs of those images in randomtrip.pt are:

https://randomtrip.pt/wp-content/uploads/2021/12/angra-do-heroismo-prainha-1024x683.jpg => 10771
https://randomtrip.pt/wp-content/uploads/2021/12/angra-do-heroismo-porto-1024x683.jpg => 10772
https://randomtrip.pt/wp-content/uploads/2021/12/angra-do-heroismo-igreja-da-misericordia-1024x683.jpg => 10773
https://randomtrip.pt/wp-content/uploads/2021/12/angra-do-heroismo-vasco-da-gama-1024x683.jpg => 10774

### A clear and concise description of what you expected to happen.

When importing a post with Galleries using the Wordpress Import tool, I expect that:

- A new post is created with the info provided in the XML file
- Referenced images are downloaded and included in the Media library
- Jetpack galleries html code is updated so any reference to each image is updated to point to the local, imported image (not the original one where the post was exported from)
- Jetpack galleries should work once the post is imported

### What actually happened

The import post includes the galleries and imported the images to the Media library, but the Jetpack gallery code references in some of the fields to incorrect data (the ids and URLs of the images in the original exported post instead of the current imported post).

When clicking on an image in the gallery, sometimes an image different from the one in the gallery is loaded.

### Other information

https://videopress.com/v/Hp7TyNyi

### Operating System

macOS

### OS Version

12.0.1

### Browser

Chrome/Chromium

### Browser Version(s)

96.0.4664.110

Contributor guide

Open the contributing guide

Research direction

Start with the WordPress Import tool and the Jetpack gallery HTML in an imported post, comparing the source and current image IDs, URLs, and gallery references. Reproduce the mismatch using the linked example and verify that imported galleries open the same local images shown in the gallery, including when an old ID exists locally.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend, content
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.