-- Copy magazine articles to Estonia and Luxembourg

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/', '/ee/'),
      (select id from market_locales where name = 'Estonia (English)' limit 1)
FROM article_content ac
WHERE ac.market_locale_id = (select id from market_locales where name = 'International' limit 1);

-- Replace URLs
UPDATE article_content
   SET body = regexp_replace(body, 'www.photowall.global/', 'www.photowall.com/ee/', 'g')
 WHERE market_locale_id = (select id from market_locales where name = 'Estonia (English)');

UPDATE article_content
   SET body = regexp_replace(body, '\.\./\.\./\.\./int', 'https://www.photowall.com/ee', 'g')
WHERE market_locale_id = (select id from market_locales where name = 'Estonia (English)');


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, '^/ca-fr/', '/lu-fr/'),
	(select id from market_locales where name = 'Luxembourg (French)' limit 1)
FROM article_content ac
WHERE ac.market_locale_id = (select id from market_locales where name = 'Canada (French)' limit 1);


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, '^/', '/lu-de/'),
	(select id from market_locales where name = 'Luxembourg (German)' limit 1)
FROM article_content ac
WHERE ac.market_locale_id = (select id from market_locales where name = 'Germany' limit 1);


UPDATE article_content SET body = REGEXP_REPLACE(body, 'www.photowall.de', 'www.photowall.com/lu-de', 'g')
	WHERE market_locale_id = (select id from market_locales where name = 'Luxembourg (German)' limit 1);

UPDATE article_content SET body = REGEXP_REPLACE(body, 'www.photowall.com/ca-fr', 'www.photowall.com/lu-fr', 'g')
	WHERE market_locale_id = (select id from market_locales where name = 'Luxembourg (French)' limit 1);

UPDATE article_content SET body = regexp_replace(body, '\.\./\.\./\.\./ca-fr', 'https://www.photowall.com/lu-fr', 'g')
	WHERE market_locale_id = (select id from market_locales where name = 'Luxembourg (French)' limit 1);

UPDATE article_content SET body = regexp_replace(body, '\.\./\.\./\.\.', 'https://www.photowall.com/lu-de', 'g')
	WHERE market_locale_id = (select id from market_locales where name = 'Luxembourg (German)' limit 1);

