From ee2e46c338aedb5661513f643245d35281a81656 Mon Sep 17 00:00:00 2001 From: dMetzger Date: Mon, 27 Aug 2012 06:47:41 +0000 Subject: [PATCH] [-] Installer : ignore port when creating the sender e-mail address #PSCFV-3756 // Improved profiling tool --- classes/Tools.php | 4 +- install-dev/models/mail.php | 2 +- tools/profiling/Db.php | 74 +++++++++++++++++++++---------------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/classes/Tools.php b/classes/Tools.php index f38484cb0..ab89fddbb 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -175,9 +175,11 @@ class ToolsCore * @param boolean $entities * @return string host */ - public static function getHttpHost($http = false, $entities = false) + public static function getHttpHost($http = false, $entities = false, $ignore_port = false) { $host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']); + if ($ignore_port && $pos = strpos($host, ':')) + $host = substr($host, 0, $pos); if ($entities) $host = htmlspecialchars($host, ENT_COMPAT, 'UTF-8'); if ($http) diff --git a/install-dev/models/mail.php b/install-dev/models/mail.php index a3d047858..3cbd53671 100644 --- a/install-dev/models/mail.php +++ b/install-dev/models/mail.php @@ -79,7 +79,7 @@ class InstallModelMail extends InstallAbstractModel $swift = new Swift(new Swift_Connection_NativeMail()); $message = new Swift_Message($subject, $content, 'text/html'); - if (@$swift->send($message, $this->email, 'no-reply@'.Tools::getHttpHost())) + if (@$swift->send($message, $this->email, 'no-reply@'.Tools::getHttpHost(false, false, true))) $result = false; else $result = 'Could not send message'; diff --git a/tools/profiling/Db.php b/tools/profiling/Db.php index 1a16a8fb6..f788b5783 100644 --- a/tools/profiling/Db.php +++ b/tools/profiling/Db.php @@ -69,41 +69,53 @@ abstract class Db extends DbCore */ public function query($sql) { - $uniqSql = preg_replace('/[0-9]+/', 'XX', $sql); - if (!isset($this->uniqQueries[$uniqSql])) - $this->uniqQueries[$uniqSql] = 0; - $this->uniqQueries[$uniqSql]++; - - // No cache for query - if ($this->disableCache) - $sql = preg_replace('/^select /i', 'SELECT SQL_NO_CACHE ', trim($sql)); - - // Get tables in quer - preg_match_all('/(from|join)\s+`?'._DB_PREFIX_.'([a-z0-9_-]+)/ui', $sql, $matches); - foreach ($matches[2] as $table) + $explain = false; + if (preg_match('/^\s*explain\s+/i', $sql)) + $explain = true; + + if (!$explain) { - if (!isset($this->tables[$table])) - $this->tables[$table] = 0; - $this->tables[$table]++; - } + $uniqSql = preg_replace('/[0-9]+/', 'XX', $sql); + if (!isset($this->uniqQueries[$uniqSql])) + $this->uniqQueries[$uniqSql] = 0; + $this->uniqQueries[$uniqSql]++; - // Execute query - $start = microtime(true); + // No cache for query + if ($this->disableCache) + $sql = preg_replace('/^\s*select\s+/i', 'SELECT SQL_NO_CACHE ', trim($sql)); + + // Get tables in quer + preg_match_all('/(from|join)\s+`?'._DB_PREFIX_.'([a-z0-9_-]+)/ui', $sql, $matches); + foreach ($matches[2] as $table) + { + if (!isset($this->tables[$table])) + $this->tables[$table] = 0; + $this->tables[$table]++; + } + + // Execute query + $start = microtime(true); + } + $result = parent::query($sql); - $end = microtime(true); - // Save details - $timeSpent = $end - $start; - $trace = debug_backtrace(false); - while (preg_match('@[/\\\\]classes[/\\\\]db[/\\\\]@i', $trace[0]['file'])) - array_shift($trace); - - $this->queries[] = array( - 'query' => $sql, - 'time' => $timeSpent, - 'file' => $trace[0]['file'], - 'line' => $trace[0]['line'], - ); + if (!$explain) + { + $end = microtime(true); + + // Save details + $timeSpent = $end - $start; + $trace = debug_backtrace(false); + while (preg_match('@[/\\\\]classes[/\\\\]db[/\\\\]@i', $trace[0]['file'])) + array_shift($trace); + + $this->queries[] = array( + 'query' => $sql, + 'time' => $timeSpent, + 'file' => $trace[0]['file'], + 'line' => $trace[0]['line'], + ); + } return $result; }