Copy template config for Version 5.0

Hey everyone,

I adapted the config copy script by stefan2 for version 5, in case anybody needs that:


<?php
/**
 * $Id$
 *
 * It's quite remarkable, that the oxid in oxconfig and oxconfigdisplay do not correspond.
 * If a new config-value is saved, this will get a new ID.
 * check: core/oxconfig ~ 1680
 *
 * # you need to be logged in as Admin in Frontend, or comment out the checkup in line exit(Log In needed.)
 * # Adjust values for Source and Target before running first.
 * # Put file into rootlevel
 * # copy the source-themefolder first and rename to "myTheme"
 */

ini_set('display_errors', 1);

// Adjust here:
$scriptConfig = (object) array(
    'from' => 'azure',           // Source
    'to'   => 'apsp'          // Target
);

if (!defined('OX_BASE_PATH')) {
    define('OX_BASE_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR );
}

// custom functions file
require_once OX_BASE_PATH . 'modules/functions.php';

// Generic utility method file including autoloading definition
require_once OX_BASE_PATH . 'core/oxfunctions.php';

//sets default PHP ini params
setPhpIniParams();

//strips magics quote if any is set
stripGpcMagicQuotes();

//init config.inc.php file reader
$oConfigFile = new oxConfigFile( OX_BASE_PATH . "config.inc.php" );

oxRegistry::set("oxConfigFile", $oConfigFile );

exit('Logged in? Adapted parameters?');

$oDb      = oxDb::getDb(true);
$oShopControl = oxNew('oxShopControl');
$shopConfig = $oShopControl->getConfig();
$sShopId = $shopConfig->getBaseShopId();


$sSql = "
    SELECT
        `cfg`.`oxid`                                                   AS `id`,
        `cfg`.`oxmodule`                                               AS `theme`,
        `cfg`.`oxvarname`                                              AS `name`,
        `cfg`.`oxvartype`                                              AS `type`,
        DECODE( `cfg`.`oxvarvalue`, '" . $shopConfig->getConfigParam( '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` = '" . $sShopId . "'
    AND
        `cfg`.`oxmodule` = 'theme:" . $scriptConfig->from ."'
    AND(
        `cfgd`.`oxcfgmodule` = `cfg`.`oxmodule`
        AND
        `cfgd`.`oxcfgvarname` = `cfg`.`oxvarname`
    )
";

$aThemeValues = $oDb->getAll( $sSql );

if( is_array( $aThemeValues )
    && !empty( $aThemeValues ) )
{
    // delete existing values for theme
    $oDb->Execute("
        DELETE FROM
            `oxconfig`
        WHERE
            `oxshopid`  = '" . $sShopId . "'
        AND
            `oxmodule` = 'theme:" . $scriptConfig->to . "'
    ");

    // delete existing values for theme
    $oDb->Execute("
        DELETE FROM
            `oxconfigdisplay`
        WHERE
            `oxcfgmodule` = 'theme:" . $scriptConfig->to . "'
    ");

    foreach( $aThemeValues as $aConfig )
    {
        $cfg = $aConfig;        
        
        $sSql = "
            REPLACE INTO
                `oxconfig`
            SET
                `OXID`       = '" . $scriptConfig->to . "." . $cfg[2] . "',
                `OXSHOPID`   = '" . $sShopId . "',
                `OXMODULE`   = 'theme:" . $scriptConfig->to . "',
                `OXVARNAME`  = '" . $cfg[2] . "',
                `OXVARTYPE`  = '" . $cfg[3] . "',
                `OXVARVALUE` = ENCODE( " . $oDb->quote( $cfg[4] ) . ", " . $oDb->quote( $shopConfig->getConfigParam( 'sConfigKey' ) ) . " )
        ";       
        
        $oDb->Execute($sSql);
        
        // display
        $sSql = "
            REPLACE INTO
                `oxconfigdisplay`
            SET
                `oxid`            = '" . $scriptConfig->to . "." . $cfg[2] . "',
                `oxcfgmodule`     = 'theme:" . $scriptConfig->to . "',
                `oxcfgvarname`    = '" . $cfg[2] . "',
                `oxgrouping`      = '" . $cfg[5] . "',
                `oxvarconstraint` = '" . $cfg[6] . "',
                `oxpos`           = '" . $cfg[7] . "'
      ";
        
        $oDb->Execute($sSql);
    }
} else {
    exit('Exception. No entries found for "'. $scriptConfig->from . '"' );
}


$scriptConfig = (object) array(
    'from' => 'azure',           // Source
    'to'   => 'apsp'          // Target
);

“APSP” has to be altered to whatever your new theme is. Make sure you’re logged in before you do that!

Thanks for adapting and sharing! I will add this in the Wiki!

hey pschoefer

very cool, thanks a lot

Hi Guys,

i’m new to oxid and try to clone the default theme ‘azure’.
copied the folders /application/views/azure to /application/views/mytemplate and the folders in /out/azure to /out/mytemplate

then i’ve uploaded your script zu my oxid root folder gave it a ‘777’ and tried to execute it. But all i#ve got is a error 500.

i’m using Community Edition 4.8.4.
thanks in advance.

no need to clone the complete template - you could set up a so called “child template” and put only the changed template files in this new directory

see here for more info:

Thank you for your reply.
but i want to clone the whole template. if i use a child template, every update to the core template affects my design. so thats no good option for me.

thanks

Thanx!! I like it, you have saved my night today :slight_smile:

Greetings
Martina

hi i am smith, i really appreciate this template coding, but i have visited a website that provides a wonderfull and free templates without any coding, templates for business, restorent, sports app, mobile apps and many more visit now. Create My Free App