Gaining access to the admin program if a module causes an error

If a module causes an error, you are currently effectively locked out of the shop, as the admin program does not start any more…

In order to regain control, I have modified the class generation process, so that inclusion of the modules is no longer carried out…

The idea is, to start the admin program in that case with a [B]parameter[/B], like

[B]…/admin/index.php?safemode=true[/B]

In order to achieve this, you have to exchange the complete function

“[B]public function getClassName( $sClassName )[/B]” in “[B]core/oxutilsobject.php[/B]”

with the following code.

    public function getClassName( $sClassName )
    {
        //Avenger
        $blSafeMode=$this->blSafeMode;
        if (!isset($blSafeMode))
        {
          $blSafeMode=$_COOKIE['safemode'];
          if (!isset($blSafeMode))
          {
            $blSafeMode=oxConfig::getParameter('safemode');
            setcookie("safemode",$blSafeMode);
            $this->blSafeMode=$blSafeMode;
          }
        }
        if (!$blSafeMode)
        {
          $aModules = $this->getConfig()->getConfigParam( 'aModules' );
          if ( is_array( $aModules ) && array_key_exists( $sClassName, $aModules ) ) {
              //multiple inheritance implementation
              //in case we have multiple modules:
              //like oxoutput => sub/suboutput1&sub/suboutput2&sub/suboutput3
              $aClassChain = explode( "&", $aModules[$sClassName] );

              $sParent = $sClassName;

              //security: just preventing string termination
              $sParent = str_replace(chr(0), '', $sParent);

              //building middle classes if needed
              $sClassName = $this->_makeSafeModuleClassParents( $aClassChain, $sParent );
          }
        }
        //Avenger

        // check if there is a path, if yes, remove it
        $sClassName = basename( $sClassName );

        return $sClassName;
    }

It is also a good idea to backup the database.table “[B]oxconfig[/B]” before you make any changes in the modules to include…

So you can recover from a potential problem also…

Good idea,

another solution to this problem especially when you habe no access to the oxutilsobject.php (PE or EE) is to go to the table oxconfig an look for the entry with oxvarname == “aModules” (don’t forget to look for the right shop in EE) and delete this record. Then all module entries are deleted.

But having such a safe mode build in for admin would be great :slight_smile:

@MaFi - deleting all modules is sub-optimal, if there are a lot of installed modules. This would most likely cripple a shop completely.

@Avenger - does the safemode=true method work for 4.5.x versions of OXID? Or what is the version for which you had tested for the above post.

Thank you both!

[QUOTE=euroblaze;72620]@Avenger - does the safemode=true method work for 4.5.x versions of OXID? Or what is the version for which you had tested for the above post.[/QUOTE]
Yes, it works…

Even better now, as it can be placed in a module, instead of modifying the core…

[QUOTE=avenger;72622]Yes, it works…

Even better now, as it can be placed in a module, instead of modifying the core…[/QUOTE]

Store the following code as “modules/powertemplate/pt_oxutilsobject/pt_oxutilsobject.php”

<?php
/**
* Implement "safemode" to recover from module failures
*
*  Copyright 2011: Avenger, [email protected]
*
Invocation in admin/modules: oxutilsobject => powertemplate/pt_oxutilsobject/pt_oxutilsobject

*/
class pt_oxutilsobject extends pt_oxutilsobject_parent
{
  public function getClassName( $sClassName )
  {
    $blSafeMode=$this->blSafeMode;
    if (!isset($blSafeMode))
    {
      $blSafeMode=$_GET['safemode'];
      if (isset($blSafeMode))
      {
        setcookie("safemode",$blSafeMode);
      }
      else
      {
        $blSafeMode=$_COOKIE['safemode'];
      }
      $blSafeMode=$blSafeMode=='true';
      $this->blSafeMode=$blSafeMode;
    }
    if ($blSafeMode)
    {
      return basename( $sClassName );
    }
    else
    {
      $sClassName=parent::getClassName( $sClassName );
      return $sClassName;
    }
  }
}
?>

In “config.inc” define

  $this->aModules = array (
  'oxutilsobject' => 'powertemplate/pt_oxutilsobject/pt_oxutilsobject'
);