Skip to content

Commit

Permalink
Merge pull request #2107 from Automattic/fix/single-site-sync
Browse files Browse the repository at this point in the history
fix(dev-env): SQL sync for single sites
  • Loading branch information
sjinks authored Nov 18, 2024
2 parents 84ae76d + f69ccda commit e061ec8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/commands/dev-env-sync-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ export class DevEnvSyncSQLCommand {
return;
}

const prologue = `
DROP PROCEDURE IF EXISTS vip_sync_update_blog_domains;
DELIMITER $$
CREATE PROCEDURE vip_sync_update_blog_domains()
BEGIN
IF EXISTS (SELECT * FROM information_schema.tables WHERE table_schema = 'wordpress' AND table_name = 'wp_blogs') THEN
`;
const epilogue = `
END IF;
END$$
DELIMITER ;
CALL vip_sync_update_blog_domains();
DROP PROCEDURE vip_sync_update_blog_domains;
`;

const queries: string[] = [];
for ( const site of networkSites ) {
if ( ! site?.blogId || ! site?.homeUrl ) {
Expand All @@ -264,12 +279,15 @@ export class DevEnvSyncSQLCommand {
: this.landoDomain;

queries.push(
`UPDATE wp_blogs SET domain = '${ newDomain }' WHERE blog_id = ${ Number( site.blogId ) };`
` UPDATE wp_blogs SET domain = '${ newDomain }' WHERE blog_id = ${ Number(
site.blogId
) };`
);
}

if ( queries.length ) {
await fs.promises.appendFile( this.sqlFile, queries.join( '\n' ) );
const sql = `${ prologue }\n${ queries.join( '\n' ) }\n${ epilogue }`;
await fs.promises.appendFile( this.sqlFile, sql );
}
}

Expand Down

0 comments on commit e061ec8

Please sign in to comment.