From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/cache/driver/memory.php | 439 ++++++++++++++++++++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 phpBB/phpbb/cache/driver/memory.php (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php new file mode 100644 index 0000000000..f77a1df316 --- /dev/null +++ b/phpBB/phpbb/cache/driver/memory.php @@ -0,0 +1,439 @@ +cache_dir = $phpbb_root_path . 'cache/'; + $this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_'; + + if (!isset($this->extension) || !extension_loaded($this->extension)) + { + global $acm_type; + + trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR); + } + + if (isset($this->function) && !function_exists($this->function)) + { + global $acm_type; + + trigger_error("The required function [{$this->function}] is not available for the ACM module $acm_type.", E_USER_ERROR); + } + } + + /** + * Load global cache + */ + function load() + { + // grab the global cache + $this->vars = $this->_read('global'); + + if ($this->vars !== false) + { + return true; + } + + return false; + } + + /** + * Unload cache object + */ + function unload() + { + $this->save(); + unset($this->vars); + unset($this->sql_rowset); + unset($this->sql_row_pointer); + + $this->vars = array(); + $this->sql_rowset = array(); + $this->sql_row_pointer = array(); + } + + /** + * Save modified objects + */ + function save() + { + if (!$this->is_modified) + { + return; + } + + $this->_write('global', $this->vars, 2592000); + + $this->is_modified = false; + } + + /** + * Tidy cache + */ + function tidy() + { + // cache has auto GC, no need to have any code here :) + + set_config('cache_last_gc', time(), true); + } + + /** + * Get saved cache object + */ + function get($var_name) + { + if ($var_name[0] == '_') + { + if (!$this->_exists($var_name)) + { + return false; + } + + return $this->_read($var_name); + } + else + { + return ($this->_exists($var_name)) ? $this->vars[$var_name] : false; + } + } + + /** + * Put data into cache + */ + function put($var_name, $var, $ttl = 2592000) + { + if ($var_name[0] == '_') + { + $this->_write($var_name, $var, $ttl); + } + else + { + $this->vars[$var_name] = $var; + $this->is_modified = true; + } + } + + /** + * Purge cache data + */ + function purge() + { + // Purge all phpbb cache files + $dir = @opendir($this->cache_dir); + + if (!$dir) + { + return; + } + + while (($entry = readdir($dir)) !== false) + { + if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && + strpos($entry, 'sql_') !== 0 && + strpos($entry, 'data_') !== 0 && + strpos($entry, 'ctpl_') !== 0 && + strpos($entry, 'tpl_') !== 0) + { + continue; + } + + $this->remove_file($this->cache_dir . $entry); + } + closedir($dir); + + unset($this->vars); + unset($this->sql_rowset); + unset($this->sql_row_pointer); + + $this->vars = array(); + $this->sql_rowset = array(); + $this->sql_row_pointer = array(); + + $this->is_modified = false; + } + + + /** + * Destroy cache data + */ + function destroy($var_name, $table = '') + { + if ($var_name == 'sql' && !empty($table)) + { + if (!is_array($table)) + { + $table = array($table); + } + + foreach ($table as $table_name) + { + // gives us the md5s that we want + $temp = $this->_read('sql_' . $table_name); + + if ($temp === false) + { + continue; + } + + // delete each query ref + foreach ($temp as $md5_id => $void) + { + $this->_delete('sql_' . $md5_id); + } + + // delete the table ref + $this->_delete('sql_' . $table_name); + } + + return; + } + + if (!$this->_exists($var_name)) + { + return; + } + + if ($var_name[0] == '_') + { + $this->_delete($var_name); + } + else if (isset($this->vars[$var_name])) + { + $this->is_modified = true; + unset($this->vars[$var_name]); + + // We save here to let the following cache hits succeed + $this->save(); + } + } + + /** + * Check if a given cache entry exist + */ + function _exists($var_name) + { + if ($var_name[0] == '_') + { + return $this->_isset($var_name); + } + else + { + if (!sizeof($this->vars)) + { + $this->load(); + } + + return isset($this->vars[$var_name]); + } + } + + /** + * Load cached sql query + */ + function sql_load($query) + { + // Remove extra spaces and tabs + $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); + $query_id = sizeof($this->sql_rowset); + + if (($result = $this->_read('sql_' . md5($query))) === false) + { + return false; + } + + $this->sql_rowset[$query_id] = $result; + $this->sql_row_pointer[$query_id] = 0; + + return $query_id; + } + + /** + * {@inheritDoc} + */ + function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) + { + // Remove extra spaces and tabs + $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); + $hash = md5($query); + + // determine which tables this query belongs to + // Some queries use backticks, namely the get_database_size() query + // don't check for conformity, the SQL would error and not reach here. + if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs)) + { + // Bail out if the match fails. + return $query_result; + } + $tables = array_map('trim', explode(',', $regs[1])); + + foreach ($tables as $table_name) + { + // Remove backticks + $table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name; + + if (($pos = strpos($table_name, ' ')) !== false) + { + $table_name = substr($table_name, 0, $pos); + } + + $temp = $this->_read('sql_' . $table_name); + + if ($temp === false) + { + $temp = array(); + } + + $temp[$hash] = true; + + // This must never expire + $this->_write('sql_' . $table_name, $temp, 0); + } + + // store them in the right place + $query_id = sizeof($this->sql_rowset); + $this->sql_rowset[$query_id] = array(); + $this->sql_row_pointer[$query_id] = 0; + + while ($row = $db->sql_fetchrow($query_result)) + { + $this->sql_rowset[$query_id][] = $row; + } + $db->sql_freeresult($query_result); + + $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); + + return $query_id; + } + + /** + * Ceck if a given sql query exist in cache + */ + function sql_exists($query_id) + { + return isset($this->sql_rowset[$query_id]); + } + + /** + * Fetch row from cache (database) + */ + function sql_fetchrow($query_id) + { + if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) + { + return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; + } + + return false; + } + + /** + * Fetch a field from the current row of a cached database result (database) + */ + function sql_fetchfield($query_id, $field) + { + if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) + { + return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false; + } + + return false; + } + + /** + * Seek a specific row in an a cached database result (database) + */ + function sql_rowseek($rownum, $query_id) + { + if ($rownum >= sizeof($this->sql_rowset[$query_id])) + { + return false; + } + + $this->sql_row_pointer[$query_id] = $rownum; + return true; + } + + /** + * Free memory used for a cached database result (database) + */ + function sql_freeresult($query_id) + { + if (!isset($this->sql_rowset[$query_id])) + { + return false; + } + + unset($this->sql_rowset[$query_id]); + unset($this->sql_row_pointer[$query_id]); + + return true; + } + + /** + * Removes/unlinks file + */ + function remove_file($filename, $check = false) + { + if (!function_exists('phpbb_is_writable')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions.' . $phpEx); + } + + if ($check && !phpbb_is_writable($this->cache_dir)) + { + // E_USER_ERROR - not using language entry - intended. + trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); + } + + return @unlink($filename); + } + + /** + * Check if a cache var exists + * + * @access protected + * @param string $var Cache key + * @return bool True if it exists, otherwise false + */ + function _isset($var) + { + // Most caches don't need to check + return true; + } +} -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- phpBB/phpbb/cache/driver/memory.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index f77a1df316..5a9861913f 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\cache\driver; + /** * @ignore */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB')) * ACM Abstract Memory Class * @package acm */ -abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base +abstract class memory extends \phpbb\cache\driver\base { var $key_prefix; @@ -285,7 +287,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base /** * {@inheritDoc} */ - function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) + function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl) { // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/cache/driver/memory.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 5a9861913f..292024212b 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -9,14 +9,6 @@ namespace phpbb\cache\driver; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * ACM Abstract Memory Class * @package acm -- cgit v1.2.1 From 60e5757fa104c875de084fbb3740d97bafa19070 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 19 Mar 2014 20:31:55 -0700 Subject: [ticket/11230] Use inheritdoc in docblocks in cache drivers http://tracker.phpbb.com/browse/PHPBB3-11230 PHPBB3-11230 --- phpBB/phpbb/cache/driver/memory.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 292024212b..aab180f26a 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -50,7 +50,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Load global cache + * {@inheritDoc} */ function load() { @@ -66,7 +66,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Unload cache object + * {@inheritDoc} */ function unload() { @@ -81,7 +81,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Save modified objects + * {@inheritDoc} */ function save() { @@ -96,7 +96,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Tidy cache + * {@inheritDoc} */ function tidy() { @@ -106,7 +106,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Get saved cache object + * {@inheritDoc} */ function get($var_name) { @@ -126,7 +126,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Put data into cache + * {@inheritDoc} */ function put($var_name, $var, $ttl = 2592000) { @@ -142,7 +142,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Purge cache data + * {@inheritDoc} */ function purge() { @@ -183,7 +183,7 @@ abstract class memory extends \phpbb\cache\driver\base /** - * Destroy cache data + * {@inheritDoc} */ function destroy($var_name, $table = '') { @@ -237,7 +237,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Check if a given cache entry exist + * {@inheritDoc} */ function _exists($var_name) { @@ -257,7 +257,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Load cached sql query + * {@inheritDoc} */ function sql_load($query) { @@ -335,7 +335,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Ceck if a given sql query exist in cache + * {@inheritDoc} */ function sql_exists($query_id) { @@ -343,7 +343,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Fetch row from cache (database) + * {@inheritDoc} */ function sql_fetchrow($query_id) { @@ -356,7 +356,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Fetch a field from the current row of a cached database result (database) + * {@inheritDoc} */ function sql_fetchfield($query_id, $field) { @@ -369,7 +369,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Seek a specific row in an a cached database result (database) + * {@inheritDoc} */ function sql_rowseek($rownum, $query_id) { @@ -383,7 +383,7 @@ abstract class memory extends \phpbb\cache\driver\base } /** - * Free memory used for a cached database result (database) + * {@inheritDoc} */ function sql_freeresult($query_id) { -- cgit v1.2.1 From b87fc1e56cb3701a89db2b6012f37bd75f52f29d Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 22 Mar 2014 08:23:18 -0700 Subject: [ticket/11230] Update cache driver dock blocks PHPBB3-12230 --- phpBB/phpbb/cache/driver/memory.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index aab180f26a..b618b0f3e6 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -400,6 +400,10 @@ abstract class memory extends \phpbb\cache\driver\base /** * Removes/unlinks file + * + * @param string $filename Filename to remove + * @param bool $check Check file permissions + * @return bool True if the file was successfully removed, otherwise false */ function remove_file($filename, $check = false) { -- cgit v1.2.1 From 11a9104b8a50cbc62cba0c242dee554b5209a327 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 17 Mar 2014 13:29:35 +0100 Subject: [ticket/12282] Use interface for type hinting PHPBB3-12282 --- phpBB/phpbb/cache/driver/memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index b618b0f3e6..d5404455d1 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -279,7 +279,7 @@ abstract class memory extends \phpbb\cache\driver\base /** * {@inheritDoc} */ - function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl) + function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl) { // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/cache/driver/memory.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index d5404455d1..5dee375192 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -11,7 +15,6 @@ namespace phpbb\cache\driver; /** * ACM Abstract Memory Class -* @package acm */ abstract class memory extends \phpbb\cache\driver\base { -- cgit v1.2.1 From e7251252ce0fcc2823226dc03b63ae18e8cd1ecb Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 30 Jun 2014 21:38:10 +0200 Subject: [ticket/12789] Remove the directories in \phpbb\cache\driver\memory::purge() PHPBB3-12789 --- phpBB/phpbb/cache/driver/memory.php | 70 ++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 5dee375192..65f70ecbb9 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -150,28 +150,34 @@ abstract class memory extends \phpbb\cache\driver\base function purge() { // Purge all phpbb cache files - $dir = @opendir($this->cache_dir); - - if (!$dir) + try + { + $iterator = new \DirectoryIterator($this->cache_dir); + } + catch (\Exception $e) { return; } - while (($entry = readdir($dir)) !== false) + foreach ($iterator as $fileInfo) { - if (strpos($entry, 'container_') !== 0 && - strpos($entry, 'url_matcher') !== 0 && - strpos($entry, 'sql_') !== 0 && - strpos($entry, 'data_') !== 0 && - strpos($entry, 'ctpl_') !== 0 && - strpos($entry, 'tpl_') !== 0) + if ($fileInfo->isDot()) { continue; } - - $this->remove_file($this->cache_dir . $entry); + $filename = $fileInfo->getFilename(); + if ($fileInfo->isDir()) + { + $this->remove_dir($fileInfo->getPathname()); + } + else if (strpos($filename, 'container_') !== 0 && + strpos($filename, 'url_matcher') !== 0 && + strpos($filename, 'sql_') !== 0 && + strpos($filename, 'data_') !== 0) + { + $this->remove_file($fileInfo->getPathname()); + } } - closedir($dir); unset($this->vars); unset($this->sql_rowset); @@ -425,6 +431,44 @@ abstract class memory extends \phpbb\cache\driver\base return @unlink($filename); } + /** + * Remove directory + * + * @param string $dir Directory to remove + * + * @return null + */ + protected function remove_dir($dir) + { + try + { + $iterator = new \DirectoryIterator($dir); + } + catch (\Exception $e) + { + return; + } + + foreach ($iterator as $fileInfo) + { + if ($fileInfo->isDot()) + { + continue; + } + + if ($fileInfo->isDir()) + { + $this->remove_dir($fileInfo->getPathname()); + } + else + { + $this->remove_file($fileInfo->getPathname()); + } + } + + @rmdir($dir); + } + /** * Check if a cache var exists * -- cgit v1.2.1 From e07e9f6cee5a43f865cfc805f5eb5763bced0c00 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 10 Jul 2014 19:47:19 +0200 Subject: [ticket/12789] Move duplicated functions to the base class PHPBB3-12789 --- phpBB/phpbb/cache/driver/memory.php | 215 ------------------------------------ 1 file changed, 215 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 65f70ecbb9..56308be8da 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -20,13 +20,6 @@ abstract class memory extends \phpbb\cache\driver\base { var $key_prefix; - var $vars = array(); - var $is_modified = false; - - var $sql_rowset = array(); - var $sql_row_pointer = array(); - var $cache_dir = ''; - /** * Set cache path */ @@ -68,21 +61,6 @@ abstract class memory extends \phpbb\cache\driver\base return false; } - /** - * {@inheritDoc} - */ - function unload() - { - $this->save(); - unset($this->vars); - unset($this->sql_rowset); - unset($this->sql_row_pointer); - - $this->vars = array(); - $this->sql_rowset = array(); - $this->sql_row_pointer = array(); - } - /** * {@inheritDoc} */ @@ -144,53 +122,6 @@ abstract class memory extends \phpbb\cache\driver\base } } - /** - * {@inheritDoc} - */ - function purge() - { - // Purge all phpbb cache files - try - { - $iterator = new \DirectoryIterator($this->cache_dir); - } - catch (\Exception $e) - { - return; - } - - foreach ($iterator as $fileInfo) - { - if ($fileInfo->isDot()) - { - continue; - } - $filename = $fileInfo->getFilename(); - if ($fileInfo->isDir()) - { - $this->remove_dir($fileInfo->getPathname()); - } - else if (strpos($filename, 'container_') !== 0 && - strpos($filename, 'url_matcher') !== 0 && - strpos($filename, 'sql_') !== 0 && - strpos($filename, 'data_') !== 0) - { - $this->remove_file($fileInfo->getPathname()); - } - } - - unset($this->vars); - unset($this->sql_rowset); - unset($this->sql_row_pointer); - - $this->vars = array(); - $this->sql_rowset = array(); - $this->sql_row_pointer = array(); - - $this->is_modified = false; - } - - /** * {@inheritDoc} */ @@ -265,26 +196,6 @@ abstract class memory extends \phpbb\cache\driver\base } } - /** - * {@inheritDoc} - */ - function sql_load($query) - { - // Remove extra spaces and tabs - $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - $query_id = sizeof($this->sql_rowset); - - if (($result = $this->_read('sql_' . md5($query))) === false) - { - return false; - } - - $this->sql_rowset[$query_id] = $result; - $this->sql_row_pointer[$query_id] = 0; - - return $query_id; - } - /** * {@inheritDoc} */ @@ -343,132 +254,6 @@ abstract class memory extends \phpbb\cache\driver\base return $query_id; } - /** - * {@inheritDoc} - */ - function sql_exists($query_id) - { - return isset($this->sql_rowset[$query_id]); - } - - /** - * {@inheritDoc} - */ - function sql_fetchrow($query_id) - { - if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) - { - return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; - } - - return false; - } - - /** - * {@inheritDoc} - */ - function sql_fetchfield($query_id, $field) - { - if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) - { - return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false; - } - - return false; - } - - /** - * {@inheritDoc} - */ - function sql_rowseek($rownum, $query_id) - { - if ($rownum >= sizeof($this->sql_rowset[$query_id])) - { - return false; - } - - $this->sql_row_pointer[$query_id] = $rownum; - return true; - } - - /** - * {@inheritDoc} - */ - function sql_freeresult($query_id) - { - if (!isset($this->sql_rowset[$query_id])) - { - return false; - } - - unset($this->sql_rowset[$query_id]); - unset($this->sql_row_pointer[$query_id]); - - return true; - } - - /** - * Removes/unlinks file - * - * @param string $filename Filename to remove - * @param bool $check Check file permissions - * @return bool True if the file was successfully removed, otherwise false - */ - function remove_file($filename, $check = false) - { - if (!function_exists('phpbb_is_writable')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/functions.' . $phpEx); - } - - if ($check && !phpbb_is_writable($this->cache_dir)) - { - // E_USER_ERROR - not using language entry - intended. - trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); - } - - return @unlink($filename); - } - - /** - * Remove directory - * - * @param string $dir Directory to remove - * - * @return null - */ - protected function remove_dir($dir) - { - try - { - $iterator = new \DirectoryIterator($dir); - } - catch (\Exception $e) - { - return; - } - - foreach ($iterator as $fileInfo) - { - if ($fileInfo->isDot()) - { - continue; - } - - if ($fileInfo->isDir()) - { - $this->remove_dir($fileInfo->getPathname()); - } - else - { - $this->remove_file($fileInfo->getPathname()); - } - } - - @rmdir($dir); - } - /** * Check if a cache var exists * -- cgit v1.2.1 From 40cd7570e6f4da7cc60d83a3e99c72a2fb99e3f7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 1 Oct 2014 11:38:45 +0200 Subject: [ticket/11224] Revert "Merge pull request #2460 from Nicofuma/ticket/11224" This reverts commit d26436944173d1fa28a1abd96bca861381246860, reversing changes made to 75fcfb1c1d68f1632e7beae3f59699ddff8e5292. PHPBB3-11224 --- phpBB/phpbb/cache/driver/memory.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 0b0e323e3d..56308be8da 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -208,24 +208,12 @@ abstract class memory extends \phpbb\cache\driver\base // determine which tables this query belongs to // Some queries use backticks, namely the get_database_size() query // don't check for conformity, the SQL would error and not reach here. - if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER)) + if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs)) { // Bail out if the match fails. return $query_result; } - - $tables = array(); - foreach ($regs as $match) - { - if ($match[0][0] == 'F') - { - $tables = array_merge($tables, array_map('trim', explode(',', $match[1]))); - } - else - { - $tables[] = $match[2]; - } - } + $tables = array_map('trim', explode(',', $regs[1])); foreach ($tables as $table_name) { -- cgit v1.2.1 From 8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 1 Oct 2014 15:00:01 +0200 Subject: [ticket/11224] Revert Revert "Merge pull request #2460 from ticket/11224" This reverts commit 40cd7570e6f4da7cc60d83a3e99c72a2fb99e3f7. --- phpBB/phpbb/cache/driver/memory.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/cache/driver/memory.php') diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 56308be8da..0b0e323e3d 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -208,12 +208,24 @@ abstract class memory extends \phpbb\cache\driver\base // determine which tables this query belongs to // Some queries use backticks, namely the get_database_size() query // don't check for conformity, the SQL would error and not reach here. - if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs)) + if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER)) { // Bail out if the match fails. return $query_result; } - $tables = array_map('trim', explode(',', $regs[1])); + + $tables = array(); + foreach ($regs as $match) + { + if ($match[0][0] == 'F') + { + $tables = array_merge($tables, array_map('trim', explode(',', $match[1]))); + } + else + { + $tables[] = $match[2]; + } + } foreach ($tables as $table_name) { -- cgit v1.2.1