DELETE FROM oxtplblocks WHERE oxmodule = 'dotvisualcmsextension';

# keep settings from old module
UPDATE
    oxconfig
SET
    oxvarvalue = ENCODE(REPLACE(DECODE(oxvarvalue, 'fq45QS09_fqyx09239QQ'), 's:21:"dotvisualcmsextension"', 's:25:"dotfly/visualcmsextension"'), 'fq45QS09_fqyx09239QQ')
WHERE
    oxvarname IN (
        'aDisabledModules',
        'aLegacyModules',
        'aModuleFiles',
        'aModulePaths',
        'aModules',
        'aModuleControllers',
        'aModuleTemplates',
        'aModuleEvents',
        'aModuleVersions',
        'aModuleExtensions',
        'moduleSmartyPluginDirectories'
    );

# delete old settings
DELETE FROM oxconfig WHERE oxmodule = 'module:dotvisualcmsextension' AND oxvarname IN (
    'dotShowOverview',
    'dotLoadDefaultWidgets',
    'dotAllowResizing',
    'dotAlwaysStretch',
    'dotStretchClass',
    'dotRowWrapperStart',
    'dotRowWrapperEnd'
);

# rename module
UPDATE oxconfig SET oxmodule = 'module:dotfly/visualcmsextension' WHERE oxmodule = 'module:dotvisualcmsextension';

# rename settings
UPDATE oxconfig SET oxvarname = 'dotVisualCmsEnableStart' WHERE oxvarname = 'dotAllowTypeStartReplacement' AND oxmodule = 'module:dotvisualcmsextension';
UPDATE oxconfig SET oxvarname = 'dotVisualCmsEnableCategory' WHERE oxvarname = 'dotAllowTypeCategoryReplacement' AND oxmodule = 'module:dotvisualcmsextension';
UPDATE oxconfig SET oxvarname = 'dotVisualCmsDisableCols' AND oxvarvalue = IF(oxvarvalue <> '', '', 0x07) WHERE oxvarname = 'dotAllowCols' AND oxmodule = 'module:dotvisualcmsextension';
UPDATE oxconfig SET oxvarname = 'dotVisualCmsDisableMeta' AND oxvarvalue = IF(oxvarvalue <> '', '', 0x07) WHERE oxvarname = 'dotAllowTypeMainmenu' AND oxmodule = 'module:dotvisualcmsextension';
UPDATE oxconfig SET oxvarname = 'dotVisualCmsDisableNavi' AND oxvarvalue = IF(oxvarvalue <> '', '', 0x07) WHERE oxvarname = 'dotAllowTypeCategoryDefault' AND oxmodule = 'module:dotvisualcmsextension';

# add new columns
ALTER TABLE `oxcontents`
    ADD COLUMN `DOTPAGETITLE` VARCHAR(255) NOT NULL DEFAULT '' AFTER `OXTIMESTAMP`,
    ADD COLUMN `DOTPAGETITLE_1` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTPAGETITLE`,
    ADD COLUMN `DOTPAGETITLE_2` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTPAGETITLE_1`,
    ADD COLUMN `DOTPAGETITLE_3` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTPAGETITLE_2`,
    ADD COLUMN `DOTNAVIGATIONTITLE` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTPAGETITLE_3`,
    ADD COLUMN `DOTNAVIGATIONTITLE_1` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTNAVIGATIONTITLE`,
    ADD COLUMN `DOTNAVIGATIONTITLE_2` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTNAVIGATIONTITLE_1`,
    ADD COLUMN `DOTNAVIGATIONTITLE_3` VARCHAR(255) NOT NULL DEFAULT '' AFTER `DOTNAVIGATIONTITLE_2`,
    ADD COLUMN `DOTMANUFACTURERID` CHAR(32) NULL DEFAULT NULL COLLATE 'latin1_general_ci' AFTER `DOTNAVIGATIONTITLE_3`;

# set correct type for types in email folder
UPDATE oxcontents SET oxtype = 0 WHERE oxfolder = 'CMSFOLDER_EMAILS';

# set snippet flag according to type
UPDATE oxcontents SET oxsnippet = 0 WHERE oxtype <> 0;
UPDATE oxcontents SET oxsnippet = 1 WHERE oxtype = 0;

# reset folder for special value
UPDATE oxcontents SET oxfolder = '' WHERE oxfolder = 'CMSFOLDER_NONE';

# reset category id for incompatible types
UPDATE oxcontents SET oxcatid = NULL WHERE oxtype NOT IN (2, 5);

# reset manufacturer id for incompatible types
UPDATE oxcontents SET dotmanufacturerid = NULL WHERE oxtype <> 6;

# remove incompatible smarty code
UPDATE oxcontents SET oxcontent = REPLACE(oxcontent, '[{$oViewConf->getCurrentHomeDir()}]', '/');

# deactivate grid for all snippets
UPDATE oxcontents SET ddplaintext = 1 WHERE oxtype = 0;

# delete seo entries for incompatible types
DELETE oxseo FROM oxseo INNER JOIN oxcontents ON oxcontents.oxid = oxseo.oxobjectid WHERE oxseo.oxtype = 'oxcontent' AND oxcontents.oxtype IN (0, 4, 5, 6, 7);
DELETE oxobject2seodata FROM oxobject2seodata INNER JOIN oxcontents ON oxcontents.oxid = oxobject2seodata.oxobjectid WHERE oxcontents.oxtype IN (0, 4, 5, 6, 7);
DELETE oxseohistory FROM oxseohistory INNER JOIN oxcontents ON oxcontents.oxid = oxseohistory.oxobjectid WHERE oxcontents.oxtype IN (0, 4, 5, 6, 7);
