phpBB

Code Changes

File: phpbb/cache/driver/file.php

  Unmodified   Added   Modified   Removed
Line 19Line 19
class file extends \phpbb\cache\driver\base
{
var $var_expires = array();

class file extends \phpbb\cache\driver\base
{
var $var_expires = array();

 

/**
* @var \phpbb\filesystem\filesystem_interface
*/
protected $filesystem;


/**
* Set cache path


/**
* Set cache path

Line 27Line 32
	*/
function __construct($cache_dir = null)
{

	*/
function __construct($cache_dir = null)
{

		global $phpbb_root_path;
$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/';








		global $phpbb_container;

$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir');
$this->filesystem = new \phpbb\filesystem\filesystem();

if (!is_dir($this->cache_dir))
{
@mkdir($this->cache_dir, 0777, true);
}

	}

/**

	}

/**

Line 63Line 75

if (!$this->_write('data_global'))
{


if (!$this->_write('data_global'))
{

			if (!function_exists('phpbb_is_writable'))
{
global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}


 
			// Now, this occurred how often? ... phew, just tell the user then...

			// Now, this occurred how often? ... phew, just tell the user then...

			if (!phpbb_is_writable($this->cache_dir))

			if (!$this->filesystem->is_writable($this->cache_dir))

			{
// We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
die('Fatal: ' . $this->cache_dir . ' is NOT writable.');

			{
// We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
die('Fatal: ' . $this->cache_dir . ' is NOT writable.');

Line 89Line 95
	*/
function tidy()
{

	*/
function tidy()
{

		global $phpEx;

		global $config, $phpEx;


$dir = @opendir($this->cache_dir);



$dir = @opendir($this->cache_dir);


Line 143Line 149
			}
}


			}
}


		set_config('cache_last_gc', time(), true);

		$config->set('cache_last_gc', time(), false);

	}

/**

	}

/**

Line 279Line 285
		if ($var_name[0] == '_')
{
global $phpEx;

		if ($var_name[0] == '_')
{
global $phpEx;

 
			$var_name = $this->clean_varname($var_name);

			return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx");
}
else

			return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx");
}
else

Line 305Line 312
		// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);


		// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);


		$query_id = sizeof($this->sql_rowset);

		$query_id = md5($query);

		$this->sql_rowset[$query_id] = array();
$this->sql_row_pointer[$query_id] = 0;


		$this->sql_rowset[$query_id] = array();
$this->sql_row_pointer[$query_id] = 0;


Line 315Line 322
		}
$db->sql_freeresult($query_result);


		}
$db->sql_freeresult($query_result);


		if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query))

		if ($this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl + time(), $query))

		{
return $query_id;
}

		{
return $query_id;
}

Line 334Line 341
	{
global $phpEx;


	{
global $phpEx;


 
		$filename = $this->clean_varname($filename);

		$file = "{$this->cache_dir}$filename.$phpEx";

$type = substr($filename, 0, strpos($filename, '_'));

		$file = "{$this->cache_dir}$filename.$phpEx";

$type = substr($filename, 0, strpos($filename, '_'));

Line 516Line 524
	{
global $phpEx;


	{
global $phpEx;


 
		$filename = $this->clean_varname($filename);

		$file = "{$this->cache_dir}$filename.$phpEx";

$lock = new \phpbb\lock\flock($file);

		$file = "{$this->cache_dir}$filename.$phpEx";

$lock = new \phpbb\lock\flock($file);

Line 565Line 574

fclose($handle);



fclose($handle);


			if (!function_exists('phpbb_chmod'))

			if (function_exists('opcache_invalidate'))

			{

			{

				global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions.' . $phpEx);

				@opcache_invalidate($this->cache_file);


			}


			}


			phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);








			try
{
$this->filesystem->phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{
// Do nothing
}


$return_value = true;
}


$return_value = true;
}

Line 583Line 598
		$lock->release();

return $return_value;

		$lock->release();

return $return_value;

 
	}

/**
* Replace slashes in the file name
*
* @param string $varname name of a cache variable
* @return string $varname name that is safe to use as a filename
*/
protected function clean_varname($varname)
{
return str_replace('/', '-', $varname);

	}
}


	}
}