-- Copy global articles to new markets

INSERT INTO article_content (
    article_id,
    title,
    preamble,
    body,
    body_saved,
    meta_title,
    meta_description,
    slug,
    market_locale_id
)
SELECT article_id,
       title,
       preamble,
       body,
       now(),
       meta_title,
       meta_description,
       REGEXP_REPLACE(slug, '^/int/', m.market_name),
       m.market_locale_id
  FROM article_content ac
  CROSS JOIN (
            SELECT 23 AS market_locale_id, '/ie/' AS market_name
            UNION
            SELECT 24, '/sg/'
            UNION
            SELECT 25, '/au/'
        ) m
 WHERE ac.market_locale_id = 6;

-- Replace URLs
UPDATE article_content
   SET body = regexp_replace(body, 'www.photowall.global/', 'www.photowall.com/ie/', 'g')
 WHERE market_locale_id = 23;

UPDATE article_content
   SET body = regexp_replace(body, 'www.photowall.global/', 'www.photowall.com/sg/', 'g')
 WHERE market_locale_id = 24;

UPDATE article_content
   SET body = regexp_replace(body, 'www.photowall.global/', 'www.photowall.com/au/', 'g')
 WHERE market_locale_id = 25;

UPDATE article_content
   SET body = regexp_replace(body, '\.\./\.\./\.\./int', 'https://www.photowall.com/ie', 'g')
 WHERE market_locale_id = 23;

UPDATE article_content
   SET body = regexp_replace(body, '\.\./\.\./\.\./int', 'https://www.photowall.com/sg', 'g')
 WHERE market_locale_id = 24;

UPDATE article_content
   SET body = regexp_replace(body, '\.\./\.\./\.\./int', 'https://www.photowall.com/au', 'g')
 WHERE market_locale_id = 25;
