aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-12-20 04:35:30 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-12-20 04:35:30 -0500
commite50f69187f21e29a12512880e0c69f2876e84aa1 (patch)
tree852fd2b5456e55ec8c0f04fb54ea770dae63f554
parent3701d83ecbd358c2ac78b74e314ddb74ce7d1812 (diff)
downloadforums-e50f69187f21e29a12512880e0c69f2876e84aa1.tar
forums-e50f69187f21e29a12512880e0c69f2876e84aa1.tar.gz
forums-e50f69187f21e29a12512880e0c69f2876e84aa1.tar.bz2
forums-e50f69187f21e29a12512880e0c69f2876e84aa1.tar.xz
forums-e50f69187f21e29a12512880e0c69f2876e84aa1.zip
[ticket/11037] Eliminate global $db usage in cache drivers.
The only time $db is needed in cache drivers is to navigate the result set in sql_save. Pass it as a parameter in that function. PHPBB3-11037
-rw-r--r--phpBB/includes/cache/driver/file.php6
-rw-r--r--phpBB/includes/cache/driver/interface.php3
-rw-r--r--phpBB/includes/cache/driver/memory.php6
-rw-r--r--phpBB/includes/cache/driver/null.php4
-rw-r--r--phpBB/includes/db/driver/firebird.php2
-rw-r--r--phpBB/includes/db/driver/mssql.php2
-rw-r--r--phpBB/includes/db/driver/mssql_odbc.php2
-rw-r--r--phpBB/includes/db/driver/mssqlnative.php2
-rw-r--r--phpBB/includes/db/driver/mysql.php2
-rw-r--r--phpBB/includes/db/driver/mysqli.php2
-rw-r--r--phpBB/includes/db/driver/oracle.php2
-rw-r--r--phpBB/includes/db/driver/postgres.php2
-rw-r--r--phpBB/includes/db/driver/sqlite.php2
-rw-r--r--tests/mock/cache.php6
14 files changed, 22 insertions, 21 deletions
diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php
index 691abe0438..85decbe3e8 100644
--- a/phpBB/includes/cache/driver/file.php
+++ b/phpBB/includes/cache/driver/file.php
@@ -367,12 +367,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
}
/**
- * Save sql query
+ * {@inheritDoc}
*/
- function sql_save($query, $query_result, $ttl)
+ function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
- global $db;
-
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php
index d403bbcd71..53f684d1c8 100644
--- a/phpBB/includes/cache/driver/interface.php
+++ b/phpBB/includes/cache/driver/interface.php
@@ -85,6 +85,7 @@ interface phpbb_cache_driver_interface
* result to persistent storage. In other words, there is no need
* to call save() afterwards.
*
+ * @param phpbb_db_driver $db Database connection
* @param string $query SQL query, should be used for generating storage key
* @param mixed $query_result The result from dbal::sql_query, to be passed to
* dbal::sql_fetchrow to get all rows and store them
@@ -95,7 +96,7 @@ interface phpbb_cache_driver_interface
* representing the query should be returned. Otherwise
* the original $query_result should be returned.
*/
- public function sql_save($query, $query_result, $ttl);
+ public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl);
/**
* Check if result for a given SQL query exists in cache.
diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php
index c39f9f7850..f77a1df316 100644
--- a/phpBB/includes/cache/driver/memory.php
+++ b/phpBB/includes/cache/driver/memory.php
@@ -283,12 +283,10 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
}
/**
- * Save sql query
+ * {@inheritDoc}
*/
- function sql_save($query, $query_result, $ttl)
+ function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
- global $db;
-
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
$hash = md5($query);
diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php
index 687604d14f..2fadc27ba3 100644
--- a/phpBB/includes/cache/driver/null.php
+++ b/phpBB/includes/cache/driver/null.php
@@ -105,9 +105,9 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base
}
/**
- * Save sql query
+ * {@inheritDoc}
*/
- function sql_save($query, $query_result, $ttl)
+ function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
return $query_result;
}
diff --git a/phpBB/includes/db/driver/firebird.php b/phpBB/includes/db/driver/firebird.php
index a55175c345..4767b29f63 100644
--- a/phpBB/includes/db/driver/firebird.php
+++ b/phpBB/includes/db/driver/firebird.php
@@ -270,7 +270,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/mssql.php b/phpBB/includes/db/driver/mssql.php
index ac957e7698..215c6345c6 100644
--- a/phpBB/includes/db/driver/mssql.php
+++ b/phpBB/includes/db/driver/mssql.php
@@ -168,7 +168,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/mssql_odbc.php b/phpBB/includes/db/driver/mssql_odbc.php
index 13e74e66d4..7d93f939a2 100644
--- a/phpBB/includes/db/driver/mssql_odbc.php
+++ b/phpBB/includes/db/driver/mssql_odbc.php
@@ -197,7 +197,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/mssqlnative.php b/phpBB/includes/db/driver/mssqlnative.php
index 4b1639aba2..f88c702d07 100644
--- a/phpBB/includes/db/driver/mssqlnative.php
+++ b/phpBB/includes/db/driver/mssqlnative.php
@@ -337,7 +337,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/mysql.php b/phpBB/includes/db/driver/mysql.php
index 6fc6fab483..30f78c9231 100644
--- a/phpBB/includes/db/driver/mysql.php
+++ b/phpBB/includes/db/driver/mysql.php
@@ -206,7 +206,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php
index be28a95715..4f45c5781c 100644
--- a/phpBB/includes/db/driver/mysqli.php
+++ b/phpBB/includes/db/driver/mysqli.php
@@ -201,7 +201,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
if ($cache_ttl)
{
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
}
else if (defined('DEBUG'))
diff --git a/phpBB/includes/db/driver/oracle.php b/phpBB/includes/db/driver/oracle.php
index 6263ea8414..53f9dd71e0 100644
--- a/phpBB/includes/db/driver/oracle.php
+++ b/phpBB/includes/db/driver/oracle.php
@@ -446,7 +446,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/postgres.php b/phpBB/includes/db/driver/postgres.php
index 147ecd04d9..cca97c9c0e 100644
--- a/phpBB/includes/db/driver/postgres.php
+++ b/phpBB/includes/db/driver/postgres.php
@@ -211,7 +211,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/phpBB/includes/db/driver/sqlite.php b/phpBB/includes/db/driver/sqlite.php
index 6b9cc64d89..155409b665 100644
--- a/phpBB/includes/db/driver/sqlite.php
+++ b/phpBB/includes/db/driver/sqlite.php
@@ -152,7 +152,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index bc18ca066b..71af3037f5 100644
--- a/tests/mock/cache.php
+++ b/tests/mock/cache.php
@@ -121,7 +121,11 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
public function sql_load($query)
{
}
- public function sql_save($query, $query_result, $ttl)
+
+ /**
+ * {@inheritDoc}
+ */
+ public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
{
return $query_result;
}