Skip to content

Fix replacing site url in DB after pulling site - #992

Merged
nightnei merged 1 commit into
trunkfrom
fix/replacingSiteUrlAfterPullingIt
Mar 7, 2025
Merged

Fix replacing site url in DB after pulling site#992
nightnei merged 1 commit into
trunkfrom
fix/replacingSiteUrlAfterPullingIt

Conversation

@nightnei

@nightnei nightnei commented Feb 28, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

When user pull or puh a site to/from Studio - all links should reflect the actual domain, all of them should be localhost:<port> if it was pulling to Studio or actual domain on dotcom if it was pushing.
This PR handles improving pulling process. We had it before, but I found not covered cases, so this PR fixes them
Regarding pushing - we don't handle it at all. I was thinking about it end ended up that it's better to do it in VaultPress side (details - p1740755830254999-slack-C07Q6R5HW3T).

Examples of issues covered in this PR:
Screenshot 2025-02-28 at 15 05 15
Screenshot 2025-02-28 at 15 07 47

Testing Instructions

  1. Create a site in wp.com
  2. Create a post with video and add poster to this video
  3. Install Elementor plugin
  4. Create a post with the help of Elementor, add video and poster to it
  5. Open Studio -> Create a new site -> Pull site from wp.com, created in the 1-st step of this instructions
  6. Open local site
  7. Assert that posters mentioned on screenshots in "Proposed Changes" have the correct localhost domain
@nightnei
nightnei requested a review from a team February 28, 2025 15:47
@nightnei nightnei changed the title fix(sync): replacing site url in DB after pulling it Feb 28, 2025
@nightnei
nightnei marked this pull request as ready for review February 28, 2025 15:47
@nightnei
nightnei force-pushed the fix/replacingSiteUrlAfterPullingIt branch from 86c76a5 to a7f5443 Compare March 4, 2025 10:14
return;
}

console.groupCollapsed( 'Sync Pull' );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to clean up the logging, could you consider opening a separate PR for that?

Comment thread src/hooks/sync-sites/use-sync-pull.ts Outdated
if ( userChoice === 1 ) {
console.log( 'User cancelled pull operation' );
const isCanceledByUser = userChoice === 1;
if ( isCanceledByUser ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this variable if it's used only once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to avoid "magic" number 1, since at a glance I thought that 1 means kinda true, as a confirmation to continue pulling, but actually it's canceling.

So to keep readability, we need either to add comment about 1 or create readable and simple variable. And the good variable name is much better than any comment.

Comment thread src/hooks/sync-sites/use-sync-pull.ts Outdated
const downloadUrl = hasBackupCompleted ? response.download_url : null;

if ( hasBackupCompleted && downloadUrl ) {
if ( downloadUrl ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the context of this removal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above line has const downloadUrl = hasBackupCompleted ? response.download_url : null; - downloadUrl is available only if hasBackupCompleted is true. So it's duplication of the condition.

const urlWithoutProtocol = oldUrl.replace( /^https?:\/\//, '' );

const oldUrlVariants = [ `http://${ urlWithoutProtocol }`, `https://${ urlWithoutProtocol }` ];
const oldUrlVariants = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct, nice catch.

@wojtekn

wojtekn commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

@nightnei, it worked as expected for me - IMG had a local URL after the pull.

However, I couldn't make the video load from wp-admin, and it always had the videopress URL. How could I test this part?

@nightnei

nightnei commented Mar 4, 2025

Copy link
Copy Markdown
Contributor Author

However, I couldn't make the video load from wp-admin, and it always had the videopress URL. How could I test this part?

@wojtekn hm, maybe it's the same case as my assumption here? p1741020425670679/1740755830.254999-slack-C07Q6R5HW3T

Could you please check and ensure that you are adding a newly uploaded image as a poster, instead of some image in your library. If it's not the case, then I will think more to try to understand why it works for you differently. Or, as an option, could you please share that website with me (nei.css@gmail.com) with Admin access and I will take a look.

@nightnei
nightnei force-pushed the fix/replacingSiteUrlAfterPullingIt branch from a7f5443 to adc57cb Compare March 4, 2025 15:03
@nightnei

nightnei commented Mar 4, 2025

Copy link
Copy Markdown
Contributor Author

@wojtekn I revert changes for console.logs etc, I will create separate PR for them, but anyway could you please take a look at my answers regarding your feedback.
UPDATE: Hovewer up to you, if you prefer to comment these lines in that separate PR then I totally don't mind :)

@wojtekn

wojtekn commented Mar 5, 2025

Copy link
Copy Markdown
Contributor

Could you please check and ensure that you are adding a newly uploaded image as a poster, instead of some image in your library.

Could you show a screenshot that illustrates what is a poster in Elementor?

@wojtekn

wojtekn commented Mar 7, 2025

Copy link
Copy Markdown
Contributor

@nightnei I've reproduced the case with the video's poster URL not being replaced and confirmed that PR fixes the issue.

@nightnei
nightnei merged commit 1666433 into trunk Mar 7, 2025
@nightnei
nightnei deleted the fix/replacingSiteUrlAfterPullingIt branch March 7, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants