Skip to content

Instantly share code, notes, and snippets.

@slackero
Last active January 24, 2017 14:24
Show Gist options
  • Save slackero/b1315acfcced7d7e921676b392750f4d to your computer and use it in GitHub Desktop.
Save slackero/b1315acfcced7d7e921676b392750f4d to your computer and use it in GitHub Desktop.
Duplicate existing OXID theme settings for another theme of your choice.
<?php
/**
* $Id$
*
* Duplicate Theme settings for another Theme
* Script is a just a quick fix for current Oxid versions (4.10.0 tested)
* and based on the script of forum member "stefan2"
* http://forum.oxid-esales.com/showthread.php?t=9393&page=2#post55919
*
*/
// Change setting
$scriptConfig = (object) array(
'from' => 'flow', // Source theme
'to' => 'mytheme', // Target theme
'dump' => true, // Debug, no changes if true
);
require_once dirname(__FILE__) . "/bootstrap.php";
require_once getShopBasePath() . 'core/oxfunctions.php';
$shopConfig = oxRegistry::getConfig();
$oDb = oxDb::getDb(true);
$sShopId = $shopConfig->getBaseShopId();
// Have you changed the key?
// 4.9.9 default decode key: fq45QS09_fqyx09239QQ
// 4.10.0 default decode key: fq45QS09_fqyx09239QQ
$sConfigKey = $shopConfig->getConfigParam('sConfigKey');
exit('Backup done? Config adapted? Unncomment this line: ' . __LINE__. ' (Shop-ID: ' . $sShopId . ', Decode-Key: ' . $sConfigKey . ')');
$sSql = "
SELECT
`cfg`.`oxid` AS `id`,
`cfg`.`oxmodule` AS `theme`,
`cfg`.`oxvarname` AS `name`,
`cfg`.`oxvartype` AS `type`,
DECODE( `cfg`.`oxvarvalue`, " . $oDb->quote( $sConfigKey ) . ") AS `value`,
`cfgd`.`oxgrouping` AS `group`,
`cfgd`.`oxvarconstraint` AS `constraint`,
`cfgd`.`oxpos` AS `pos`
FROM
`oxconfig` AS `cfg`,
`oxconfigdisplay` AS `cfgd`
WHERE
`cfg`.`oxshopid` = " . $oDb->quote( $sShopId ) . "
AND
`cfg`.`oxmodule` = " . $oDb->quote( 'theme:' . $scriptConfig->from ) ."
AND(
`cfgd`.`oxcfgmodule` = `cfg`.`oxmodule`
AND
`cfgd`.`oxcfgvarname` = `cfg`.`oxvarname`
)
";
if($scriptConfig->dump) {
var_dump($sql);
}
$aThemeValues = $oDb->getAll( $sSql );
if($scriptConfig->dump) {
var_dump($aThemeValues);
}
if( is_array( $aThemeValues )
&& !empty( $aThemeValues ) )
{
// delete existent settings
$sSql = "
DELETE FROM
`oxconfig`
WHERE
`oxshopid` = " . $oDb->quote( $sShopId ) . "
AND
`oxmodule` = " . $oDb->quote( 'theme:' . $scriptConfig->to ) . "
";
if($scriptConfig->dump) {
var_dump($sSql);
} else {
$oDb->Execute($sSql);
}
// delete existent settings
$sSql = "
DELETE FROM
`oxconfigdisplay`
WHERE
`oxcfgmodule` = " . $oDb->quote( 'theme:' . $scriptConfig->to ) . "
";
if($scriptConfig->dump) {
var_dump($sSql);
} else {
$oDb->Execute($sSql);
}
foreach( $aThemeValues as $aConfig )
{
// $aConfig[2] = name
// $aConfig[3] = type
// $aConfig[4] = value
// $aConfig[5] = group
// $aConfig[6] = constraint
// $aConfig[7] = pos
$sSql = "
REPLACE INTO
`oxconfig`
SET
`OXID` = '" . md5( 'oxconfig:theme:' . $scriptConfig->to . "." . $aConfig[2] ) . "',
`OXSHOPID` = " . $oDb->quote( $sShopId ) . ",
`OXMODULE` = " . $oDb->quote( 'theme:' . $scriptConfig->to ) . ",
`OXVARNAME` = " . $oDb->quote( $aConfig[2] ) . ",
`OXVARTYPE` = " . $oDb->quote( $aConfig[3] ) . ",
`OXVARVALUE` = ENCODE( " . $oDb->quote( $aConfig[4] ) . ", " . $oDb->quote( $sConfigKey ) . " )
";
if($scriptConfig->dump) {
var_dump($aConfig);
var_dump($sSql);
} else {
$oDb->Execute($sSql);
}
// display
$sSql = "
REPLACE INTO
`oxconfigdisplay`
SET
`oxid` = '" . md5( 'oxconfigdisplay:theme:' . $scriptConfig->to . "." . $aConfig[2] ) . "',
`oxcfgmodule` = " . $oDb->quote( 'theme:' . $scriptConfig->to ) . ",
`oxcfgvarname` = " . $oDb->quote( $aConfig[2] ) . ",
`oxgrouping` = " . $oDb->quote( $aConfig[5] ) . ",
`oxvarconstraint` = " . $oDb->quote( $aConfig[6] ) . ",
`oxpos` = " . $oDb->quote( $aConfig[7] ) . "
";
if($scriptConfig->dump) {
var_dump($sSql);
} else {
$oDb->Execute($sSql);
}
}
echo 'Done! ', 'Delete this file!!!!';
} else {
exit('Error. Could not find any items related to theme "'. $scriptConfig->from . '".' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment