Changeset 31532
- Timestamp:
- 11/26/10 10:33:48 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/idlErrorManagementPlugin/trunk/lib/idlErrorManagement.class.php
r31307 r31532 202 202 } 203 203 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'; 205 208 $dbConfig = sfYaml::load(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'databases.yml'); 206 $env = sfConfig::get('sf_environment');207 209 $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"]; 211 211 $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'; 215 213 216 214 … … 226 224 } 227 225 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 ); 247 244 248 245 // Place the id to session 249 \$id = mysql_insert_id();246 \$id = \$conn->lastInsertId(); 250 247 if (isset(\$id) && \$id > 0) { 251 248 \$_SESSION['$sessionKey'] = \$id; … … 253 250 254 251 // Redirect to comment form 255 // TODO 252 // TODO, but it's difficult as we don't now if header are already send 256 253 } 257 254 }