/** * @see ExceptionHandlerInterface::__construct() * @param object $exception */ function __construct($exception) { global $db, $transaction, $session; if (is_object($exception)) { $transaction->force_rollback(false); if ($exception instanceof BaseException) { $error_id = uniqid(); $error_data = date("Ymd-His"); if ($exception->get_write_hdd_sql()) { $db->query_log_end(); if (is_writable(constant("LOG_DIR"))) { $sql_log_dir = constant("LOG_DIR") . "/sql"; if (is_writable($sql_log_dir)) { $filename = "sql-" . $error_data . "-" . get_class($exception) . "-" . $error_id . ".txt"; $handle = fopen($sql_log_dir . "/" . $filename, "w"); fwrite($handle, $db->get_query_log()); fwrite($handle, "\n\n"); fwrite($handle, "-----------\n"); fwrite($handle, "LAST ERROR:\n"); fwrite($handle, $db->db_last_error()); fclose($handle); } } } if ($exception->get_write_hdd_session()) { $session_value_array = Session::list_all_session_values($session->get_session_id()); if (is_array($session_value_array) and count($session_value_array)) { if (is_writable(constant("LOG_DIR"))) { $session_log_dir = constant("LOG_DIR") . "/session"; if (is_writable($session_log_dir)) { $filename = "session-" . $error_data . "-" . get_class($exception) . "-" . $error_id . ".txt"; $handle = fopen($session_log_dir . "/" . $filename, "w"); foreach ($session_value_array as $key => $value) { fwrite($handle, $value['address'] . " => " . $value['value'] . "\n"); } fclose($handle); } } } } if ($exception->get_write_log()) { if (method_exists($session, get_user_id)) { if ($session->get_user_id()) { $this->write_log($session->get_user_id(), $exception); } else { $this->write_log(null, $exception); } } } } elseif ($exception instanceof Exception) { if ($session->get_user_id()) { $this->write_log($session->get_user_id(), $exception); } else { $this->write_log(null, $exception); } } } }