DROP PROCEDURE IF EXISTS makeSecure;

DELIMITER $$$
CREATE PROCEDURE makeSecure(_isSecure ENUM('y', 'n'))
NOT deterministic MODIFIES SQL DATA
  BEGIN

    IF _isSecure = 'y' THEN
      ALTER TABLE `pl_Page` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'y';
      ALTER TABLE `pl_DraftPage` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'y';
    ELSEIF _isSecure = 'n' THEN
      ALTER TABLE `pl_Page` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'n';
      ALTER TABLE `pl_DraftPage` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'n';
    ELSE
      SIGNAL SQLSTATE
      'ERR0R'
      SET
      MESSAGE_TEXT = "Incorrect isSecure argument. Use CALL makeSecure('y') or CALL makeSecure('n')",
      MYSQL_ERRNO = 1;
    END IF;

    UPDATE `pl_DPageOption` SET `value` = _isSecure WHERE `name` = 'isSecure';

    UPDATE `pl_Page` SET `isSecure` = _isSecure;
    UPDATE `pl_PageOption` SET `value` = _isSecure WHERE `name` = 'isSecure';

    UPDATE `pl_DraftPage` SET `isSecure` = _isSecure;
    UPDATE `pl_DraftPageOption` SET `value` = _isSecure WHERE `name` = 'isSecure';
  END $$$
DELIMITER ;

CALL makeSecure('y');
DROP PROCEDURE IF EXISTS makeSecure;

--
--


DROP FUNCTION IF EXISTS fixContent;
DELIMITER $$$
CREATE FUNCTION fixContent(_content LONGTEXT)
  RETURNS LONGTEXT
  BEGIN
    DECLARE RESULT LONGTEXT;
    SET RESULT = REPLACE(_content, 'http://www.pageantlife.com', 'https://www.pageantlife.com');
    SET RESULT = REPLACE(_content, 'http://pageantlife.com', 'https://www.pageantlife.com');
    SET RESULT = REPLACE(RESULT, '{BASE_URL_HTTP}', '{BASE_URL}');
    RETURN RESULT;
  END $$$
DELIMITER ;


UPDATE `pl_HtmlBlockContent`
SET `content` = fixContent(`content`),
  `rawContent` = fixContent(`rawContent`);

UPDATE `pl_DraftHtmlBlockContent`
SET `content` = fixContent(`content`),
  `rawContent` = fixContent(`rawContent`);

UPDATE `pl_Settings`
SET `label` = fixContent(`label`),
  `value` = fixContent(`value`);

UPDATE `pl_GridBlockItem`
SET `content` = fixContent(`content`),
  `url` = fixContent(`url`),
  `video` = fixContent(`video`);

DROP FUNCTION IF EXISTS fixContent;
