Edit / repair / deactivate module entries via frontend

Did a new module entry destroy your backend? Does a misconfiguration of a module prevent you from using the backend?

Just use this script:

If a Module entry causes a crash of the backend area you can easily edit those entires via frontend with this script.

So you can restore the backend functionality very easy without digging in the database. This script can be used only when logged in as admin user (oxdefaultadmin) in the frontend.

Simply save the following code to a php file and place into the rootlevel of your shop. Call the script with www.your-domain/file.php

regenerateSessionId();
if( oxRegistry::getSession()->getVariable('usr') === null || oxRegistry::getSession()->getVariable('usr') !== 'oxdefaultadmin' ) {
    exit( 'Login required' );
}

//error_reporting( E_ALL | E_STRICT );
header('content-type:text/html; charset=utf-8');

class Hz_Modules
{
    public function __construct(){}
}

$scriptConfig = (object) array(
    'delimiter'   => PHP_EOL,
    'separator'   => '=>',
    'str_pad'     => 30,
    'session_key' => 'hz_modules',//basename(__FILE__)
    'redirect'    => false,
    'lang'        => ( $lang = oxRegistry::getLang() ) ? $lang : 'de',
    'history'     => null,
    'text'        => array(
        'headline' => array(
            'de' => 'Moduleinträge bearbeiten.',
            'en' => 'Edit Module-Entries'
        ),
    )
);
$sShopId = $shopConfig->getBaseShopId();

$scriptConfig->history = $shopConfig->getConfigParam('aModulesHistory');

/**
 * Eintrag aus Verlauf löschen
 */
if( isset( $_GET['v']['delete'] ) ) {
    $time = (int)$_GET['v']['delete'];
    if( isset( $scriptConfig->history[$time] ) ) {
        unset( $scriptConfig->history[$time] );
    }
    $scriptConfig->redirect = true;
}

/**
 * Module speichern
 */
if( isset( $_POST['m']['save'] ) )
{
    $_string  = trim( $_POST['m']['modules'] );
    $_rows    = explode( $scriptConfig->delimiter, $_string );
    $aModules = array();
    foreach( $_rows as $_row ) {
        if( strpos($_row, $scriptConfig->separator ) === false ) {
            continue;
        }
        $_m = explode($scriptConfig->separator, $_row);
        if( !isset( $_m[0] ) || !isset( $_m[1] ) ) {
           continue;
        }
        $class    = trim( $_m[0] );
        $module   = trim( $_m[1] );
        if( !empty( $class ) && !empty( $module ) ) {
            $aModules[$class] = $module;
        }
    }
    $shopConfig->saveShopConfVar( 'aarr', 'aModules', $aModules, $sShopId, $sModule = '' );
    $_aTmp = array();
    foreach( $aModules as $class => $module ) {
        $_aTmp[] = str_pad($class,$scriptConfig->str_pad,' ') . str_pad( $scriptConfig->separator, ( strlen( $scriptConfig->separator ) + 2 ) , ' ', STR_PAD_BOTH ) . $module;
    }
    $scriptConfig->history[time()] = array(
        'comment' => htmlspecialchars( $_POST['m']['comment'] ),
        'modules'   => implode( PHP_EOL, $_aTmp )
    );
    krsort( $scriptConfig->history );
    $scriptConfig->redirect = true;
}

/**
 * Wenn gepeichert oder gelöscht, redirect um "reload" zu verhindern.
 */
if( $scriptConfig->redirect === true ) {
    $shopConfig->saveShopConfVar( 'aarr', 'aModulesHistory', $scriptConfig->history, $sShopId, $sModule = '' );
    header('location:http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] );
}

/**
 * Zeichenkette für die Textarea
 * Setze den ersten Eintrag aus dem Verlauf (Letzter gepeicherter) wenn es einen
 * gibt.
 */
$sModules  = '';
$sComment  = '';
if( !empty( $scriptConfig->history ) ) {
    $_entry = reset( $scriptConfig->history );
    $sModules  = $_entry['modules'];
    $sComment  = $_entry['comment'];
} else {
    $_aModules = array();
    foreach( $shopConfig->getConfigParam( 'aModules' ) as $class => $module ) {
        $_aModules[] = str_pad($class,$scriptConfig->str_pad,' ') . str_pad( $scriptConfig->separator, ( strlen( $scriptConfig->separator ) + 2 ), ' ',  STR_PAD_BOTH) . $module;
    }
    $sModules = implode( PHP_EOL, $_aModules );
    $sComment = 'Kommentar';
}


?>



    OXID eSales - Module bearbeiten
    
    
    
    
    
    
    



    

Module bearbeiten

  • Man kann Einträge auch auskommentieren in dem man die Klasse "unkenntlich" macht. z.B.: "//oxorder => ... "
  • Windowssystem akzeptieren "Datei.php = datei.php", Unix nicht. Schreibweise beachten.
Aktuelle Moduleinträge:
history ) : ?>

Verlauf:

$data ) : ?>
In das Eingabefeld übernehmen|aus Verlauf löschen

Thanks to Stefan / stefan2

http://www.oxid-esales.com/forum/member.php?u=8626

[Update] edited by foxido.de to run with the latest versions (thanks for that!): http://forum.oxid-esales.com/showthread.php?t=40205&page=3#post182821



0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *