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 `ei_Page` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'y';
    ALTER TABLE `ei_DraftPage` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'y';
  ELSEIF _isSecure = 'n' THEN
    ALTER TABLE `ei_Page` CHANGE `isSecure` `isSecure` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'n';
    ALTER TABLE `ei_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 `ei_Page` SET `isSecure` = _isSecure;
  UPDATE `ei_DraftPage` SET `isSecure` = _isSecure;
  UPDATE `ei_DPageOption` SET `value` = _isSecure WHERE `name` = 'isSecure';
  UPDATE `ei_PageOption` SET `value` = _isSecure WHERE `name` = 'isSecure';
  UPDATE `ei_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.elementsinc.com', 'https://www.elementsinc.com');
  SET result = REPLACE(result, '{BASE_URL_HTTP}', '{BASE_URL}');
  RETURN result;
END $$$
DELIMITER ;
 
 
UPDATE `ei_HtmlBlockContent`
SET `content` = fixContent(`content`),
    `rawContent` = fixContent(`rawContent`);
  
UPDATE `ei_Settings`
SET `label` = fixContent(`label`),
    `value` = fixContent(`value`);
	
UPDATE `ei_ProductCategory`
SET `productImages` = fixContent(`productImages`),
    `priceList` = fixContent(`priceList`),
	`availableShapes` = fixContent(`availableShapes`),
	`description` = fixContent(`description`),
	`pageContent` = fixContent(`pageContent`);	
	
 
DROP FUNCTION IF EXISTS fixContent;