mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge pull request #1194 from dereuromark/2.4-file-improvements
Allow creating of missing tmp directories in debug (development) mode
This commit is contained in:
commit
054668f149
4 changed files with 23 additions and 8 deletions
|
@ -326,7 +326,7 @@ class FileEngine extends CacheEngine {
|
||||||
$dir = $this->settings['path'] . $groups;
|
$dir = $this->settings['path'] . $groups;
|
||||||
|
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0775, true);
|
||||||
}
|
}
|
||||||
$path = new SplFileInfo($dir . $key);
|
$path = new SplFileInfo($dir . $key);
|
||||||
|
|
||||||
|
@ -359,6 +359,12 @@ class FileEngine extends CacheEngine {
|
||||||
*/
|
*/
|
||||||
protected function _active() {
|
protected function _active() {
|
||||||
$dir = new SplFileInfo($this->settings['path']);
|
$dir = new SplFileInfo($this->settings['path']);
|
||||||
|
if (Configure::read('debug')) {
|
||||||
|
$path = $dir->getPathname();
|
||||||
|
if (!is_dir($path)) {
|
||||||
|
mkdir($path, 0775, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($this->_init && !($dir->isDir() && $dir->isWritable())) {
|
if ($this->_init && !($dir->isDir() && $dir->isWritable())) {
|
||||||
$this->_init = false;
|
$this->_init = false;
|
||||||
trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING);
|
trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING);
|
||||||
|
|
|
@ -104,6 +104,10 @@ class FileLog extends BaseLog {
|
||||||
if (!empty($config['path'])) {
|
if (!empty($config['path'])) {
|
||||||
$this->_path = $config['path'];
|
$this->_path = $config['path'];
|
||||||
}
|
}
|
||||||
|
if (Configure::read('debug') && !is_dir($this->_path)) {
|
||||||
|
mkdir($this->_path, 0775, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($config['file'])) {
|
if (!empty($config['file'])) {
|
||||||
$this->_file = $config['file'];
|
$this->_file = $config['file'];
|
||||||
if (substr($this->_file, -4) !== '.log') {
|
if (substr($this->_file, -4) !== '.log') {
|
||||||
|
|
|
@ -132,6 +132,10 @@ class CacheTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testInvalidConfig() {
|
public function testInvalidConfig() {
|
||||||
|
// In debug mode it would auto create the folder.
|
||||||
|
$debug = Configure::read('debug');
|
||||||
|
Configure::write('debug', 0);
|
||||||
|
|
||||||
Cache::config('invalid', array(
|
Cache::config('invalid', array(
|
||||||
'engine' => 'File',
|
'engine' => 'File',
|
||||||
'duration' => '+1 year',
|
'duration' => '+1 year',
|
||||||
|
@ -141,6 +145,8 @@ class CacheTest extends CakeTestCase {
|
||||||
'random' => 'wii'
|
'random' => 'wii'
|
||||||
));
|
));
|
||||||
Cache::read('Test', 'invalid');
|
Cache::read('Test', 'invalid');
|
||||||
|
|
||||||
|
Configure::write('debug', $debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -373,20 +373,19 @@ class FileEngineTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check that FileEngine generates an error when a configured Path does not exist.
|
* check that FileEngine does not generate an error when a configured Path does not exist in debug mode.
|
||||||
*
|
*
|
||||||
* @expectedException PHPUnit_Framework_Error_Warning
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testErrorWhenPathDoesNotExist() {
|
public function testPathDoesNotExist() {
|
||||||
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');
|
$this->skipIf(is_dir(TMP . 'tests' . DS . 'autocreate'), 'Cannot run if test directory exists.');
|
||||||
|
|
||||||
Cache::config('failure', array(
|
Cache::config('autocreate', array(
|
||||||
'engine' => 'File',
|
'engine' => 'File',
|
||||||
'path' => TMP . 'tests' . DS . 'file_failure'
|
'path' => TMP . 'tests' . DS . 'autocreate'
|
||||||
));
|
));
|
||||||
|
|
||||||
Cache::drop('failure');
|
Cache::drop('autocreate');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue