Development

Changeset 31532

You must first sign up to be able to contribute.

Changeset 31532

Show
Ignore:
Timestamp:
11/26/10 10:33:48 (2 years ago)
Author:
jeanmonod
Message:

Switch to use the Doctrine Abstraction layer when saving PHP_errors, so now it's compatible with any database engine
fix #9262

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/idlErrorManagementPlugin/trunk/lib/idlErrorManagement.class.php

    r31307 r31532  
    202202    } 
    203203       
    204     // Retrived the database configuration parameter for current env 
     204    // Retrived parameters for script generation 
     205    $env = sfConfig::get('sf_environment'); 
     206    $sessionKey = self::LAST_ERROR_SESSION_KEY; 
     207    $doctrinePath = sfConfig::get('sf_symfony_lib_dir').'/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine.php'; 
    205208    $dbConfig = sfYaml::load(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'databases.yml'); 
    206     $env = sfConfig::get('sf_environment'); 
    207209    $dbConfig = $dbConfig[$env]['doctrine']['param']; 
    208     preg_match("/.+:host=(.+);dbname=(.+)/",$dbConfig["dsn"], $matches); 
    209     $host = $matches[1]; 
    210     $dbName = $matches[2]; 
     210    $dsn = $dbConfig["dsn"]; 
    211211    $user = $dbConfig['username']; 
    212     $password = isset($dbConfig['password']) ? $dbConfig['password'] : null; 
    213     $sessionKey = self::LAST_ERROR_SESSION_KEY; 
    214     $passwordParam = isset($password) ? ", '".$password."'" : ""; 
     212    $password = isset($dbConfig['password']) ? "'".$dbConfig['password']."'" : 'null'; 
    215213     
    216214     
     
    226224      } 
    227225       
    228       // Record to database 
    229       \$con = @mysql_connect('$host', '$user' $passwordParam); 
    230       if (\$con==false){ 
    231         echo ("idlErrorManagementPlugin: Connection to database fail, impossible to record error\n<br>See $file for more info"); 
    232         return; 
    233       } 
    234       mysql_select_db('$dbName', \$con); 
    235       \$sql = "INSERT INTO `application_error` (`type`, `file`, `line`, `code`,  `message`, `user_agent`, `uri`, `created_at`)  
    236       VALUES ( 
    237         'PHP error', 
    238         '".\$error['file']."', 
    239         '".\$error['line']."', 
    240         '".\$error['type']."', 
    241         '".\$error['message']."', 
    242         '".(isset(\$_SERVER['HTTP_USER_AGENT'])?\$_SERVER['HTTP_USER_AGENT']:'')."', 
    243         '".(isset(\$_SERVER['REQUEST_URI'])?\$_SERVER['REQUEST_URI']:'')."', 
    244         '".date("Y-m-d H:i:s")."' 
    245       );"; 
    246       mysql_query(\$sql,\$con); 
     226      // Connect to the database using doctrine abstraction layer 
     227      require_once('$doctrinePath'); 
     228      spl_autoload_register(array('Doctrine', 'autoload')); 
     229      \$pdo = new PDO('$dsn', '$user', $password); 
     230      \$conn = Doctrine_Manager::connection(\$pdo); 
     231      \$conn->execute( 
     232        "INSERT INTO `application_error` (`type`, `file`, `line`, `code`,  `message`, `user_agent`, `uri`, `created_at`)  
     233        VALUES ( 
     234          'PHP error', 
     235          '".\$error['file']."', 
     236          '".\$error['line']."', 
     237          '".\$error['type']."', 
     238          '".\$error['message']."', 
     239          '".(isset(\$_SERVER['HTTP_USER_AGENT'])?\$_SERVER['HTTP_USER_AGENT']:'')."', 
     240          '".(isset(\$_SERVER['REQUEST_URI'])?\$_SERVER['REQUEST_URI']:'')."', 
     241          '".date("Y-m-d H:i:s")."' 
     242        )" 
     243      ); 
    247244       
    248245      // Place the id to session 
    249       \$id = mysql_insert_id(); 
     246      \$id = \$conn->lastInsertId(); 
    250247      if (isset(\$id) && \$id > 0) { 
    251248        \$_SESSION['$sessionKey'] = \$id; 
     
    253250       
    254251      // Redirect to comment form 
    255       // TODO 
     252      // TODO, but it's difficult as we don't now if header are already send 
    256253    } 
    257254  }